SystemUser新增agent_id字段
This commit is contained in:
@@ -14,6 +14,7 @@ use plugin\saiadmin\basic\think\BaseModel;
|
|||||||
* sa_system_user 用户表
|
* sa_system_user 用户表
|
||||||
*
|
*
|
||||||
* @property $id
|
* @property $id
|
||||||
|
* @property $agent_id 代理标识,md5(id)唯一
|
||||||
* @property $username 登录账号
|
* @property $username 登录账号
|
||||||
* @property $password 加密密码
|
* @property $password 加密密码
|
||||||
* @property $realname 真实姓名
|
* @property $realname 真实姓名
|
||||||
@@ -49,6 +50,30 @@ class SystemUser extends BaseModel
|
|||||||
*/
|
*/
|
||||||
protected $table = 'sa_system_user';
|
protected $table = 'sa_system_user';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入后:自动填充 agent_id = md5(id),保证唯一
|
||||||
|
*/
|
||||||
|
public static function onAfterInsert($model): void
|
||||||
|
{
|
||||||
|
$id = $model->getAttr('id');
|
||||||
|
if ($id !== null && $id !== '') {
|
||||||
|
$agentId = md5((string) $id);
|
||||||
|
(new static())->where('id', $id)->update(['agent_id' => $agentId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 agent_id:若未存储则返回 md5(id)
|
||||||
|
*/
|
||||||
|
public function getAgentIdAttr($value, $data)
|
||||||
|
{
|
||||||
|
if ($value !== null && $value !== '') {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
$id = $data['id'] ?? null;
|
||||||
|
return $id !== null ? md5((string) $id) : '';
|
||||||
|
}
|
||||||
|
|
||||||
public function searchKeywordAttr($query, $value)
|
public function searchKeywordAttr($query, $value)
|
||||||
{
|
{
|
||||||
if ($value) {
|
if ($value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user