f
This commit is contained in:
@@ -2,6 +2,8 @@ package admin_order
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
@@ -9,6 +11,7 @@ import (
|
||||
"tydata-server/app/main/model"
|
||||
"tydata-server/common/globalkey"
|
||||
"tydata-server/common/xerr"
|
||||
"tydata-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
@@ -77,6 +80,19 @@ func (l *AdminGetOrderListLogic) AdminGetOrderList(req *types.AdminGetOrderListR
|
||||
builder = builder.Where("refund_time <= ?", req.RefundTimeEnd)
|
||||
}
|
||||
|
||||
// 按被查询人(query_user_record 表)过滤:姓名、身份证、手机号(库中为密文,需解密后匹配)
|
||||
if req.QueryName != "" || req.QueryIdCard != "" || req.QueryMobile != "" {
|
||||
orderIds, filterErr := l.filterOrderIdsByQueryUserRecord(req.QueryName, req.QueryIdCard, req.QueryMobile)
|
||||
if filterErr != nil {
|
||||
return nil, filterErr
|
||||
}
|
||||
if len(orderIds) == 0 {
|
||||
builder = builder.Where("1 = 0") // 无匹配时返回空
|
||||
} else {
|
||||
builder = builder.Where(squirrel.Eq{"id": orderIds})
|
||||
}
|
||||
}
|
||||
|
||||
// 并发获取总数和列表
|
||||
var total int64
|
||||
var orders []*model.Order
|
||||
@@ -294,3 +310,71 @@ func (l *AdminGetOrderListLogic) AdminGetOrderList(req *types.AdminGetOrderListR
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// filterOrderIdsByQueryUserRecord 根据姓名、身份证、手机号(明文)从 query_user_record 解密后匹配,返回符合条件的 order_id 列表
|
||||
func (l *AdminGetOrderListLogic) filterOrderIdsByQueryUserRecord(queryName, queryIdCard, queryMobile string) ([]int64, error) {
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
key, keyErr := hex.DecodeString(secretKey)
|
||||
if keyErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "Encrypt.SecretKey 解析失败: %v", keyErr)
|
||||
}
|
||||
|
||||
qb := l.svcCtx.QueryUserRecordModel.SelectBuilder().Where("order_id > ?", 0)
|
||||
recs, err := l.svcCtx.QueryUserRecordModel.FindAll(l.ctx, qb, "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询 query_user_record 失败: %v", err)
|
||||
}
|
||||
|
||||
orderIds := make([]int64, 0, len(recs))
|
||||
for _, rec := range recs {
|
||||
match := true
|
||||
|
||||
if queryName != "" {
|
||||
var decName string
|
||||
if rec.Name != "" {
|
||||
bs, e := crypto.AesEcbDecrypt(rec.Name, key)
|
||||
if e != nil {
|
||||
match = false
|
||||
} else {
|
||||
decName = string(bs)
|
||||
}
|
||||
}
|
||||
if match && !strings.Contains(decName, queryName) {
|
||||
match = false
|
||||
}
|
||||
}
|
||||
|
||||
if match && queryIdCard != "" {
|
||||
var decIdCard string
|
||||
if rec.IdCard != "" {
|
||||
var e error
|
||||
decIdCard, e = crypto.DecryptIDCard(rec.IdCard, key)
|
||||
if e != nil {
|
||||
match = false
|
||||
}
|
||||
}
|
||||
if match && decIdCard != queryIdCard {
|
||||
match = false
|
||||
}
|
||||
}
|
||||
|
||||
if match && queryMobile != "" {
|
||||
var decMobile string
|
||||
if rec.Mobile != "" {
|
||||
var e error
|
||||
decMobile, e = crypto.DecryptMobile(rec.Mobile, secretKey)
|
||||
if e != nil {
|
||||
match = false
|
||||
}
|
||||
}
|
||||
if match && decMobile != queryMobile {
|
||||
match = false
|
||||
}
|
||||
}
|
||||
|
||||
if match {
|
||||
orderIds = append(orderIds, rec.OrderId)
|
||||
}
|
||||
}
|
||||
return orderIds, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user