LoginBusiness.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\business;
  3. use Illuminate\Support\Arr;
  4. use support\Db;
  5. use support\Redis;
  6. class LoginBusiness
  7. {
  8. /** 注册
  9. * @param array $param
  10. * @return void
  11. */
  12. static public function login(array $param)
  13. {
  14. try {
  15. $userData = Db::table('wa_users')->where('mobile', $param['mobile'])->first();
  16. if (empty($userData)) {
  17. throw new \Exception('账号不存在');
  18. }
  19. if ($userData->password != md5($param['password'])) {
  20. throw new \Exception('密码不正确');
  21. }
  22. if (empty($userData->status)) {
  23. throw new \Exception('账号已被冻结');
  24. }
  25. $token = jwtEncode(collect($userData)->toArray());
  26. $uid = $userData->id;
  27. if (Arr::get($param, 'app')) {
  28. Db::table('wa_users')->where('id', $uid)->update([
  29. 'is_app' => 1
  30. ]);
  31. }
  32. Db::table('wa_users')->where('id', $uid)->update([
  33. 'last_time' => date('Y-m-d H:i:s'),
  34. ]);
  35. Redis::setEx(getenv('PROJECTWEB') . '_' . $uid, 86400, $token);
  36. } catch (\Throwable $exception) {
  37. throw new \Exception($exception->getMessage());
  38. }
  39. return $token;
  40. }
  41. /** 注册
  42. * @param array $param
  43. * @return void
  44. */
  45. static public function register(array $param)
  46. {
  47. try {
  48. $has = Db::table('wa_users')->where('mobile', $param['mobile'])->exists();
  49. if ($has) {
  50. throw new \Exception('账号已存在');
  51. }
  52. $pidData = Db::table('wa_users')->where('uuid', $param['invitation_code'])->first();
  53. if (empty($pidData)) {
  54. throw new \Exception('邀请码无效');
  55. }
  56. //同IP注册给他限制五个先
  57. $starttime = date('Y-m-d 00:00:00');
  58. $endtimr = date('Y-m-d 23:59:59');
  59. $usercount = Db::table('wa_users')
  60. ->where('created_at', '>=', $starttime)
  61. ->where('created_at', '<=', $endtimr)
  62. ->where('join_ip', $param['join_ip'])->count();
  63. if ($usercount >= 100) {
  64. throw new \Exception('暂不能注册');
  65. }
  66. $array_img = ['/upload/img/20250918/1.png', '/upload/img/20250918/2.png', '/upload/img/20250918/3.png', '/upload/img/20250918/4.png'];
  67. $array_name = ['WB·ED银行卡', 'WB·HC银行卡', 'WB·AG银行卡', 'WB·IP银行卡'];
  68. $randomKey = array_rand($array_img);
  69. $bank_img = $array_img[$randomKey];
  70. $card_name = $array_name[$randomKey];
  71. $add = [
  72. 'name' => '未实名',
  73. 'uuid' => uuid(),
  74. 'mobile' => $param['mobile'],
  75. 'password' => md5($param['password']),
  76. 'pid' => $pidData->id,
  77. 'ppid' => !empty($pidData->pid) ? $pidData->pid : 0,
  78. 'toppid' => !empty($pidData->ppid) ? $pidData->ppid : 0,
  79. 'team_id' => !empty($pidData->team_id) ? $pidData->team_id : 0,
  80. 'last_time' => date('Y-m-d H:i:s'),
  81. 'join_time' => date('Y-m-d H:i:s'),
  82. 'join_ip' => $param['join_ip'],
  83. 'last_ip' => $param['join_ip'],
  84. 'bank_img' => $bank_img,
  85. 'card_name' => $card_name,
  86. 'created_at' => date('Y-m-d H:i:s'),
  87. 'updated_at' => date('Y-m-d H:i:s'),
  88. 'certificate_code' => generateCertificateNumber(12),
  89. ];
  90. $userId = Db::table('wa_users')->insertGetId($add);
  91. /** 给上级增加 人数 */
  92. Db::table('wa_users')->where('id', $pidData->id)->increment('num', 1);
  93. $add['id'] = $userId;
  94. $token = jwtEncode($add);
  95. Redis::setEx(getenv('PROJECTWEB') . '_' . $userId, 86400, $token);
  96. } catch (\Throwable $exception) {
  97. throw new \Exception($exception->getMessage());
  98. }
  99. return $token;
  100. }
  101. }