diff --git a/server/plugin/saiadmin/app/model/system/SystemUser.php b/server/plugin/saiadmin/app/model/system/SystemUser.php index 44475f9..818bf67 100644 --- a/server/plugin/saiadmin/app/model/system/SystemUser.php +++ b/server/plugin/saiadmin/app/model/system/SystemUser.php @@ -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) {