package logic import ( "context" "healthapi/internal/model" "healthapi/internal/svc" "healthapi/internal/types" "healthapi/pkg/errorx" "github.com/zeromicro/go-zero/core/logx" ) type BatchSelectCartLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewBatchSelectCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BatchSelectCartLogic { return &BatchSelectCartLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *BatchSelectCartLogic) BatchSelectCart(req *types.BatchSelectCartReq) (resp *types.CommonResp, err error) { userID, err := GetUserIDFromCtx(l.ctx) if err != nil { return nil, errorx.ErrUnauthorized } if len(req.Ids) == 0 { // 全选/全不选 l.svcCtx.DB.Model(&model.CartItem{}).Where("user_id = ?", userID).Update("selected", req.Selected) } else { // 批量选择指定项 l.svcCtx.DB.Model(&model.CartItem{}). Where("user_id = ? AND id IN ?", userID, req.Ids). Update("selected", req.Selected) } return &types.CommonResp{ Code: 0, Message: "操作成功", }, nil }