'integer', 'account_type' => 'integer', 'belong_id' => 'integer', 'dept_id' => 'integer', 'master_flag' => 'integer', 'status' => 'integer', 'sex' => 'integer']; public static function getByUsername(string $username, array $field = ['*']) { return self::query()->where("username", $username)->first($field); } public static function getAuths(int $account_id, int $account_type, int $master_flag) { return $master_flag ? Menu::getAuth1($account_type) : Menu::getAuth2($account_id, $account_type); } public static function getInfo(int $account_id): array { $info = self::with('roles') ->with('posts') ->with('dept') ->select(['account_id', 'username', 'nickname', 'avatar', 'bio', 'tags', 'sex', 'birthday', 'create_time']) ->find($account_id); return $info->toArray(); } public static function getById(int $account_id, array $field = ['*']): array { $info = self::where("account_id", $account_id) ->select($field) ->first(); return $info->toArray(); } public static function getMenu(array $account) { // 总后台账号 $field = ['title', 'path', 'pid', 'name', 'menu_id', 'icon', 'hidden']; // 获取角色 $roles = match ($account['account_type']) { 1 => ["ADMIN"], 2 => ["ORG"], 3 => ["MERCHANT"], default => [] }; // 标识 if ($account['master_flag']) { $menus = Menu::getMenu($account['account_type'], $field); $buttons = Menu::getButton($account['account_type']); $roles[] = 'MAIN'; } else { $menus = Menu::getMenu2($account['account_id'], $account['account_type'], $field); $buttons = Menu::getButton2($account['account_id'], $account['account_type']); $roles[] = 'CHILD'; } // 获取商户行业标识 return compact("menus", "buttons", "roles"); } public function roles() { return $this->belongsToMany( Role::class, 'account_role', 'account_id', 'role_id' ); } public function posts() { return $this->belongsToMany( Post::class, 'account_post', 'account_id', 'post_id' ); } public function dept() { return $this->hasOne( Dept::class, 'dept_id', 'dept_id' ); } }