diff --git a/app/controller/AdminAgentTeam.php b/app/controller/AdminAgentTeam.php index 10ea162..6a2c1c3 100644 --- a/app/controller/AdminAgentTeam.php +++ b/app/controller/AdminAgentTeam.php @@ -189,4 +189,30 @@ class AdminAgentTeam extends BaseController return $this->renderError($validateException->getMessage()); } } + + /** + * 新增代理 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function addAgent() + { + $param = Request::param(); + + try { + + validate(Agent::class)->scene('register')->check($param); + + $AgentUser = new AgentUser(); + $result = $AgentUser->register($param); + + if (!$result) throw new ValidateException('代理已存在'); + + return $this->renderSuccess('添加成功'); + } catch (ValidateException $validateException) { + return $this->renderError($validateException->getMessage()); + } + } } diff --git a/app/model/AgentUser.php b/app/model/AgentUser.php index 2b85140..5732bc2 100644 --- a/app/model/AgentUser.php +++ b/app/model/AgentUser.php @@ -55,6 +55,37 @@ class AgentUser extends Model } } + /** + * 注册、创建代理 + * @param $data + * @return bool + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function register($data) + { + $user = $this->where('phone', $data['phone'])->find(); + if ($user) return false; + + // 生成盐值 + $salt = generate_random_str(6); + // 密码加盐值后哈希存储 + $password = $this->generateHashedPassword($data['password'], $salt); + + $this->save([ + // 随机头像 + 'avatar' => rand_avatar(), + 'password' => $password, + 'salt' => $salt, + 'phone' => $data['phone'], + 'invite_code' => generate_random_str(6), + 'create_time' => date("Y-m-d H:i:s",time()) + ]); + + return true; + } + /** * 扣减余额(给用户上分) * @param $aid diff --git a/app/validate/Agent.php b/app/validate/Agent.php index 82dfadc..d65ea55 100644 --- a/app/validate/Agent.php +++ b/app/validate/Agent.php @@ -18,6 +18,7 @@ class Agent extends Validate 'quota|额度' => 'require|number', 'password|密码' => 'require|min:6|max:20', 'aid|代理id' => 'require|number', + 'phone|手机号' => 'require|mobile', ]; /** @@ -32,5 +33,6 @@ class Agent extends Validate 'scores' => ['user_id','quota'], 'edit' => ['aid','password'], 'del' => ['aid'], + 'register' => ['phone','password'], ]; } diff --git a/route/app.php b/route/app.php index e765b40..e4c3d11 100644 --- a/route/app.php +++ b/route/app.php @@ -63,12 +63,14 @@ Route::group('adminUserTeam',function() { Route::post('upScores','adminUserTeam/upScores')->middleware(CheckAdmin::class)->allowCrossDomain(); Route::post('downScores','adminUserTeam/downScores')->middleware(CheckAdmin::class)->allowCrossDomain(); }); + Route::group('adminAgentTeam',function() { Route::post('agentList','adminAgentTeam/agentList')->middleware(CheckAdmin::class)->allowCrossDomain(); Route::post('agentUpScores','adminAgentTeam/agentUpScores')->middleware(CheckAdmin::class)->allowCrossDomain(); Route::post('agentDownScores','adminAgentTeam/agentDownScores')->middleware(CheckAdmin::class)->allowCrossDomain(); Route::post('editAgent','adminAgentTeam/editAgent')->middleware(CheckAdmin::class)->allowCrossDomain(); Route::post('deleteAgent','adminAgentTeam/deleteAgent')->middleware(CheckAdmin::class)->allowCrossDomain(); + Route::post('addAgent','adminAgentTeam/addAgent')->middleware(CheckAdmin::class)->allowCrossDomain(); }); # 支付(待开发)