代码提交
This commit is contained in:
@@ -34,6 +34,12 @@ func List(ctx context.Context, req *proto.RefundOrderListReq) (*proto.RefundOrde
|
||||
if req.CID != nil && *req.CID != "" {
|
||||
filter[refundOrderMod.FN.RefundOrder.CID] = *req.CID
|
||||
}
|
||||
if req.TransNo != nil && *req.TransNo != "" {
|
||||
filter[refundOrderMod.FN.RefundOrder.TransNo] = *req.TransNo
|
||||
}
|
||||
if req.IP != nil && *req.IP != "" {
|
||||
filter[refundOrderMod.FN.RefundOrder.IP] = *req.IP
|
||||
}
|
||||
if req.ChannelName != nil && *req.ChannelName != "" {
|
||||
filter[refundOrderMod.FN.RefundOrder.ChannelName] = *req.ChannelName
|
||||
}
|
||||
@@ -60,30 +66,30 @@ func List(ctx context.Context, req *proto.RefundOrderListReq) (*proto.RefundOrde
|
||||
|
||||
// Add 按单个 cid 回填
|
||||
func Add(ctx context.Context, req *proto.AddRefundOrderReq) (*proto.AddRefundOrderResp, error) {
|
||||
return addByCids(ctx, []string{req.CID})
|
||||
return addItems(ctx, []proto.RefundOrderItem{{CID: req.CID, TransNo: req.TransNo, IP: req.IP}})
|
||||
}
|
||||
|
||||
// BatchAdd 按多个 cid 批量回填
|
||||
// BatchAdd 批量回填
|
||||
func BatchAdd(ctx context.Context, req *proto.BatchAddRefundOrderReq) (*proto.AddRefundOrderResp, error) {
|
||||
return addByCids(ctx, req.CIDs)
|
||||
return addItems(ctx, req.Items)
|
||||
}
|
||||
|
||||
// addByCids 逐个 cid 查询 log_recharge 的成功订单,按 (appId, orderId) 判重后落库。
|
||||
// 单个 cid 失败不影响其余 cid,错误直接返回由调用方决定。
|
||||
func addByCids(ctx context.Context, cids []string) (*proto.AddRefundOrderResp, error) {
|
||||
// addItems 逐个 cid 查询 log_recharge 的成功订单,按 (appId, orderId) 判重后落库。
|
||||
// transNo 不参与查询,只随记录一起写入用于追溯。
|
||||
func addItems(ctx context.Context, items []proto.RefundOrderItem) (*proto.AddRefundOrderResp, error) {
|
||||
resp := &proto.AddRefundOrderResp{
|
||||
Details: make([]proto.RefundCidStat, 0, len(cids)),
|
||||
Details: make([]proto.RefundCidStat, 0, len(items)),
|
||||
}
|
||||
seen := make(map[string]bool, len(cids)) // 同一次请求里 cid 去重
|
||||
for _, cid := range cids {
|
||||
if cid == "" || seen[cid] {
|
||||
seen := make(map[string]bool, len(items)) // 同一次请求里 cid 去重
|
||||
for _, item := range items {
|
||||
if item.CID == "" || seen[item.CID] {
|
||||
continue
|
||||
}
|
||||
seen[cid] = true
|
||||
seen[item.CID] = true
|
||||
|
||||
stat, err := addOneCid(ctx, cid)
|
||||
stat, err := addOneCid(ctx, item.CID, item.TransNo, item.IP)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("回填渠道[%s]失败: %w", cid, err)
|
||||
return nil, fmt.Errorf("回填订单[%s]失败: %w", item.CID, err)
|
||||
}
|
||||
resp.Matched += stat.Matched
|
||||
resp.Inserted += stat.Inserted
|
||||
@@ -93,8 +99,8 @@ func addByCids(ctx context.Context, cids []string) (*proto.AddRefundOrderResp, e
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func addOneCid(ctx context.Context, cid string) (*proto.RefundCidStat, error) {
|
||||
stat := &proto.RefundCidStat{CID: cid}
|
||||
func addOneCid(ctx context.Context, cid, transNo, ip string) (*proto.RefundCidStat, error) {
|
||||
stat := &proto.RefundCidStat{CID: cid, TransNo: transNo}
|
||||
|
||||
// cid 唯一标识一笔订单,只回填付款成功的那条
|
||||
src, err := rechargemod.FindOneRecharge(ctx, bson.M{
|
||||
@@ -125,6 +131,8 @@ func addOneCid(ctx context.Context, cid string) (*proto.RefundCidStat, error) {
|
||||
doc := &refundOrderMod.RefundOrder{
|
||||
AppId: src.AppId,
|
||||
CID: src.CID,
|
||||
TransNo: transNo,
|
||||
IP: ip,
|
||||
DistrictCode: src.DistrictCode,
|
||||
Money: src.Money,
|
||||
OrderId: src.OrderId,
|
||||
|
||||
Reference in New Issue
Block a user