package logic import ( "context" "healthapi/internal/model" "healthapi/internal/svc" "healthapi/internal/types" "healthapi/pkg/errorx" "github.com/zeromicro/go-zero/core/logx" ) type ClearCartLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewClearCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClearCartLogic { return &ClearCartLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *ClearCartLogic) ClearCart() (resp *types.CommonResp, err error) { userID, err := GetUserIDFromCtx(l.ctx) if err != nil { return nil, errorx.ErrUnauthorized } l.svcCtx.DB.Where("user_id = ?", userID).Delete(&model.CartItem{}) return &types.CommonResp{ Code: 0, Message: "购物车已清空", }, nil }