package logic import ( "errors" "fusenapi/utils/auth" "fusenapi/utils/basic" "gorm.io/gorm" "context" "fusenapi/server/product/internal/svc" "fusenapi/server/product/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type CaculateProductPriceLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewCaculateProductPriceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CaculateProductPriceLogic { return &CaculateProductPriceLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } // 处理进入前逻辑w,r // func (l *CaculateProductPriceLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } func (l *CaculateProductPriceLogic) CaculateProductPrice(req *types.CaculateProductPriceReq, userinfo *auth.UserInfo) (resp *basic.Response) { if req.ProductId <= 0 { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:product id") } if req.SizeId <= 0 { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:size id") } //获取产品信息(只是获取id) _, err := l.svcCtx.AllModels.FsProduct.FindOne(l.ctx, req.ProductId, "id") if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists") } logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info") } return resp.SetStatus(basic.CodeOK) } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 // func (l *CaculateProductPriceLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // // httpx.OkJsonCtx(r.Context(), w, resp) // }