# 客户管理

> 模块标识：customer  |  接口数量：7

## 1. 获取客户列表
**方法**：	GET

**路径**：				/api/customers

**功能说明**：
分页获取客户列表

### 请求参数
```json
{
  "query": [
    {
      "name": "pageNum",
      "type": "number",
      "required": false,
      "description": "页码，默认1"
    },
    {
      "name": "pageSize",
      "type": "number",
      "required": false,
      "description": "每页数量，默认10"
    },
    {
      "name": "name",
      "type": "string",
      "required": false,
      "description": "客户名称关键词"
    },
    {
      "name": "status",
      "type": "number",
      "required": false,
      "description": "状态过滤"
    }
  ]
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "获取成功",
    "data": {
      "list": [
        {
          "id": 1,
          "code": "CUS0001",
          "name": "示例客户",
          "contactName": "李四",
          "contactPhone": "021-88888888",
          "status": 1
        }
      ],
      "total": 100,
      "pageNum": 1,
      "pageSize": 10,
      "authorizedToMeCustomers": [
        {
          "id": 2,
          "code": "CUS0002",
          "name": "被授权客户",
          "contactName": "王五",
          "contactPhone": "021-66666666",
          "status": 1,
          "grantorUser": {
            "userId": "USER0002",
            "username": "授权方用户",
            "phone": "13800000002",
            "userType": "User"
          },
          "authorizationCreateTime": "2026-04-15T09:00:00.000Z",
          "authorizationUpdateTime": "2026-04-15T09:30:00.000Z"
        }
      ],
      "authorizedByMeCustomers": [
        {
          "customerId": 3,
          "granteeUser": {
            "userId": "USER0003",
            "username": "接收方用户",
            "phone": "13800000003",
            "userType": "User"
          },
          "authorizationCreateTime": "2026-04-15T10:00:00.000Z",
          "authorizationUpdateTime": "2026-04-15T10:15:00.000Z"
        }
      ]
    }
  }
}
```


## 2. 获取客户详情
**方法**：	GET

**路径**：				/api/customers/{id}

**功能说明**：
根据客户ID获取客户详细信息

### 请求参数
```json
{
  "path": [
    {
      "name": "id",
      "type": "string",
      "required": true,
      "description": "客户ID"
    }
  ]
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "获取成功",
    "data": {
      "id": 1,
      "code": "CUS0001",
      "name": "示例客户",
      "contactName": "李四",
      "contactPhone": "021-88888888",
      "status": 1
    }
  },
  "failure": {
    "code": "4040",
    "message": "客户不存在",
    "data": null
  }
}
```


## 3. 创建客户
**方法**：	POST

**路径**：				/api/customers

**功能说明**：
创建新的客户

### 请求参数
```json
{
  "body": {
    "name": "string｜必填，客户名称",
    "contactName": "string｜可选，联系人姓名",
    "contactPhone": "string｜可选，联系人电话",
    "status": "number｜可选，状态：1-合作中，0-已终止"
  }
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "创建客户成功",
    "data": {
      "id": 1,
      "code": "CUS0001",
      "name": "示例客户",
      "contactName": "李四",
      "contactPhone": "021-88888888",
      "status": 1
    }
  },
  "failure": {
    "code": "4000",
    "message": "创建客户失败",
    "data": null
  }
}
```


## 4. 更新客户
**方法**：	PUT

**路径**：				/api/customers/{id}

**功能说明**：
更新指定客户的信息

### 请求参数
```json
{
  "body": {
    "name": "string｜必填，客户名称",
    "contactName": "string｜可选，联系人姓名",
    "contactPhone": "string｜可选，联系人电话",
    "status": "number｜可选，状态：1-合作中，0-已终止"
  },
  "path": [
    {
      "name": "id",
      "type": "string",
      "required": true,
      "description": "客户ID"
    }
  ]
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "更新客户成功",
    "data": {
      "id": 1,
      "code": "CUS0001",
      "name": "示例客户",
      "contactName": "李四",
      "contactPhone": "021-88888888",
      "status": 1
    }
  },
  "failure": {
    "code": "4000",
    "message": "更新客户失败",
    "data": null
  }
}
```


## 5. 客户授权
**方法**：	POST

**路径**：				/api/customers/authorize

**功能说明**：
将指定客户授权给目标用户

### 请求参数
```json
{
  "body": {
    "customerIds": "array｜必填，客户ID列表",
    "targetUserId": "string｜必填，接收授权的用户ID",
    "targetUserType": "string｜可选，用户类型（User/ClientUser）"
  }
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "客户授权成功",
    "data": {
      "createdCount": 2,
      "skippedCount": 1
    }
  },
  "failure": {
    "code": "4000",
    "message": "客户授权失败",
    "data": null
  }
}
```


## 6. 解除客户授权
**方法**：	POST

**路径**：				/api/customers/unauthorize

**功能说明**：
解除当前用户对指定客户授予目标用户的授权

### 请求参数
```json
{
  "body": {
    "customerIds": "array｜必填，客户ID列表",
    "targetUserId": "string｜必填，接收授权的用户ID",
    "targetUserType": "string｜可选，用户类型（User/ClientUser）"
  }
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "客户授权解除成功",
    "data": {
      "revokedCount": 2
    }
  },
  "failure": {
    "code": "4000",
    "message": "解除客户授权失败",
    "data": null
  }
}
```


## 7. 删除客户
**方法**：	DELETE

**路径**：				/api/customers/{id}

**功能说明**：
删除指定的客户

### 请求参数
```json
{
  "path": [
    {
      "name": "id",
      "type": "string",
      "required": true,
      "description": "客户ID"
    }
  ]
}
```

### 响应示例
```json
{
  "success": {
    "code": "0000",
    "message": "删除客户成功",
    "data": {
      "result": true
    }
  },
  "failure": {
    "code": "4000",
    "message": "删除客户失败",
    "data": null
  }
}
```

