2023-06-13 06:29:44 +00:00
|
|
|
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"
|
2023-07-21 07:20:18 +00:00
|
|
|
|
2023-06-13 06:29:44 +00:00
|
|
|
"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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-21 07:20:18 +00:00
|
|
|
func (l *CartNumberLogic) CartNumber(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
2023-06-15 04:00:32 +00:00
|
|
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
|
|
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
|
|
|
}
|
2023-06-13 06:29:44 +00:00
|
|
|
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,
|
|
|
|
})
|
|
|
|
}
|