第三段完善 代理商绑定 激活等 正式上线的版本
This commit is contained in:
@@ -43,6 +43,7 @@ class Agent extends Controller
|
||||
'parent_id.default' => 0,
|
||||
'commission_rate.require' => '佣金比例不能为空',
|
||||
'status.default' => 1,
|
||||
'admin_id.default' => 0, // 绑定的管理员ID
|
||||
'remark.default' => ''
|
||||
]);
|
||||
|
||||
@@ -62,6 +63,19 @@ class Agent extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
// 如果绑定了管理员账号,检查是否存在
|
||||
if (!empty($data['admin_id'])) {
|
||||
$admin = Db::name('system_user')->where('id', $data['admin_id'])->find();
|
||||
if (empty($admin)) {
|
||||
$this->error('管理员账号不存在!');
|
||||
}
|
||||
// 检查管理员账号是否已被绑定
|
||||
$exists = Db::name('cursor_agents')->where('admin_id', $data['admin_id'])->find();
|
||||
if ($exists) {
|
||||
$this->error('该管理员账号已被其他代理商绑定!');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理密码
|
||||
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
|
||||
$data['created_at'] = $data['updated_at'] = date('Y-m-d H:i:s');
|
||||
@@ -77,6 +91,13 @@ class Agent extends Controller
|
||||
->where('level', 1)
|
||||
->where('status', 1)
|
||||
->select();
|
||||
|
||||
// 获取管理员列表
|
||||
$this->admins = Db::name('system_user')
|
||||
->where('status', 1)
|
||||
->field('id, username, nickname')
|
||||
->select();
|
||||
|
||||
$this->fetch();
|
||||
}
|
||||
}
|
||||
@@ -87,8 +108,85 @@ class Agent extends Controller
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$this->_applyFormToken();
|
||||
$this->_form('cursor_agents', 'form');
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->_vali([
|
||||
'id.require' => '代理商ID不能为空',
|
||||
'username.require' => '用户名不能为空',
|
||||
'password.default' => '',
|
||||
'nickname.default' => '',
|
||||
'level.require' => '代理级别不能为空',
|
||||
'parent_id.default' => 0,
|
||||
'commission_rate.require' => '佣金比例不能为空',
|
||||
'status.default' => 1,
|
||||
'admin_id.default' => 0, // 绑定的管理员ID
|
||||
'remark.default' => ''
|
||||
]);
|
||||
|
||||
// 检查用户名是否存在
|
||||
$exists = Db::name('cursor_agents')
|
||||
->where('username', $data['username'])
|
||||
->where('id', '<>', $data['id'])
|
||||
->find();
|
||||
if ($exists) {
|
||||
$this->error('用户名已存在!');
|
||||
}
|
||||
|
||||
// 如果是二级代理,检查上级代理
|
||||
if ($data['level'] == 2) {
|
||||
if (empty($data['parent_id'])) {
|
||||
$this->error('请选择上级代理!');
|
||||
}
|
||||
$parent = Db::name('cursor_agents')->where('id', $data['parent_id'])->find();
|
||||
if (empty($parent) || $parent['level'] != 1) {
|
||||
$this->error('上级代理不存在或不是一级代理!');
|
||||
}
|
||||
}
|
||||
|
||||
// 如果绑定了管理员账号,检查是否存在
|
||||
if (!empty($data['admin_id'])) {
|
||||
$admin = Db::name('system_user')->where('id', $data['admin_id'])->find();
|
||||
if (empty($admin)) {
|
||||
$this->error('管理员账号不存在!');
|
||||
}
|
||||
// 检查管理员账号是否已被其他代理商绑定
|
||||
$exists = Db::name('cursor_agents')
|
||||
->where('admin_id', $data['admin_id'])
|
||||
->where('id', '<>', $data['id'])
|
||||
->find();
|
||||
if ($exists) {
|
||||
$this->error('该管理员账号已被其他代理商绑定!');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理密码
|
||||
if (!empty($data['password'])) {
|
||||
$data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
|
||||
} else {
|
||||
unset($data['password']);
|
||||
}
|
||||
|
||||
$data['updated_at'] = date('Y-m-d H:i:s');
|
||||
|
||||
if (Db::name('cursor_agents')->update($data) !== false) {
|
||||
$this->success('更新成功!');
|
||||
} else {
|
||||
$this->error('更新失败!');
|
||||
}
|
||||
} else {
|
||||
// 获取一级代理列表(用于选择上级)
|
||||
$this->agents = Db::name('cursor_agents')
|
||||
->where('level', 1)
|
||||
->where('status', 1)
|
||||
->select();
|
||||
|
||||
// 获取管理员列表
|
||||
$this->admins = Db::name('system_user')
|
||||
->where('status', 1)
|
||||
->field('id, username, nickname')
|
||||
->select();
|
||||
|
||||
$this->_form('cursor_agents', 'form');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user