新功能(#77): 套餐列表 API 返回规格级促销信息
将 promo 字段从 Subscribe 顶层移至 SubscribeDiscount(discount[] 项内), 促销查询按 subscribe_id + quantity 维度写入,每个规格独立命中最高优先级规则。 Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -56,11 +56,19 @@ func (l *QuerySubscribeListLogic) QuerySubscribeList(req *types.QuerySubscribeLi
|
||||
var discount []types.SubscribeDiscount
|
||||
_ = json.Unmarshal([]byte(item.Discount), &discount)
|
||||
sub.Discount = discount
|
||||
list[i] = sub
|
||||
}
|
||||
list[i] = sub
|
||||
}
|
||||
|
||||
promos, err := loadSubscribePromoMap(l.ctx, l.svcCtx, subscribeIDs)
|
||||
if err != nil {
|
||||
l.Errorw("[QuerySubscribeListLogic] Query Promo Error", logger.Field("error", err.Error()))
|
||||
return nil, err
|
||||
}
|
||||
for i := range list {
|
||||
applySubscribeDiscountPromos(&list[i], promos[list[i].Id])
|
||||
}
|
||||
|
||||
// 老版本客户端(无 X-App-Id)去掉每个套餐 discount 的最后一个
|
||||
hasAppId, _ := l.ctx.Value(constant.CtxKeyHasAppId).(bool)
|
||||
if !hasAppId {
|
||||
@@ -71,16 +79,13 @@ func (l *QuerySubscribeListLogic) QuerySubscribeList(req *types.QuerySubscribeLi
|
||||
}
|
||||
}
|
||||
|
||||
promos, err := loadSubscribePromoMap(l.ctx, l.svcCtx, subscribeIDs)
|
||||
if err != nil {
|
||||
l.Errorw("[QuerySubscribeListLogic] Query Promo Error", logger.Field("error", err.Error()))
|
||||
return nil, err
|
||||
}
|
||||
for i := range list {
|
||||
list[i].Promo = promos[list[i].Id]
|
||||
}
|
||||
|
||||
resp.List = list
|
||||
resp.Total = int64(len(list))
|
||||
return
|
||||
}
|
||||
|
||||
func applySubscribeDiscountPromos(subscribe *types.Subscribe, promoByQuantity map[int64]*types.SubscribePromo) {
|
||||
for i := range subscribe.Discount {
|
||||
subscribe.Discount[i].Promo = promoByQuantity[subscribe.Discount[i].Quantity]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user