SystemUser新增agent_id字段

This commit is contained in:
2026-03-10 10:54:40 +08:00
parent 7716929447
commit 9452fd28e2

View File

@@ -14,6 +14,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* sa_system_user 用户表
*
* @property $id
* @property $agent_id 代理标识md5(id)唯一
* @property $username 登录账号
* @property $password 加密密码
* @property $realname 真实姓名
@@ -49,6 +50,30 @@ class SystemUser extends BaseModel
*/
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)
{
if ($value) {