feat: 新增业务人员公共接口(role_id=2,全量返回)
- PublicApiController 新增 staffList():通过 user_roles 关联筛选业务人员 - 返回 id/name/sn/phone/email,支持 keyword 模糊匹配,不分页全量返回 - 路由组新增 /common/public/staff/list - .gitignore 忽略 docs/*.sql(数据导出文件,不入库) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+2
-1
@@ -13,4 +13,5 @@
|
||||
/bootstrap.php
|
||||
/composer.lock
|
||||
.env_copy
|
||||
/public/excel
|
||||
/public/excel
|
||||
/docs/*.sql
|
||||
@@ -4,12 +4,16 @@ namespace app\common\controller;
|
||||
|
||||
use app\common\model\StockOrders;
|
||||
use app\common\model\StockOrderItems;
|
||||
use app\common\model\User;
|
||||
use support\Request;
|
||||
|
||||
class PublicApiController extends BaseController
|
||||
{
|
||||
protected $noNeedLogin = ['piList', 'vinList'];
|
||||
protected $noNeedHeaderData = ['piList', 'vinList'];
|
||||
// 业务人员固定角色ID
|
||||
protected const STAFF_ROLE_ID = 2;
|
||||
|
||||
protected $noNeedLogin = ['piList', 'vinList', 'staffList'];
|
||||
protected $noNeedHeaderData = ['piList', 'vinList', 'staffList'];
|
||||
|
||||
/**
|
||||
* PI 号列表(含关联的 VIN 和车型名称)
|
||||
@@ -102,4 +106,47 @@ class PublicApiController extends BaseController
|
||||
return $this->error('查询失败,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务人员列表(role_id=2,在职,全量返回)
|
||||
* GET /common/public/staff/list
|
||||
*/
|
||||
public function staffList(Request $request)
|
||||
{
|
||||
try {
|
||||
$keyword = $request->input('keyword', '');
|
||||
|
||||
// 通过 user_roles 关联,筛选指定角色的用户
|
||||
$query = User::whereHas('roles', function ($q) {
|
||||
$q->where('roles.id', static::STAFF_ROLE_ID);
|
||||
})->where('status', 1);
|
||||
|
||||
if ($keyword !== '') {
|
||||
$kw = '%' . addcslashes($keyword, '%_') . '%';
|
||||
$query->where(function ($q) use ($kw) {
|
||||
$q->where('name', 'like', $kw)
|
||||
->orWhere('sn', 'like', $kw)
|
||||
->orWhere('phone', 'like', $kw)
|
||||
->orWhere('email', 'like', $kw);
|
||||
});
|
||||
}
|
||||
|
||||
$list = $query->orderBy('id', 'asc')
|
||||
->get(['id', 'sn', 'name', 'phone', 'email']);
|
||||
|
||||
$data = $list->map(function ($user) {
|
||||
return [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'sn' => $user->sn,
|
||||
'phone' => $user->phone,
|
||||
'email' => $user->email,
|
||||
];
|
||||
})->values()->toArray();
|
||||
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error('查询失败,请稍后重试');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -643,4 +643,5 @@ Route::group('/crm', function () {
|
||||
Route::group('/common/public', function () {
|
||||
Route::any('/pi/list', [app\common\controller\PublicApiController::class, 'piList']);
|
||||
Route::any('/vin/list', [app\common\controller\PublicApiController::class, 'vinList']);
|
||||
Route::any('/staff/list', [app\common\controller\PublicApiController::class, 'staffList']);
|
||||
})->middleware([app\middleware\AccessControl::class, app\middleware\ApiKeyAuth::class]);
|
||||
@@ -146,6 +146,53 @@ GET /common/public/vin/list
|
||||
|
||||
---
|
||||
|
||||
### 3. 业务人员列表
|
||||
|
||||
查询业务人员(角色 role_id=2,在职),全量返回。
|
||||
|
||||
**请求**
|
||||
|
||||
```
|
||||
GET /common/public/staff/list
|
||||
```
|
||||
|
||||
**参数**
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| keyword | string | 否 | 关键词,模糊匹配姓名/编号/电话/邮箱 |
|
||||
|
||||
**响应示例**
|
||||
|
||||
```json
|
||||
{
|
||||
"status": "success",
|
||||
"code": 200,
|
||||
"message": "请求成功",
|
||||
"data": [
|
||||
{
|
||||
"id": 17,
|
||||
"name": "张三",
|
||||
"sn": "S0017",
|
||||
"phone": "13800138000",
|
||||
"email": "zhangsan@example.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**字段说明**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | int | 用户ID |
|
||||
| name | string | 姓名 |
|
||||
| sn | string | 编号 |
|
||||
| phone | string | 电话 |
|
||||
| email | string | 邮箱 |
|
||||
|
||||
---
|
||||
|
||||
## 调用示例
|
||||
|
||||
```bash
|
||||
@@ -164,6 +211,10 @@ curl -H "Fdesk-Api-Key: your-api-key" \
|
||||
# 按 VIN 号搜索
|
||||
curl -H "Fdesk-Api-Key: your-api-key" \
|
||||
"https://your-domain.com/common/public/vin/list?vin=LSVAU2A3"
|
||||
|
||||
# 查询业务人员列表
|
||||
curl -H "Fdesk-Api-Key: your-api-key" \
|
||||
"https://your-domain.com/common/public/staff/list?page=1&page_size=50"
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
Reference in New Issue
Block a user