webman-admin普通管理员添加限制为auth数据时无法自动生成admin_id,看Crud.php中代码好像必须要前台传admin_id参数过来,不能自动获取当前管理员ID.
/**
* 插入前置方法
* @param Request $request
* @return array
* @throws BusinessException
*/
protected function insertInput(Request $request): array
{
$data = $this->inputFilter($request->post());
$password_filed = 'password';
if (isset($data[$password_filed])) {
$data[$password_filed] = Util::passwordHash($data[$password_filed]);
}
if (!Auth::isSuperAdmin()) {
if ($this->dataLimit === 'personal') {
$data[$this->dataLimitField] = admin_id();
} elseif ($this->dataLimit === 'auth') {
if (!empty($data[$this->dataLimitField])) {
$admin_id = $data[$this->dataLimitField];
if (!in_array($admin_id, Auth::getScopeAdminIds(true))) {
throw new BusinessException('无数据权限');
}
}
}
} elseif ($this->dataLimit && empty($data[$this->dataLimitField])) {
$data[$this->dataLimitField] = admin_id();
}
return $data;
}
1、添加普通管理员
2、普通管理员登录添加限制为auth的数据提示缺少admin_id
windows10 Workerman version:4.1.15
发下报错,报错发全
SQLSTATE[HY000]: General error: 1364 Field 'admin_id' doesn't have a default value (SQL: insert into
wa_cars
(plate
,carmodel
,carseries
,driver_id
,review
,insure
,mileage
,status
,updated_at
,created_at
) values (ddd, z5s, benchi, 5, ?, ?, ?, 0, 2024-06-05 14:01:43, 2024-06-05 14:01:43))SQL报错的意思是向 wa_cars 表写入数据的时候没传 admin_id,传下admin_id就好了。和权限是不是auth没有关系
admin_id不是应该自动生成吗,你看代码中如果是超级管理员就会自动生成,为什么普通管理员就不行?这是基于什么考虑吗
if (!Auth::isSuperAdmin()) {
if ($this->dataLimit === 'personal') {
$data[$this->dataLimitField] = admin_id(); //personal权限会自动生成admin_id参数
} elseif ($this->dataLimit === 'auth') { //为什么auth权限就不能自动生成admin_id参数而必须要手动传这个参数?
if (!empty($data[$this->dataLimitField])) {
$admin_id = $data[$this->dataLimitField];
if (!in_array($admin_id, Auth::getScopeAdminIds(true))) {
throw new BusinessException('无数据权限');
}
}
}
} elseif ($this->dataLimit && empty($data[$this->dataLimitField])) {
$data[$this->dataLimitField] = admin_id();//超级管理员权限会自动生成admin_id参数
}
改成这样试下