fusenapi/server/shopping-cart-confirmation/internal/logic/cartnumberlogic.go

44 lines
1.1 KiB
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(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
if userinfo.GetIdType() != auth.IDTYPE_User {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
}
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,
})
}