Browse Source

新增代理接口

master
wanghongjun 3 years ago
parent
commit
d61ae242f5
  1. 26
      app/controller/AdminAgentTeam.php
  2. 31
      app/model/AgentUser.php
  3. 2
      app/validate/Agent.php
  4. 2
      route/app.php

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

31
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

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

2
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();
});
# 支付(待开发)

Loading…
Cancel
Save