{
  "openapi": "3.0.3",
  "info": {
    "title": "三全消费机支付宝付款码入口",
    "version": "1.0.0",
    "description": "智慧餐厅消费机统一结算接口的支付宝付款码增量说明。"
  },
  "servers": [
    {
      "url": "http://127.0.0.1:8090",
      "description": "本地 Docker；现场测试时替换为实际 store 地址"
    }
  ],
  "paths": {
    "/api/consume/orderPay": {
      "post": {
        "summary": "订单结算（支持支付宝付款码）",
        "description": "支付宝分流条件：order_type=1、card_id 为空、paycode 为支付宝付款码。接口先创建待支付消费订单，再由独立支付宝模块调用 ai_api；成功后订单 pay_status=20、pay_type=60、trade_id 为 ai_api 的 yoshop_payment_trade.trade_id。支付结果为 PAYING/UNKNOWN 时由 ai_api 自动查单并撤销；撤销成功后 store 取消原待支付订单，向消费机返回 code=8002、payment_status=CLOSED。消费机结束旧支付交互并使用新 msgid 重新扫码。相同 msgid 不重复扣款。order_type=2 不进入支付宝在线付款码流程。",
        "tags": ["支付宝消费支付/消费机入口"],
        "x-apifox-folder": "支付宝消费支付/消费机入口",
        "parameters": [
          {
            "name": "account",
            "in": "header",
            "required": true,
            "description": "消费机接口授权账号",
            "schema": {"type": "string", "example": "{{consumeApiAccount}}"}
          },
          {
            "name": "pwd",
            "in": "header",
            "required": true,
            "description": "消费机接口授权密码",
            "schema": {"type": "string", "format": "password", "example": "{{consumeApiPassword}}"}
          },
          {
            "name": "key",
            "in": "header",
            "required": true,
            "description": "消费机接口授权密钥",
            "schema": {"type": "string", "format": "password", "example": "{{consumeApiKey}}"}
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {"$ref": "#/components/schemas/AlipayOrderPayRequest"},
              "example": {
                "dishes": [{"uuid": "custom_dish", "number": 1, "money": "0.01"}],
                "staff_uuid": "",
                "paycode": "{{alipayAuthCode}}",
                "card_id": "",
                "money": "0.01",
                "equipment_code": "LOCAL-ALIPAY-E2E",
                "order_type": 1,
                "create_time": "2026-09-02 12:00:00",
                "msgid": "ALI-E2E-20260902120000001"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {"$ref": "#/components/schemas/AlipayOrderPayRequest"}
            }
          }
        },
        "responses": {
          "200": {
            "description": "业务结果由 code/message 表示",
            "content": {
              "application/json": {
                "schema": {"$ref": "#/components/schemas/OrderPayResponse"},
                "examples": {
                  "success": {
                    "summary": "支付宝支付成功",
                    "value": {"code": 0, "message": "支付成功", "data": {"order_no": "251216168174448", "trade_id": 10086, "pay_type": 60, "order_type": 1}, "trace_id": "69411f03e2b06"}
                  },
                  "paying": {
                    "summary": "支付仍在处理中",
                    "value": {"code": 2, "message": "支付处理中，请勿重复扫码", "data": {"order_no": "251216168174448", "trade_id": 10086, "payment_status": "PAYING"}, "trace_id": "69411f03e2b06"}
                  },
                  "closedRescan": {
                    "summary": "原交易已撤销，重新扫码",
                    "value": {"code": 8002, "message": "付款未完成，请重新出示付款码", "data": {"order_no": "251216168174448", "trade_id": 10086, "payment_status": "CLOSED"}, "trace_id": "69411f03e2b06"}
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Dish": {
        "type": "object",
        "required": ["uuid", "number", "money"],
        "properties": {
          "uuid": {"type": "string"},
          "number": {"type": "integer", "minimum": 1},
          "money": {"type": "string", "pattern": "^\\d+\\.\\d{2}$"}
        }
      },
      "AlipayOrderPayRequest": {
        "type": "object",
        "required": ["paycode", "money", "equipment_code", "order_type", "msgid"],
        "properties": {
          "dishes": {"type": "array", "items": {"$ref": "#/components/schemas/Dish"}},
          "staff_uuid": {"type": "string", "description": "支付宝付款时留空"},
          "paycode": {"type": "string", "format": "password", "description": "支付宝动态付款码；真实测试可能立即扣款，不应保存为 Apifox 环境固定值"},
          "card_id": {"type": "string", "description": "支付宝付款时必须留空"},
          "money": {"type": "string", "pattern": "^\\d+\\.\\d{2}$", "description": "订单金额，单位元"},
          "equipment_code": {"type": "string"},
          "order_type": {"type": "integer", "enum": [1], "description": "1=在线；支付宝付款码仅支持在线结算"},
          "create_time": {"type": "string", "format": "date-time"},
          "msgid": {"type": "string", "description": "消费机请求唯一号，也是入口防重键；每笔新交易必须不同"}
        }
      },
      "OrderPayResponse": {
        "type": "object",
        "required": ["code", "message"],
        "properties": {
          "code": {"type": "integer", "enum": [0, 1, 2, 8001, 8002], "description": "0=成功；1=明确失败；2=处理中；8001=余额不足；8002=原支付宝交易已关闭，消费机需重新扫码"},
          "message": {"type": "string"},
          "data": {"type": "object", "additionalProperties": true},
          "trace_id": {"type": "string"}
        }
      }
    }
  }
}
