$userInfo['user_id']]) ->field('id,sn,sex,account,nickname,real_name,avatar,mobile,create_time,is_new_user,user_money,password') ->findOrEmpty(); if (in_array($userInfo['terminal'], [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA])) { $auth = UserAuth::where(['user_id' => $userInfo['user_id'], 'terminal' => $userInfo['terminal']])->find(); $user['is_auth'] = $auth ? YesNoEnum::YES : YesNoEnum::NO; } $user['has_password'] = !empty($user['password']); $user->hidden(['password']); return $user->toArray(); } /** * @notes 个人信息 * @param $userId * @return array * @author 段誉 * @date 2022/9/20 19:45 */ public static function info(int $userId) { $user = User::where(['id' => $userId]) ->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,create_time,user_money,member') ->findOrEmpty(); $user['has_password'] = !empty($user['password']); $user['has_auth'] = self::hasWechatAuth($userId); $user['version'] = config('project.version'); $user['collect_count'] = TeamasterCollect::where("user_id",$userId) ->where("status",1) ->count(); $user['coupon_count'] = UserCoupon::where("user_id",$userId) ->where("status",0) ->count(); $user->hidden(['password']); return $user->toArray(); } /** * @notes 设置用户信息 * @param int $userId * @param array $params * @return User|false * @author 段誉 * @date 2022/9/21 16:53 */ public static function setInfo(int $userId, array $params) { try { if ($params['field'] == "avatar") { $params['value'] = FileService::setFileUrl($params['value']); } return User::update([ 'id' => $userId, $params['field'] => $params['value']] ); } catch (\Exception $e) { self::$error = $e->getMessage(); return false; } } /** * @notes 重置登录密码 * @param $params * @return bool * @author 段誉 * @date 2022/9/16 18:06 */ public static function resetPassword(array $params) { Db::startTrans(); try { // 校验验证码 $smsDriver = new SmsDriver(); if (!$smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA)) { throw new \Exception('验证码错误'); } // 重置密码 $passwordSalt = Config::get('project.unique_identification'); $password = create_password($params['password'], $passwordSalt); if($params['password']!= $params['password_confirm']){ throw new \Exception('两次输入不正确'); } // 更新 StoreUser::where('mobile', $params['mobile'])->update([ 'password' => $password ]); return true; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } }