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:
mzl
2026-06-18 13:37:48 +08:00
parent 71dca13119
commit b89ac48dd8
4 changed files with 103 additions and 3 deletions
+49 -2
View File
@@ -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('查询失败,请稍后重试');
}
}
}