diff --git a/app/controller/AdminAgentTeam.php b/app/controller/AdminAgentTeam.php index 08e758c..d4848e2 100644 --- a/app/controller/AdminAgentTeam.php +++ b/app/controller/AdminAgentTeam.php @@ -9,6 +9,7 @@ use app\model\AdminUpScoresRecords; use app\model\AgentRechargeRecords; use app\model\AgentUser; use app\validate\Admin; +use app\validate\Agent; use think\exception\ValidateException; use think\facade\Db; use think\facade\Request; @@ -144,4 +145,48 @@ class AdminAgentTeam extends BaseController return $this->renderError($exception->getMessage()); } } + + /** + * 编辑代理信息 + */ + public function editUser() + { + $param = Request::param(); + + try { + + validate(Agent::class)->scene('edit')->check($param); + + $UserModel = new AgentUser(); + $result = $UserModel->retrieve($param); + + if (!$result['status']) throw new ValidateException($result['msg']); + + return $this->renderSuccess($result['msg']); + } catch (ValidateException $validateException) { + return $this->renderError($validateException->getMessage()); + } + } + + /** + * 删除代理 + * @return array + */ + public function deleteUser() + { + $param = Request::param(); + + try { + + validate(Agent::class)->scene('del')->check($param); + + $result = AgentUser::destroy($param['aid']); + + if (!$result) throw new ValidateException('删除失败'); + + return $this->renderSuccess('已删除'); + } catch (ValidateException $validateException) { + return $this->renderError($validateException->getMessage()); + } + } } diff --git a/app/model/AdminUser.php b/app/model/AdminUser.php index b8f15e9..d3d0b1b 100644 --- a/app/model/AdminUser.php +++ b/app/model/AdminUser.php @@ -5,17 +5,12 @@ namespace app\model; use think\facade\Session; use think\Model; -use think\model\concern\SoftDelete; /** * @mixin \think\Model */ class AdminUser extends Model { - use SoftDelete; - protected $deleteTime = 'delete_time'; - protected $defaultSoftDelete = 0; - /** * 管理员登陆 diff --git a/app/model/AgentUser.php b/app/model/AgentUser.php index 1a1e0b1..2b85140 100644 --- a/app/model/AgentUser.php +++ b/app/model/AgentUser.php @@ -5,13 +5,16 @@ namespace app\model; use think\facade\Session; use think\Model; +use think\model\concern\SoftDelete; /** * @mixin \think\Model */ class AgentUser extends Model { - // + use SoftDelete; + protected $deleteTime = 'delete_time'; + protected $defaultSoftDelete = 0; /** * 代理登陆 @@ -161,6 +164,45 @@ class AgentUser extends Model return ['status' => 1]; } + /** + * 找回密码 + * @param $data + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function retrieve($data) + { + // 根据代理手机号和代理id修改密码 + $user = []; + $errorMsg = ''; + if (isset($data['phone'])) { + $errorMsg = '手机号'; + $user = $this->where('phone', $data['phone'])->find(); + } elseif ($data['aid']) { + $errorMsg = '代理账号'; + $user = $this->find($data['aid']); + } + + if ($user) { + + // 生成盐值 + $salt = generate_random_str(6); + $password = $this->generateHashedPassword($data['password'], $salt); + // 密码加盐值后哈希存储 + $user->password = $password; + $user->salt = $salt; + $user->update_time = date("Y-m-d H:i:s",time()); + $user->save(); + + return ['status' => true, 'msg' => '密码重制成功']; + } + + return ['status' => false, 'msg' => $errorMsg.'未注册']; + } + + /** * 生成密码 * @param $password diff --git a/app/validate/Agent.php b/app/validate/Agent.php index 3bd65c2..82dfadc 100644 --- a/app/validate/Agent.php +++ b/app/validate/Agent.php @@ -15,7 +15,9 @@ class Agent extends Validate */ protected $rule = [ 'user_id|用户id' => 'require|number', - 'quota|额度' => 'require|number' + 'quota|额度' => 'require|number', + 'password|密码' => 'require|min:6|max:20', + 'aid|代理id' => 'require|number', ]; /** @@ -27,6 +29,8 @@ class Agent extends Validate protected $message = []; protected $scene = [ - 'scores' => ['user_id','quota'] + 'scores' => ['user_id','quota'], + 'edit' => ['aid','password'], + 'del' => ['aid'], ]; }