UserLogic.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\logic;
  20. use EasyWeChat\Factory;
  21. use app\common\{enum\DistributionConfigEnum,
  22. enum\UserTerminalEnum,
  23. enum\YesNoEnum,
  24. model\DistributionConfig,
  25. model\GoodsCollect,
  26. model\User,
  27. model\Order,
  28. enum\PayEnum,
  29. enum\OrderEnum,
  30. enum\CouponEnum,
  31. model\UserAuth,
  32. model\UserLevel,
  33. logic\BaseLogic,
  34. model\AfterSale,
  35. model\CouponList,
  36. enum\AfterSaleEnum,
  37. model\UserTransfer,
  38. service\FileService,
  39. enum\AccountLogEnum,
  40. service\ConfigService,
  41. logic\AccountLogLogic,
  42. service\sms\SmsDriver,
  43. service\WeChatConfigService,
  44. service\WeChatService};
  45. use think\Exception;
  46. use think\facade\Config;
  47. use think\facade\Db;
  48. /**
  49. * 会员逻辑层
  50. * Class UserLogic
  51. * @package app\shopapi\logic
  52. */
  53. class UserLogic extends BaseLogic
  54. {
  55. /**
  56. * @notes 个人中心
  57. * @param int $userId
  58. * @return array
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\DbException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @author cjhao
  63. * @date 2021/8/6 19:16
  64. */
  65. public function centre(array $userInfo): array
  66. {
  67. $user = User::with('user_level')->field('id,sn,sex,nickname,avatar,user_money,user_integral,mobile,level,create_time,code,is_new_user,is_register_award')
  68. ->find($userInfo['user_id']);
  69. $user->level_rank = $user->rank ?? '';
  70. $user->level_name = $user->name ?? '';
  71. //待支付
  72. $user->wait_pay = Order::where(['user_id' => $userInfo['user_id'], 'order_status' => OrderEnum::STATUS_WAIT_PAY, 'pay_status' => PayEnum::UNPAID])->count();
  73. //待发货
  74. $user->wait_delivery = Order::where(['user_id' => $userInfo['user_id'], 'order_status' => OrderEnum::STATUS_WAIT_DELIVERY, 'pay_status' => PayEnum::ISPAID])->count();
  75. //待收货
  76. $user->wait_take = Order::where(['user_id' => $userInfo['user_id'], 'order_status' => OrderEnum::STATUS_WAIT_RECEIVE, 'pay_status' => PayEnum::ISPAID])->count();
  77. //待评论
  78. $user->wait_comment = Order::alias('O')
  79. ->join('order_goods OG', 'OG.order_id = O.id')
  80. ->where(['user_id' => $userInfo['user_id'], 'is_comment' => YesNoEnum::NO, 'order_status' => OrderEnum::STATUS_FINISH, 'pay_status' => PayEnum::ISPAID])
  81. ->count();
  82. //退款、售后
  83. $user->after_sale = AfterSale::where(['user_id' => $userInfo['user_id'], 'status' => AfterSaleEnum::STATUS_ING])->count();
  84. //优惠券
  85. $user->coupon = CouponList::where([
  86. ['user_id', '=', $userInfo['user_id']],
  87. ['status', '=', CouponEnum::USE_STATUS_NOT],
  88. ['invalid_time', '>=', time()]
  89. ])->count();
  90. //收藏数量
  91. $user->collect = GoodsCollect::where(['user_id' => $userInfo['user_id']])->count();
  92. // 自定义邀请海报
  93. $dbConfig = DistributionConfig::column('value', 'key');
  94. $dbConfig['apply_image'] = $dbConfig['apply_image'] ?? DistributionConfigEnum::DEFAULT_APPLY_IMAGE;
  95. $dbConfig['poster'] = $dbConfig['poster'] ?? DistributionConfigEnum::DEFAULT_POSTER;
  96. $dbConfig['apply_image'] = FileService::getFileUrl($dbConfig['apply_image']);
  97. $dbConfig['poster'] = FileService::getFileUrl($dbConfig['poster']);
  98. $user->poster = $dbConfig['poster'];
  99. $user->apply_image = $dbConfig['apply_image'];
  100. //是否有微信授权登录
  101. if (in_array($userInfo['terminal'], [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA])) {
  102. $auth = UserAuth::where(['user_id' => $userInfo['user_id'], 'terminal' => $userInfo['terminal']])->find();
  103. $user->is_auth = $auth ? 1 : 0;
  104. }
  105. $user->hidden(['name', 'rank']);
  106. return $user->toArray();
  107. }
  108. /**
  109. * @notes 设置用户信息
  110. * @param int $userId
  111. * @param array $params
  112. * @return bool
  113. * @author cjhao
  114. * @date 2021/8/6 19:44
  115. */
  116. public static function setInfo(int $userId, array $params): bool
  117. {
  118. User::update(['id' => $userId, $params['field'] => $params['value']]);
  119. return true;
  120. }
  121. /**
  122. * @notes 绑定手机号
  123. * @param $params
  124. * @return bool
  125. * @author Tab
  126. * @date 2021/8/25 17:55
  127. */
  128. public static function bindMobile($params)
  129. {
  130. try {
  131. $smsDriver = new SmsDriver();
  132. $result = $smsDriver->verify($params['mobile'], $params['code']);
  133. if (!$result) {
  134. throw new \Exception('验证码错误');
  135. }
  136. $user = User::where('mobile', $params['mobile'])->findOrEmpty();
  137. if (!$user->isEmpty()) {
  138. throw new \Exception('该手机号已被其他账号绑定');
  139. }
  140. unset($params['code']);
  141. User::update($params);
  142. return true;
  143. } catch (\Exception $e) {
  144. self::setError($e->getMessage());
  145. return false;
  146. }
  147. }
  148. /**
  149. * @notes 绑定推荐人
  150. * @param $params
  151. * @return bool
  152. * @author Tab
  153. * @date 2021/8/25 17:55
  154. */
  155. public static function bindInviterId($params)
  156. {
  157. try {
  158. $user = User::where('id', $params['id'])->findOrEmpty();
  159. if ($user->inviter_id) {
  160. throw new \Exception('您已经绑定过推荐人了!无需重复绑定');
  161. }
  162. $bind_user = User::where('code', $params['inviter_code'])->findOrEmpty();
  163. unset($params['code']);
  164. $params['inviter_id'] = $bind_user['id'];
  165. User::update($params);
  166. return true;
  167. } catch (\Exception $e) {
  168. self::setError($e->getMessage());
  169. return false;
  170. }
  171. }
  172. /**
  173. * @notes 会员中心
  174. * @param int $userId
  175. * @return array
  176. * @throws \think\db\exception\DataNotFoundException
  177. * @throws \think\db\exception\DbException
  178. * @throws \think\db\exception\ModelNotFoundException
  179. * @author cjhao
  180. * @date 2021/8/9 11:03
  181. */
  182. public function userLevel(int $userId): array
  183. {
  184. $user = User::field('id,nickname,avatar,level')->find($userId);
  185. $levelList = UserLevel::order(['rank' => 'asc'])->withoutField('remark,create_time,update_time,delete_time')->select();
  186. $levelName = '';
  187. foreach ($levelList as $levelKey => $level) {
  188. if ($level->discount > 0) {
  189. $level->discount = '会员折扣:' . floatval($level->discount) . '折';
  190. }
  191. //下个等级
  192. $level->next_level = $levelList[$levelKey + 1]->name ?? '';
  193. $level->status = 0;
  194. if ($user->level == $level->id) {
  195. $level->status = 1;
  196. $levelName = $level->name;
  197. $user->rank = $level->rank;//更新为等级权重
  198. }
  199. //会员条件
  200. $conditionArray = [];
  201. if ($level->condition) {
  202. $condition = \app\common\logic\UserLogic::formatLevelCondition($level->condition);
  203. //没有设置条件;直接返回空数组
  204. if ('' === $condition['condition_type']) {
  205. $level->condition = $conditionArray;
  206. continue;
  207. }
  208. $level->condition_tips = '满足以下任意条件即可升级';
  209. //满足全部条件
  210. if ($condition['condition_type']) {
  211. $level->condition_tips = '满足以下全部条件即可升级';
  212. }
  213. //单笔消费满足金额
  214. if ($condition['is_single_money'] && $condition['single_money'] > 0) {
  215. $conditionArray[] = '单消费金额满' . $condition['single_money'] . '元';
  216. }
  217. //累计消费金额
  218. if ($condition['is_total_money'] && $condition['total_money'] > 0) {
  219. $conditionArray[] = '累计消费金额满' . $condition['total_money'] . '元';
  220. }
  221. //累计消费次数
  222. if ($condition['is_total_num'] && $condition['total_num'] > 0) {
  223. $conditionArray[] = '累计消费次数' . $condition['total_num'] . '次';
  224. }
  225. }
  226. $level->condition = $conditionArray;
  227. }
  228. $user->level_name = $levelName;
  229. $data = [
  230. 'user' => $user,
  231. 'level_list' => $levelList,
  232. ];
  233. return $data;
  234. }
  235. /**
  236. * @notes 余额转账
  237. * @param $params
  238. * @return false
  239. * @author Tab
  240. * @date 2021/8/12 9:15
  241. */
  242. public static function transfer($params)
  243. {
  244. Db::startTrans();
  245. try {
  246. // 扣减自身余额
  247. $me = User::findOrEmpty($params['user_id']);
  248. $me->user_money = $me->user_money - $params['money'];
  249. $me->save();
  250. // 记录账户流水
  251. AccountLogLogic::add($me->id, AccountLogEnum::BNW_DEC_TRANSFER, AccountLogEnum::DEC, $params['money'], '', '余额转账-转出');
  252. // 增加收款方余额
  253. $transferIn = User::whereOr('sn', $params['transfer_in'])
  254. ->whereOr('mobile', $params['transfer_in'])
  255. ->findOrEmpty();
  256. $transferIn->user_money = $transferIn->user_money + $params['money'];
  257. $transferIn->save();
  258. // 记录账户流水
  259. AccountLogLogic::add($transferIn->id, AccountLogEnum::BNW_INC_TRANSFER, AccountLogEnum::INC, $params['money'], '', '余额转账-转入');
  260. // 转账记录
  261. UserTransfer::create([
  262. 'transfer_out' => $me->id,
  263. 'transfer_in' => $transferIn->id,
  264. 'money' => $params['money']
  265. ]);
  266. Db::commit();
  267. return true;
  268. } catch (\Exception $e) {
  269. Db::rollback();
  270. self::setError($e->getMessage());
  271. return false;
  272. }
  273. }
  274. /**
  275. * @notes 最近转账记录(3条)
  276. * @param $userId
  277. * @return mixed
  278. * @author Tab
  279. * @date 2021/8/12 10:35
  280. */
  281. public static function transferRecent($userId)
  282. {
  283. $lists = UserTransfer::alias('ut')
  284. ->leftJoin('user u', 'u.id = ut.transfer_in')
  285. ->field('u.avatar,u.sn,u.nickname')
  286. ->distinct(true)
  287. ->where('ut.transfer_out', $userId)
  288. ->where('u.user_delete', 0)
  289. ->limit(3)
  290. ->select()
  291. ->toArray();
  292. foreach ($lists as &$item) {
  293. $item['avatar'] = FileService::getFileUrl($item['avatar']);
  294. }
  295. return $lists;
  296. }
  297. /**
  298. * @notes 收款用户信息
  299. * @param $params
  300. * @return array|false
  301. * @author Tab
  302. * @date 2021/8/12 11:03
  303. */
  304. public static function transferIn($params)
  305. {
  306. try {
  307. $user = User::field('avatar,nickname,sn,mobile,user_delete')
  308. ->where('sn|mobile', $params['transfer_in'])
  309. ->findOrEmpty();
  310. if ($user->isEmpty() || $user->user_delete) {
  311. throw new \think\Exception('收款用户不存在');
  312. }
  313. return $user->toArray();
  314. } catch (\Exception $e) {
  315. self::setError($e->getMessage());
  316. return false;
  317. }
  318. }
  319. /**
  320. * @notes 判断用户是否已设置支付密码
  321. * @param $userId
  322. * @return bool
  323. * @author Tab
  324. * @date 2021/8/17 10:31
  325. */
  326. public static function hasPayPassword($userId)
  327. {
  328. $user = User::findOrEmpty($userId);
  329. if (empty($user->pay_password)) {
  330. return ['has_pay_password' => false];
  331. }
  332. return ['has_pay_password' => true];
  333. }
  334. /**
  335. * @notes 设置/修改交易密码
  336. * @param $params
  337. * @return bool
  338. * @author Tab
  339. * @date 2021/8/12 11:32
  340. */
  341. public static function setPayPassword($params)
  342. {
  343. try {
  344. $user = User::findOrEmpty($params['user_id']);
  345. if (empty($user->pay_password)) {
  346. // 首次设置密码
  347. $user->pay_password = md5($params['pay_password']);
  348. $user->save();
  349. return true;
  350. }
  351. // 修改密码
  352. if (!isset($params['origin_pay_password']) || empty($params['origin_pay_password'])) {
  353. throw new \think\Exception('请输入原支付密码');
  354. }
  355. if ($user->pay_password != md5($params['origin_pay_password'])) {
  356. throw new \think\Exception('原支付密码错误');
  357. }
  358. // 设置新支付密码
  359. $user->pay_password = md5($params['pay_password']);
  360. $user->save();
  361. return true;
  362. } catch (\Exception $e) {
  363. self::setError($e->getMessage());
  364. return false;
  365. }
  366. }
  367. /**
  368. * @notes 重置支付密码
  369. * @param $params
  370. * @return bool
  371. * @author Tab
  372. * @date 2021/8/24 16:30
  373. */
  374. public static function resetPayPassword($params)
  375. {
  376. try {
  377. // 校验验证码
  378. $smsDriver = new SmsDriver();
  379. if (!$smsDriver->verify($params['mobile'], $params['code'])) {
  380. throw new \Exception('验证码错误');
  381. }
  382. $params['pay_password'] = md5($params['pay_password']);
  383. unset($params['code']);
  384. unset($params['mobile']);
  385. User::update($params);
  386. return true;
  387. } catch (\Exception $e) {
  388. self::setError($e->getMessage());
  389. return false;
  390. }
  391. }
  392. /**
  393. * @notes 重置登录密码
  394. * @param $params
  395. * @return bool
  396. * @author Tab
  397. * @date 2021/8/25 17:03
  398. */
  399. public static function resetPassword($params)
  400. {
  401. try {
  402. // 校验验证码
  403. $smsDriver = new SmsDriver();
  404. if (!$smsDriver->verify($params['mobile'], $params['code'])) {
  405. throw new \Exception('验证码错误');
  406. }
  407. $passwordSalt = Config::get('project.unique_identification');
  408. $password = create_password($params['password'], $passwordSalt);
  409. User::where('mobile', $params['mobile'])->update([
  410. 'password' => $password
  411. ]);
  412. return true;
  413. } catch (\Exception $e) {
  414. self::setError($e->getMessage());
  415. return false;
  416. }
  417. }
  418. /**
  419. * @notes 钱包
  420. * @param $userId
  421. * @return array
  422. * @author Tab
  423. * @date 2021/8/12 14:58
  424. */
  425. public static function wallet($userId)
  426. {
  427. $user = User::findOrEmpty($userId);
  428. $rechargeOpen = ConfigService::get('recharge', 'open');
  429. $rechargeMinAmount = ConfigService::get('recharge', 'min_amount');
  430. $userMoney = is_null($user->user_money) ? 0 : $user->user_money;
  431. $userEarnings = is_null($user->user_earnings) ? 0 : $user->user_earnings;
  432. $totalOrderAmount = is_null($user->total_order_amount) ? 0 : $user->total_order_amount;
  433. return [
  434. 'user_money' => $userMoney,
  435. 'user_earnings' => $userEarnings,
  436. 'total_amount' => round($userMoney + $userEarnings, 2),
  437. 'recharge_open' => $rechargeOpen,
  438. 'recharge_min_amount' => $rechargeMinAmount,
  439. 'total_order_amount' => $totalOrderAmount,
  440. ];
  441. }
  442. /**
  443. * @notes 用户信息
  444. * @param $userId
  445. * @return array
  446. * @author Tab
  447. * @date 2021/8/25 17:22
  448. */
  449. public static function info($userId)
  450. {
  451. $user = User::field('sn,avatar,nickname,sex,mobile,create_time')->findOrEmpty($userId)->toArray();
  452. $user['has_password'] = empty($user['password']) ? '未设置' : '已设置';
  453. $user['version'] = request()->header('version');
  454. return $user;
  455. }
  456. /**
  457. * @notes 获取微信手机号
  458. * @param $params
  459. * @return array|false
  460. * @author Tab
  461. * @date 2021/8/24 15:20
  462. * @deprecated 小程序获取手机号码更新升级,旧接口放弃
  463. */
  464. public static function getMobileByMnp($params)
  465. {
  466. try {
  467. $config = [
  468. 'app_id' => ConfigService::get('mini_program', 'app_id'),
  469. 'secret' => ConfigService::get('mini_program', 'app_secret'),
  470. ];
  471. $app = Factory::miniProgram($config);
  472. $response = $app->auth->session($params['code']);
  473. if (!isset($response['session_key'])) {
  474. throw new \Exception('获取用户信息失败');
  475. }
  476. $response = $app->encryptor->decryptData($response['session_key'], $params['iv'], $params['encrypted_data']);
  477. $user = User::where([
  478. ['mobile', '=', $response['phoneNumber']],
  479. ['id', '<>', $params['user_id']]
  480. ])->findOrEmpty();
  481. if (!$user->isEmpty()) {
  482. throw new \Exception('手机号已被其他账号绑定');
  483. }
  484. // 绑定手机号
  485. self::setInfo($params['user_id'], [
  486. 'field' => 'mobile',
  487. 'value' => $response['phoneNumber']
  488. ]);
  489. return true;
  490. } catch (\Exception $e) {
  491. self::setError($e->getMessage());
  492. return false;
  493. }
  494. }
  495. /**
  496. * @notes 微信小程序获取手机号码并绑定
  497. * @param $params
  498. * @return bool
  499. * @throws \GuzzleHttp\Exception\GuzzleException
  500. * @author cjhao
  501. * @date 2022/5/17 9:34
  502. */
  503. public static function getNewMobileByMnp($params)
  504. {
  505. try {
  506. $getMnpConfig = WeChatConfigService::getMnpConfig();
  507. $app = Factory::miniProgram($getMnpConfig);
  508. $response = $app->phone_number->getUserPhoneNumber($params['code']);
  509. $phoneNumber = $response['phone_info']['purePhoneNumber'] ?? '';
  510. if(empty($phoneNumber)){
  511. throw new Exception('获取手机号码失败');
  512. }
  513. $user = User::where([
  514. ['mobile', '=', $phoneNumber],
  515. ['id', '<>', $params['user_id']]
  516. ])->findOrEmpty();
  517. if (!$user->isEmpty()) {
  518. throw new \Exception('手机号已被其他账号绑定');
  519. }
  520. // 绑定手机号
  521. self::setInfo($params['user_id'], [
  522. 'field' => 'mobile',
  523. 'value' => $phoneNumber
  524. ]);
  525. return true;
  526. } catch (\Exception $e) {
  527. self::setError($e->getMessage());
  528. return false;
  529. }
  530. }
  531. /**
  532. * @notes 获取服务协议
  533. * @return array
  534. * @author Tab
  535. * @date 2021/8/24 16:48
  536. */
  537. public static function getServiceAgreement()
  538. {
  539. $data = [
  540. 'service_agreement_name' => ConfigService::get('shop', 'service_agreement_name', ''),
  541. 'service_agreement_content' => ConfigService::get('shop', 'service_agreement_content', ''),
  542. ];
  543. return $data;
  544. }
  545. /**
  546. * @notes 获取隐私政策
  547. * @return array
  548. * @author Tab
  549. * @date 2021/8/24 16:50
  550. */
  551. public static function getPrivacyPolicy()
  552. {
  553. $data = [
  554. 'privacy_policy_name' => ConfigService::get('shop', 'privacy_policy_name', ''),
  555. 'privacy_policy_content' => ConfigService::get('shop', 'privacy_policy_content', '')
  556. ];
  557. return $data;
  558. }
  559. /**
  560. * @notes 设置登录密码
  561. * @author Tab
  562. * @date 2021/10/22 18:10
  563. */
  564. public static function setPassword($params)
  565. {
  566. try {
  567. $user = User::findOrEmpty($params['user_id']);
  568. if ($user->isEmpty()) {
  569. throw new \Exception('用户不存在');
  570. }
  571. if (!empty($user->password)) {
  572. throw new \Exception('用户已设置登录密码');
  573. }
  574. $passwordSalt = Config::get('project.unique_identification');
  575. $password = create_password($params['password'], $passwordSalt);
  576. $user->password = $password;
  577. $user->save();
  578. return true;;
  579. } catch (\Exception $e) {
  580. self::setError($e->getMessage());
  581. return false;
  582. }
  583. }
  584. /**
  585. * @notes 修改登录密码
  586. * @param $params
  587. * @return bool
  588. * @author Tab
  589. * @date 2021/10/22 18:17
  590. */
  591. public static function changePassword($params)
  592. {
  593. try {
  594. $user = User::findOrEmpty($params['user_id']);
  595. if ($user->isEmpty()) {
  596. throw new \Exception('用户不存在');
  597. }
  598. $passwordSalt = Config::get('project.unique_identification');
  599. $oldPassword = create_password($params['old_password'], $passwordSalt);
  600. $newPassword = create_password($params['password'], $passwordSalt);
  601. if ($user->password != $oldPassword) {
  602. throw new \Exception('原密码错误');
  603. }
  604. $user->password = $newPassword;
  605. $user->save();
  606. return true;;
  607. } catch (\Exception $e) {
  608. self::setError($e->getMessage());
  609. return false;
  610. }
  611. }
  612. /**
  613. * @notes 判断用户是否有设置登录密码
  614. * @param $userId
  615. * @author Tab
  616. * @date 2021/10/22 18:25
  617. */
  618. public static function hasPassword($userId)
  619. {
  620. $user = User::findOrEmpty($userId);
  621. return empty($user->password) ? false : true;
  622. }
  623. static function updateRegisterAward($userId)
  624. {
  625. User::update([
  626. 'id' => $userId,
  627. 'is_register_award' => 1,
  628. ]);
  629. }
  630. }