// +---------------------------------------------------------------------- namespace App\Models; use App\Services\Common\UserRoleService; /** * 会员管理-模型 * @author laravel开发员 * @since 2020/11/10 * Class AdminModel * @package App\Models */ class UserModel extends BaseModel { // 设置数据表 protected $table = 'user'; protected $appends = ['mobile_text']; /** * @return array */ public function getmobileTextAttribute() { return $this->mobile? format_mobile($this->mobile):''; } /** * 获取数据信息 * @param int $id 用户ID * @return array|string * @author laravel开发员 * @since 2020/11/10 */ public function getInfo($id) { $info = parent::getInfo($id); if ($info) { // 头像 if ($info['avatar']) { $info['avatar'] = get_image_url($info['avatar']); } // 性别 if ($info['gender']) { $info['gender_name'] = config('admin.gender_list')[$info['gender']]; } // 获取用户角色列表 $userRoleService = new UserRoleService(); $roleList = $userRoleService->getUserRoleList($id); $info['roles'] = $roleList; } return $info; } }