{
  "openapi": "3.0.1",
  "info": {
    "title": "AI运动营养师 - H5外卖订单取消接口增量",
    "version": "1.0.0",
    "description": "本文件用于向 Apifox 增量同步 H5 外卖记录订单详情中的取消规则字段，以及客户自助取消订单接口。"
  },
  "servers": [
    {
      "url": "https://aizhctdev.yyangpt.cn/index.php?s=",
      "description": "开发环境 API 直连地址"
    }
  ],
  "tags": [
    {
      "name": "订单/外卖记录"
    }
  ],
  "paths": {
    "/api/mealOrder/detail": {
      "get": {
        "tags": [
          "订单/外卖记录"
        ],
        "summary": "外卖订单详情",
        "description": "H5 外卖记录订单详情接口。前端代理路径为 `/aizhct/api/mealOrder/detail`。\n\n本次补充取消订单相关字段：`can_cancel`、`cancel_reason`、`cancel_rule`。前端根据 `can_cancel=true` 展示取消按钮；如果不可取消，可展示 `cancel_reason`。",
        "operationId": "get_api_mealOrder_detail",
        "parameters": [
          {
            "name": "Access-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "登录态令牌"
          },
          {
            "name": "platform",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "default": "H5"
            },
            "description": "客户端平台，H5 端传 `H5`"
          },
          {
            "name": "order_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer",
              "example": 67500
            },
            "description": "订单 ID"
          },
          {
            "name": "id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "example": 67500
            },
            "description": "兼容字段，H5 当前会同时传 `id` 和 `order_id`"
          }
        ],
        "responses": {
          "200": {
            "description": "订单详情。业务是否成功以响应体 `status` 为准。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MealOrderDetailResponse"
                },
                "examples": {
                  "cancelablePaidOrder": {
                    "summary": "已支付且规则内可取消",
                    "value": {
                      "status": 200,
                      "message": "success",
                      "data": {
                        "data": {
                          "id": 67500,
                          "order_no": "260609113094679",
                          "pay_status": 20,
                          "order_status": 30,
                          "refund_status": 0,
                          "meal_date": "2026-06-10",
                          "meal_times": 2,
                          "pay_price": "12.00",
                          "can_cancel": true,
                          "cancel_reason": "",
                          "cancel_rule": {
                            "stall_type": 2,
                            "meal_times": 2,
                            "cancel_time": "10:00",
                            "cancel_deadline": "2026-06-10 10:00:59",
                            "rules": {
                              "1": "08:00",
                              "2": "10:00",
                              "3": "16:00",
                              "4": ""
                            }
                          }
                        }
                      },
                      "trace_id": "xxxxxxxxxxxx"
                    }
                  },
                  "uncancelable": {
                    "summary": "不可取消",
                    "value": {
                      "status": 200,
                      "message": "success",
                      "data": {
                        "data": {
                          "id": 67506,
                          "order_no": "260609178635485",
                          "pay_status": 20,
                          "order_status": 30,
                          "refund_status": 0,
                          "can_cancel": false,
                          "cancel_reason": "已超过取消时间，不可取消",
                          "cancel_rule": {
                            "stall_type": 2,
                            "meal_times": 2,
                            "cancel_time": "10:00",
                            "cancel_deadline": "2026-06-10 10:00:59",
                            "rules": {
                              "1": "08:00",
                              "2": "10:00",
                              "3": "16:00",
                              "4": ""
                            }
                          }
                        }
                      },
                      "trace_id": "xxxxxxxxxxxx"
                    }
                  }
                }
              }
            }
          }
        },
        "x-apifox-folder": "订单/外卖记录"
      }
    },
    "/api/mealOrder/cancel": {
      "post": {
        "tags": [
          "订单/外卖记录"
        ],
        "summary": "取消外卖订单",
        "description": "H5 外卖记录订单详情页的客户自助取消接口。前端代理路径为 `/aizhct/api/mealOrder/cancel`。\n\n取消逻辑：\n- 未支付订单：`pay_status=10` 且 `order_status=10` 时可直接取消，只更新订单为已取消，不生成退款单，不退余额/补贴，返回 `has_refund=false`。\n- 已支付订单：`pay_status=20` 且 `order_status` 为 `10` 或 `30` 时，继续校验档口取消规则、退款状态、取餐状态和取消截止时间；通过后自动退款，返回 `has_refund=true`。\n- 已取消、退款中/已退款、已进入取餐流程、超过取消时间均不可取消。",
        "operationId": "post_api_mealOrder_cancel",
        "parameters": [
          {
            "name": "Access-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "登录态令牌"
          },
          {
            "name": "platform",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "default": "H5"
            },
            "description": "客户端平台，H5 端传 `H5`"
          },
          {
            "name": "content-type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "default": "application/x-www-form-urlencoded;charset=UTF-8"
            },
            "description": "H5 当前使用 URLSearchParams 表单提交"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/MealOrderCancelRequest"
              },
              "examples": {
                "byOrderId": {
                  "summary": "按 order_id 取消",
                  "value": {
                    "order_id": 67500
                  }
                },
                "compatiblePayload": {
                  "summary": "H5 当前兼容传参",
                  "value": {
                    "order_id": 67500,
                    "orderId": 67500
                  }
                }
              }
            },
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MealOrderCancelRequest"
              },
              "example": {
                "order_id": 67500
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "取消成功或业务失败。业务是否成功以响应体 `status` 为准。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MealOrderCancelResponse"
                },
                "examples": {
                  "unpaidCancelSuccess": {
                    "summary": "未支付订单取消成功，无退款",
                    "value": {
                      "status": 200,
                      "message": "取消成功",
                      "data": {
                        "can_cancel": true,
                        "cancel_reason": "",
                        "cancel_rule": {
                          "stall_type": 2,
                          "meal_times": 2,
                          "cancel_time": "",
                          "cancel_deadline": "",
                          "rules": []
                        },
                        "order_id": 67500,
                        "order_no": "260609113094679",
                        "has_refund": false,
                        "refund_order_no": "",
                        "refund_amount": "0.00"
                      },
                      "trace_id": "xxxxxxxxxxxx"
                    }
                  },
                  "paidCancelSuccess": {
                    "summary": "已支付订单取消成功，自动退款",
                    "value": {
                      "status": 200,
                      "message": "取消成功，退款已自动退回",
                      "data": {
                        "can_cancel": true,
                        "cancel_reason": "",
                        "cancel_rule": {
                          "stall_type": 2,
                          "meal_times": 2,
                          "cancel_time": "10:00",
                          "cancel_deadline": "2026-06-10 10:00:59",
                          "rules": {
                            "1": "08:00",
                            "2": "10:00",
                            "3": "16:00",
                            "4": ""
                          }
                        },
                        "order_id": 67500,
                        "order_no": "260609113094679",
                        "has_refund": true,
                        "refund_order_no": "RF260610123456789",
                        "refund_amount": "12.00",
                        "remain_balance": "100.00",
                        "remain_cash": "80.00",
                        "remain_subsidy": "20.00"
                      },
                      "trace_id": "xxxxxxxxxxxx"
                    }
                  },
                  "cancelFailed": {
                    "summary": "不可取消",
                    "value": {
                      "status": 500,
                      "message": "已超过取消时间，不可取消",
                      "data": [],
                      "trace_id": "xxxxxxxxxxxx"
                    }
                  }
                }
              }
            }
          }
        },
        "x-apifox-folder": "订单/外卖记录"
      }
    }
  },
  "components": {
    "schemas": {
      "CommonEnvelope": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "description": "业务状态码，成功通常为 200"
          },
          "message": {
            "type": "string",
            "description": "提示信息"
          },
          "data": {
            "description": "业务数据"
          },
          "trace_id": {
            "type": "string",
            "description": "链路追踪 ID"
          }
        }
      },
      "CancelRule": {
        "type": "object",
        "properties": {
          "stall_type": {
            "type": "integer",
            "description": "档口类型，2=订单外卖，3=招待订餐"
          },
          "meal_times": {
            "type": "integer",
            "description": "餐次，1=早餐，2=午餐，3=晚餐，4=夜宵"
          },
          "cancel_time": {
            "type": "string",
            "description": "当前餐次取消截止时间，格式 HH:mm"
          },
          "cancel_deadline": {
            "type": "string",
            "description": "取消截止完整时间，格式 yyyy-MM-dd HH:mm:ss"
          },
          "rules": {
            "type": "object",
            "description": "档口配置的各餐次取消规则"
          }
        }
      },
      "MealOrderDetail": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "订单 ID"
          },
          "order_no": {
            "type": "string",
            "description": "订单编号"
          },
          "pay_status": {
            "type": "integer",
            "description": "支付状态，10=待支付，20=已支付"
          },
          "order_status": {
            "type": "integer",
            "description": "订单状态，10=进行中，20=取消，21=待取消，30=已完成"
          },
          "refund_status": {
            "type": "integer",
            "description": "退款状态"
          },
          "meal_date": {
            "type": "string",
            "description": "就餐日期"
          },
          "meal_times": {
            "type": "integer",
            "description": "餐次，1=早餐，2=午餐，3=晚餐，4=夜宵"
          },
          "pay_price": {
            "type": "string",
            "description": "支付金额"
          },
          "can_cancel": {
            "type": "boolean",
            "description": "当前订单是否允许 H5 自助取消"
          },
          "cancel_reason": {
            "type": "string",
            "description": "不可取消原因；可取消时为空字符串"
          },
          "cancel_rule": {
            "$ref": "#/components/schemas/CancelRule"
          }
        }
      },
      "MealOrderDetailResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/CommonEnvelope"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "type": "object",
                "properties": {
                  "data": {
                    "$ref": "#/components/schemas/MealOrderDetail"
                  }
                }
              }
            }
          }
        ]
      },
      "MealOrderCancelRequest": {
        "type": "object",
        "properties": {
          "order_id": {
            "type": "integer",
            "description": "订单 ID"
          },
          "orderId": {
            "type": "integer",
            "description": "兼容字段，订单 ID"
          },
          "id": {
            "type": "integer",
            "description": "兼容字段，订单 ID"
          }
        },
        "anyOf": [
          {
            "required": [
              "order_id"
            ]
          },
          {
            "required": [
              "orderId"
            ]
          },
          {
            "required": [
              "id"
            ]
          }
        ]
      },
      "MealOrderCancelResult": {
        "type": "object",
        "properties": {
          "can_cancel": {
            "type": "boolean",
            "description": "是否允许取消"
          },
          "cancel_reason": {
            "type": "string",
            "description": "不可取消原因；取消成功时为空"
          },
          "cancel_rule": {
            "$ref": "#/components/schemas/CancelRule"
          },
          "order_id": {
            "type": "integer",
            "description": "订单 ID"
          },
          "order_no": {
            "type": "string",
            "description": "订单编号"
          },
          "has_refund": {
            "type": "boolean",
            "description": "是否发生自动退款。未支付订单取消时为 false，已支付订单规则内取消退款时为 true"
          },
          "refund_order_no": {
            "type": "string",
            "description": "退款单号；未支付取消为空字符串"
          },
          "refund_amount": {
            "type": "string",
            "description": "退款金额；未支付取消为 0.00"
          },
          "remain_balance": {
            "type": "string",
            "description": "退款后剩余总余额；仅已支付退款场景返回"
          },
          "remain_cash": {
            "type": "string",
            "description": "退款后现金余额；仅已支付退款场景返回"
          },
          "remain_subsidy": {
            "type": "string",
            "description": "退款后补贴余额；仅已支付退款场景返回"
          }
        }
      },
      "MealOrderCancelResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/CommonEnvelope"
          },
          {
            "type": "object",
            "properties": {
              "data": {
                "$ref": "#/components/schemas/MealOrderCancelResult"
              }
            }
          }
        ]
      }
    }
  }
}
