48 lines
1.2 KiB
Go
48 lines
1.2 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 userinfo.GetIdType() != auth.IDTYPE_User {
|
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
|
}
|
|
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")
|
|
}
|