Browse Source

删除 编辑 代理接口

master
wanghongjun 3 years ago
parent
commit
df48e9659a
  1. 45
      app/controller/AdminAgentTeam.php
  2. 5
      app/model/AdminUser.php
  3. 44
      app/model/AgentUser.php
  4. 8
      app/validate/Agent.php

45
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());
}
}
}

5
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;
/**
* 管理员登陆

44
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

8
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'],
];
}

Loading…
Cancel
Save