fusenapi/server/shopping-cart-confirmation/internal/logic/cartdeletelogic.go
laodaming 6f6da3f481 fix
2023-06-14 14:05:27 +08:00

45 lines
1.1 KiB
Go

package logic
import (
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/shopping-cart-confirmation/internal/svc"
"fusenapi/server/shopping-cart-confirmation/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type CartDeleteLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCartDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDeleteLogic {
return &CartDeleteLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CartDeleteLogic) CartDelete(req *types.CartDeleteReq, userinfo *auth.UserInfo) (resp *basic.Response) {
if req.Id <= 0 {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param id")
}
cartModel := gmodel.NewFsCartModel(l.svcCtx.MysqlConn)
status := int64(0)
err := cartModel.UpdateByIdUserId(l.ctx, req.Id, userinfo.UserId, gmodel.FsCart{
Status: &status,
})
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to delete cart")
}
return resp.SetStatusWithMessage(basic.CodeOK, "delete success")
}