fusenapi/server/shopping-cart-confirmation/internal/logic/cartnumberlogic.go
laodaming da347feac9 fix
2023-06-13 14:29:44 +08:00

40 lines
995 B
Go

package logic
import (
"fusenapi/model/gmodel"
"fusenapi/server/shopping-cart-confirmation/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/shopping-cart-confirmation/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type CartNumberLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCartNumberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartNumberLogic {
return &CartNumberLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CartNumberLogic) CartNumber(userinfo *auth.UserInfo) (resp *basic.Response) {
cartModel := gmodel.NewFsCartModel(l.svcCtx.MysqlConn)
total, err := cartModel.CountUserCart(l.ctx, userinfo.UserId)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeApiErr, "failed to get count of your cart")
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CartNumberRsp{
Num: total,
})
}