ea586e3ba2
Co-authored-by: multica-agent <github@multica.ai>
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
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
|
|
}
|