# 订单支付API文档

## 概述
本文档描述了客户端订单支付相关的API接口，包括创建订单、支付、退款等完整流程。

## 基础信息
- 基础URL: `/client/order`
- 请求方式: REST API
- 数据格式: JSON
- 认证方式: Token认证

## 订单状态说明
- 1: 已创建 - 订单创建成功，等待支付
- 2: 已支付 - 支付成功，等待服务开始
- 3: 已完成 - 服务完成
- 4: 已退款 - 订单已退款
- 5: 已取消 - 订单已取消

## 支付方式
- aliPay: 支付宝支付
- wechatPay: 微信支付
- applePay: Apple Pay支付

## API接口

### 1. 创建订单
**接口地址**: `POST /client/order/create`

**请求参数**:
```json
{
    "orderName": "VIP会员包月",
    "amount": 9900,
    "payType": "aliPay",
    "packageType": "1",
    "deviceType": "android"
}
```

**响应示例**:
```json
{
    "code": 200,
    "msg": "订单创建成功",
    "data": {
        "id": "uuid",
        "orderId": 1706342400000,
        "orderName": "VIP会员包月",
        "userId": 1,
        "amount": 9900,
        "payType": "aliPay",
        "payStatus": 1,
        "packageType": "1",
        "deviceType": "android",
        "createTime": "2025-01-27 10:00:00"
    }
}
```

### 2. 支付订单
**接口地址**: `POST /client/order/pay`

**请求参数**:
```json
{
    "orderId": "1706342400000",
    "payType": "aliPay",
    "deviceType": "android",
    "paymentParams": "{}"
}
```

**响应示例**:
```json
{
    "code": 200,
    "msg": "支付请求成功",
    "data": {
        "paymentUrl": "https://openapi.alipay.com/gateway.do?",
        "orderId": "1706342400000",
        "amount": 9900,
        "payType": "aliPay"
    }
}
```

### 3. 支付回调
**接口地址**: `POST /client/order/callback`

**请求参数**:
- orderId: 订单ID
- tradeNo: 第三方交易号
- payType: 支付方式

**响应示例**:
```json
{
    "code": 200,
    "msg": "支付完成"
}
```

### 4. 申请退款
**接口地址**: `POST /client/order/refund`

**请求参数**:
```json
{
    "orderId": "1706342400000",
    "refundAmount": 9900,
    "refundReason": "用户申请退款",
    "refundType": 1
}
```

**响应示例**:
```json
{
    "code": 200,
    "msg": "退款申请成功"
}
```

### 5. 查询用户订单列表
**接口地址**: `GET /client/order/list`

**响应示例**:
```json
{
    "code": 200,
    "msg": "查询成功",
    "data": [
        {
            "id": "uuid",
            "orderId": "1706342400000",
            "orderName": "VIP会员包月",
            "amount": 9900,
            "payType": "aliPay",
            "payStatus": 2,
            "payTime": "2025-01-27 10:05:00",
            "startTime": "2025-01-27 10:05:00",
            "endTime": "2025-02-27 10:05:00",
            "createTime": "2025-01-27 10:00:00"
        }
    ]
}
```

### 6. 查询订单详情
**接口地址**: `GET /client/order/detail/{orderId}`

**响应示例**:
```json
{
    "code": 200,
    "msg": "查询成功",
    "data": {
        "id": "uuid",
        "orderId": "1706342400000",
        "orderName": "VIP会员包月",
        "userId": 1,
        "amount": 9900,
        "payType": "aliPay",
        "payStatus": 2,
        "payTime": "2025-01-27 10:05:00",
        "startTime": "2025-01-27 10:05:00",
        "endTime": "2025-02-27 10:05:00",
        "tradeNo": "2025012722001234567890",
        "createTime": "2025-01-27 10:00:00",
        "updateTime": "2025-01-27 10:05:00"
    }
}
```

## 错误码说明
- 200: 成功
- 400: 请求参数错误
- 401: 用户未登录
- 403: 权限不足
- 404: 资源不存在
- 500: 服务器内部错误

## 套餐类型说明
- 1: 包月
- 3: 包季度
- 6: 半年
- 12: 一年

## 设备类型说明
- android: Android设备
- ios: iOS设备

## 注意事项
1. 所有金额单位为分
2. 支付回调需要验证签名
3. 退款只能对已支付的订单进行
4. 订单创建后需要在指定时间内完成支付
5. 支付成功后会自动计算服务时间 