LoginBusiness.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. Redis::setEx(getenv('PROJECTWEB') . '_' . $uid, 86400, $token);
  33. } catch (\Throwable $exception) {
  34. throw new \Exception($exception->getMessage());
  35. }
  36. return $token;
  37. }
  38. /** 注册
  39. * @param array $param
  40. * @return void
  41. */
  42. static public function register(array $param)
  43. {
  44. try {
  45. $has = Db::table('wa_users')->where('mobile', $param['mobile'])->exists();
  46. if ($has) {
  47. throw new \Exception('账号已存在');
  48. }
  49. $pidData = Db::table('wa_users')->where('uuid', $param['invitation_code'])->first();
  50. if (empty($pidData)) {
  51. throw new \Exception('邀请码无效');
  52. }
  53. // //同IP注册给他限制五个先
  54. // $starttime = date('Y-m-d 00:00:00');
  55. // $endtimr = date('Y-m-d 23:59:59');
  56. // $usercount = Db::table('wa_users')
  57. // ->where('created_at','>=',$starttime)
  58. // ->where('created_at','<=',$endtimr)
  59. // ->where('join_ip',$param['join_ip'])->count();
  60. // if($usercount>=5){
  61. // throw new \Exception('暂不能注册');
  62. // }
  63. // $card_code = generateBankAccountNumber();
  64. $add = [
  65. 'name' => '未实名',
  66. 'uuid' => uuid(),
  67. 'mobile' => $param['mobile'],
  68. 'password' => md5($param['password']),
  69. 'pid' => $pidData->id,
  70. 'ppid' => !empty($pidData->pid) ? $pidData->pid : 0,
  71. 'toppid' => !empty($pidData->ppid) ? $pidData->ppid : 0,
  72. 'team_id' => !empty($pidData->team_id) ? $pidData->team_id : 0,
  73. 'last_time' => date('Y-m-d H:i:s'),
  74. 'join_time' => date('Y-m-d H:i:s'),
  75. 'join_ip' => $param['join_ip'],
  76. 'last_ip' => $param['join_ip'],
  77. // 'card_code' => $card_code,
  78. 'created_at' => date('Y-m-d H:i:s'),
  79. 'updated_at' => date('Y-m-d H:i:s'),
  80. // 'certificate_code' => generateCertificateNumber(12),
  81. ];
  82. $userId = Db::table('wa_users')->insertGetId($add);
  83. /** 给上级增加 人数 */
  84. Db::table('wa_users')->where('id', $pidData->id)->increment('num', 1);
  85. $add['id'] = $userId;
  86. $token = jwtEncode($add);
  87. Redis::setEx(getenv('PROJECTWEB') . '_' . $userId, 86400, $token);
  88. } catch (\Throwable $exception) {
  89. throw new \Exception($exception->getMessage());
  90. }
  91. return $token;
  92. }
  93. }