where('mobile', $param['mobile'])->first(); if (empty($userData)) { throw new \Exception('账号不存在'); } if ($userData->password != md5($param['password'])) { throw new \Exception('密码不正确'); } if (empty($userData->status)) { throw new \Exception('账号已被冻结'); } $token = jwtEncode(collect($userData)->toArray()); $uid = $userData->id; if (Arr::get($param, 'app')) { Db::table('wa_users')->where('id', $uid)->update([ 'is_app' => 1 ]); } Redis::setEx(getenv('PROJECTWEB') . '_' . $uid, 86400, $token); } catch (\Throwable $exception) { throw new \Exception($exception->getMessage()); } return $token; } /** 注册 * @param array $param * @return void */ static public function register(array $param) { try { $has = Db::table('wa_users')->where('mobile', $param['mobile'])->exists(); if ($has) { throw new \Exception('账号已存在'); } $pidData = Db::table('wa_users')->where('uuid', $param['invitation_code'])->first(); if (empty($pidData)) { throw new \Exception('邀请码无效'); } // //同IP注册给他限制五个先 // $starttime = date('Y-m-d 00:00:00'); // $endtimr = date('Y-m-d 23:59:59'); // $usercount = Db::table('wa_users') // ->where('created_at','>=',$starttime) // ->where('created_at','<=',$endtimr) // ->where('join_ip',$param['join_ip'])->count(); // if($usercount>=5){ // throw new \Exception('暂不能注册'); // } // $card_code = generateBankAccountNumber(); $add = [ 'name' => '未实名', 'uuid' => uuid(), 'mobile' => $param['mobile'], 'password' => md5($param['password']), 'pid' => $pidData->id, 'ppid' => !empty($pidData->pid) ? $pidData->pid : 0, 'toppid' => !empty($pidData->ppid) ? $pidData->ppid : 0, 'team_id' => !empty($pidData->team_id) ? $pidData->team_id : 0, 'last_time' => date('Y-m-d H:i:s'), 'join_time' => date('Y-m-d H:i:s'), 'join_ip' => $param['join_ip'], 'last_ip' => $param['join_ip'], // 'card_code' => $card_code, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), // 'certificate_code' => generateCertificateNumber(12), ]; $userId = Db::table('wa_users')->insertGetId($add); /** 给上级增加 人数 */ Db::table('wa_users')->where('id', $pidData->id)->increment('num', 1); $add['id'] = $userId; $token = jwtEncode($add); Redis::setEx(getenv('PROJECTWEB') . '_' . $userId, 86400, $token); } catch (\Throwable $exception) { throw new \Exception($exception->getMessage()); } return $token; } }