diff --git a/.gitignore b/.gitignore index 224ad2d..05b9fd5 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ /bootstrap.php /composer.lock .env_copy -/public/excel \ No newline at end of file +/public/excel +/docs/*.sql \ No newline at end of file diff --git a/app/common/controller/PublicApiController.php b/app/common/controller/PublicApiController.php index e4222d2..588bd17 100644 --- a/app/common/controller/PublicApiController.php +++ b/app/common/controller/PublicApiController.php @@ -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('查询失败,请稍后重试'); + } + } } diff --git a/config/route.php b/config/route.php index 02c32da..e7872d4 100644 --- a/config/route.php +++ b/config/route.php @@ -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]); \ No newline at end of file diff --git a/docs/public-stock-api.md b/docs/public-stock-api.md index 94529b1..96751bf 100644 --- a/docs/public-stock-api.md +++ b/docs/public-stock-api.md @@ -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" ``` ## 注意事项