修复(#84): 补齐促销管理API实现文件
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package promo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
promoModel "github.com/perfect-panel/server/internal/model/promo"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/logger"
|
||||
)
|
||||
|
||||
type GetPromoPriceListLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Get promo price list
|
||||
func NewGetPromoPriceListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPromoPriceListLogic {
|
||||
return &GetPromoPriceListLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetPromoPriceListLogic) GetPromoPriceList(req *types.GetPromoPriceListRequest) (*types.GetPromoPriceListResponse, error) {
|
||||
total, list, err := l.svcCtx.PromoModel.QuerySubscribePromoList(l.ctx, promoModel.SubscribePromoFilter{
|
||||
Page: int(req.Page),
|
||||
Size: int(req.Size),
|
||||
PromoRuleId: req.PromoRuleId,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[GetPromoPriceList] Database Error", logger.Field("error", err.Error()))
|
||||
return nil, wrapQueryError("get promo price list failed", err)
|
||||
}
|
||||
resp := &types.GetPromoPriceListResponse{
|
||||
Total: total,
|
||||
List: make([]types.PromoPrice, 0, len(list)),
|
||||
}
|
||||
for _, item := range list {
|
||||
var unitPrice int64
|
||||
sub, subErr := l.svcCtx.SubscribeModel.FindOne(l.ctx, item.SubscribeId)
|
||||
if subErr == nil {
|
||||
unitPrice = sub.UnitPrice
|
||||
}
|
||||
resp.List = append(resp.List, toPriceResponse(item, unitPrice))
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user