package logic import ( "context" "time" "healthapi/internal/model" "healthapi/internal/svc" "healthapi/internal/types" "healthapi/pkg/errorx" "github.com/zeromicro/go-zero/core/logx" ) type ConfirmReceiveLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewConfirmReceiveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ConfirmReceiveLogic { return &ConfirmReceiveLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *ConfirmReceiveLogic) ConfirmReceive(req *types.OrderIdReq) (resp *types.CommonResp, err error) { userID, err := GetUserIDFromCtx(l.ctx) if err != nil { return nil, errorx.ErrUnauthorized } var order model.Order if err := l.svcCtx.DB.Where("id = ? AND user_id = ?", req.Id, userID).First(&order).Error; err != nil { return nil, errorx.NewCodeError(404, "订单不存在") } if order.Status != model.OrderStatusShipped { return nil, errorx.NewCodeError(400, "只能确认已发货订单") } now := time.Now() if err := l.svcCtx.DB.Model(&order).Updates(map[string]interface{}{ "status": model.OrderStatusCompleted, "receive_time": now, }).Error; err != nil { return nil, err } return &types.CommonResp{ Code: 0, Message: "确认收货成功", }, nil }