package order import ( "errors" "net/http" "hfb_sys/backend/pkg/response" "github.com/gin-gonic/gin" ) func writeOrderError(c *gin.Context, err error) { response.RecordError(c, err) switch { case errors.Is(err, ErrDependencyUnavailable): response.ServiceUnavailable(c, "数据库未连接") case errors.Is(err, ErrInvalidRentHours): response.BadRequest(c, "订单信息不符合规则") case errors.Is(err, ErrListingUnavailable): response.Error(c, http.StatusConflict, "listing_unavailable", "该账号暂不可租") case errors.Is(err, ErrCannotRentOwnListing): response.BadRequest(c, "不能租用自己发布的账号") case errors.Is(err, ErrInsufficientBalance): response.Error(c, http.StatusConflict, "insufficient_balance", "钱包余额不足,请先充值") case errors.Is(err, ErrChannelPaymentRequired): response.Error(c, http.StatusGone, "channel_payment_required", "请使用第三方支付入口完成订单付款") case errors.Is(err, ErrOrderCannotPay): response.Error(c, http.StatusConflict, "order_cannot_pay", "当前订单不能支付") case errors.Is(err, ErrOrderCannotCancel): response.Error(c, http.StatusConflict, "order_cannot_cancel", "当前订单不能取消") case errors.Is(err, ErrOrderCannotHandoff): response.Error(c, http.StatusConflict, "order_cannot_handoff", "当前订单不能交接") case errors.Is(err, ErrOrderCannotResetHandoff): response.Error(c, http.StatusConflict, "order_cannot_reset_handoff", "仅超时卡住的订单可重置到对应待办阶段") case errors.Is(err, ErrOrderCannotReceive): response.Error(c, http.StatusConflict, "order_cannot_receive", "当前订单不能确认收号") case errors.Is(err, ErrOrderCannotReturn): response.Error(c, http.StatusConflict, "order_cannot_return", "当前订单不能归还") case errors.Is(err, ErrOrderCannotComplete): response.Error(c, http.StatusConflict, "order_cannot_complete", "当前订单不能完成") case errors.Is(err, ErrCheckoutCannotSubmit): response.Error(c, http.StatusConflict, "checkout_cannot_submit", "当前订单不能发起结账") case errors.Is(err, ErrCheckoutCannotConfirm): response.Error(c, http.StatusConflict, "checkout_cannot_confirm", "当前结账不能确认") case errors.Is(err, ErrCheckoutCannotCounter): response.Error(c, http.StatusConflict, "checkout_cannot_counter", "当前结账不能修改") case errors.Is(err, ErrCheckoutMaxRounds): response.Error(c, http.StatusConflict, "checkout_max_rounds", "结账协商已达 6 轮上限,请同意当前方案或发起争议由人工处理") case errors.Is(err, ErrCheckoutDepositShortfall): response.Error(c, http.StatusConflict, "checkout_deposit_shortfall", "押金不足以覆盖打超/赔付差额,无法自动完结,请发起争议由人工处理") case errors.Is(err, ErrInvalidCheckoutAmount): response.BadRequest(c, "结账金额不符合规则") case errors.Is(err, ErrDisputeExists): response.Error(c, http.StatusConflict, "dispute_exists", "当前订单已有处理中争议") case errors.Is(err, ErrPermissionDenied): response.Error(c, http.StatusForbidden, "permission_denied", "无权操作该订单") case errors.Is(err, ErrDepositCannotHold): response.Error(c, http.StatusConflict, "deposit_cannot_hold", "当前订单不可暂扣押金") case errors.Is(err, ErrDepositNotHeld): response.Error(c, http.StatusConflict, "deposit_not_held", "该订单押金未处于暂扣状态") case errors.Is(err, ErrDepositHoldAmountEmpty): response.Error(c, http.StatusConflict, "deposit_hold_amount_empty", "暂扣押金尚未形成可归还金额") case errors.Is(err, ErrOfflineSettlementCannotMark): response.Error(c, http.StatusConflict, "offline_settlement_cannot_mark", "当前订单不可确认线下结算") case IsNotFound(err): response.Error(c, http.StatusNotFound, "not_found", "订单不存在") default: response.Error(c, http.StatusInternalServerError, "internal_error", "订单服务暂时不可用") } }