fix: 统一佣金状态常量并修复佣金明细关联查询
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m33s

- 删除 model/commission.go 中与 constants 包冲突的旧常量(值=1/2)
- 所有服务层改用 constants.CommissionStatusReleased(值=3)写入和查询
- 数据库迁移:status 1→3(已发放),2→4(已失效)
- 修复佣金明细列表接口,通过 JOIN 关联返回 order_no、iccid、virtual_no、order_created_at
- 新增 seller_shop_id / seller_shop_name 销售来源字段
- 统计接口过滤条件从精确匹配改为排除无效(NOT IN 4,99)
- 更新 OpenAPI 文档及 commission-record-query spec
This commit is contained in:
2026-04-11 10:42:37 +08:00
parent d0989c66bb
commit 677d6239ce
17 changed files with 604 additions and 38 deletions

View File

@@ -410,8 +410,33 @@ func (s *Service) ListShopCommissionRecords(ctx context.Context, shopID uint, re
return nil, errors.Wrap(errors.CodeInternalError, err, "查询佣金明细失败")
}
sellerShopIDs := make([]uint, 0)
for _, r := range records {
if r.SellerShopID != nil && *r.SellerShopID > 0 {
sellerShopIDs = append(sellerShopIDs, *r.SellerShopID)
}
}
shopNameMap := make(map[uint]string)
if len(sellerShopIDs) > 0 {
shops, err := s.shopStore.GetByIDs(ctx, sellerShopIDs)
if err == nil {
for _, sh := range shops {
shopNameMap[sh.ID] = sh.ShopName
}
}
}
items := make([]dto.ShopCommissionRecordItem, 0, len(records))
for _, r := range records {
var orderCreatedAt string
if r.OrderCreatedAt != nil {
orderCreatedAt = r.OrderCreatedAt.Format("2006-01-02 15:04:05")
}
var sellerShopID uint
if r.SellerShopID != nil {
sellerShopID = *r.SellerShopID
}
item := dto.ShopCommissionRecordItem{
ID: r.ID,
Amount: r.Amount,
@@ -420,10 +445,12 @@ func (s *Service) ListShopCommissionRecords(ctx context.Context, shopID uint, re
Status: r.Status,
StatusName: getCommissionStatusName(r.Status),
OrderID: r.OrderID,
OrderNo: "",
VirtualNo: "",
ICCID: "",
OrderCreatedAt: "",
OrderNo: r.OrderNo,
VirtualNo: r.VirtualNo,
ICCID: r.ICCID,
OrderCreatedAt: orderCreatedAt,
SellerShopID: sellerShopID,
SellerShopName: shopNameMap[sellerShopID],
CreatedAt: r.CreatedAt.Format("2006-01-02 15:04:05"),
}
items = append(items, item)
@@ -746,7 +773,7 @@ func (s *Service) ResolveCommissionRecord(ctx context.Context, recordID uint, re
if req.Action == "invalidate" {
return s.commissionRecordStore.UpdateByID(ctx, nil, recordID, map[string]any{
"status": model.CommissionStatusInvalid,
"status": constants.CommissionStatusInvalid,
"remark": resolveRemark,
})
}
@@ -764,7 +791,7 @@ func (s *Service) ResolveCommissionRecord(ctx context.Context, recordID uint, re
return s.db.Transaction(func(tx *gorm.DB) error {
if err := s.commissionRecordStore.UpdateByID(ctx, tx, recordID, map[string]any{
"status": model.CommissionStatusReleased,
"status": constants.CommissionStatusReleased,
"amount": amount,
"released_at": now,
"remark": resolveRemark,