|
@@ -3,8 +3,14 @@
|
|
|
namespace app\admin\controller\user;
|
|
|
|
|
|
use app\admin\model\Message;
|
|
|
+use app\admin\model\UserPower;
|
|
|
use app\common\controller\Backend;
|
|
|
use app\common\library\Auth;
|
|
|
+use fast\Random;
|
|
|
+use think\Db;
|
|
|
+use think\Exception;
|
|
|
+use think\exception\PDOException;
|
|
|
+use think\exception\ValidateException;
|
|
|
|
|
|
/**
|
|
|
* 会员管理
|
|
@@ -27,6 +33,7 @@ class User extends Backend
|
|
|
parent::_initialize();
|
|
|
$this->model = model('User');
|
|
|
$typeList = [
|
|
|
+ 'genderList' => $this->model->getGenderList(),
|
|
|
'isCoolList' => $this->model->getIsCoolList(),
|
|
|
'isManagerList' => $this->model->getIsManagerList(),
|
|
|
];
|
|
@@ -68,12 +75,60 @@ class User extends Backend
|
|
|
/**
|
|
|
* 添加
|
|
|
*/
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ */
|
|
|
public function add()
|
|
|
{
|
|
|
if ($this->request->isPost()) {
|
|
|
- $this->token();
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ $params = $this->preExcludeFields($params);
|
|
|
+ if (!$params) {
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ $result = false;
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ //是否采用模型验证
|
|
|
+ if ($this->modelValidate) {
|
|
|
+ $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
+ $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
|
|
|
+ $this->model->validateFailException(true)->validate($validate);
|
|
|
+ }
|
|
|
+ if (empty($params['avatar'])) {
|
|
|
+ $params['avatar'] = '/assets/img/default_avatar.png';
|
|
|
+ }
|
|
|
+ $ids = $this->model->column("u_id");
|
|
|
+ $invite_no = $this->model->column("invite_no");
|
|
|
+ $params['u_id'] = $this->model->getUinqueId(8, [$ids]);
|
|
|
+ $params['invite_no'] = $this->model->getUinqueNo(8, $invite_no);
|
|
|
+ if (empty($params['nickname'])) {
|
|
|
+ $params['nickname'] = 'gg_'.$params['u_id'];
|
|
|
+ }
|
|
|
+ $params['image'] = '/assets/img/default_avatar.png';
|
|
|
+ $params['username'] = $params['mobile'];
|
|
|
+ $params['status'] = 'normal';
|
|
|
+ $params['salt'] = Random::alnum();
|
|
|
+ $params['has_info'] = 1;
|
|
|
+ $result = $this->model->allowField(true)->save($params);
|
|
|
+ $userId = $this->model->id;
|
|
|
+ $userPower = new UserPower();
|
|
|
+ $userPowerData['user_id'] = $userId;
|
|
|
+ $userPowerRes = $userPower->insertGetId($userPowerData);
|
|
|
+ if (!$userPowerRes) {
|
|
|
+ throw new Exception('创建用户权限失败');
|
|
|
+ }
|
|
|
+ } catch (ValidateException|PDOException|Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ if ($result == false) {
|
|
|
+ $this->error(__('No rows were inserted'));
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ $this->success();
|
|
|
}
|
|
|
- return parent::add();
|
|
|
+ return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -81,15 +136,55 @@ class User extends Backend
|
|
|
*/
|
|
|
public function edit($ids = null)
|
|
|
{
|
|
|
- if ($this->request->isPost()) {
|
|
|
- $this->token();
|
|
|
- }
|
|
|
$row = $this->model->get($ids);
|
|
|
- $this->modelValidate = true;
|
|
|
if (!$row) {
|
|
|
$this->error(__('No Results were found'));
|
|
|
}
|
|
|
- return parent::edit($ids);
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds)) {
|
|
|
+ if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
|
|
+ $this->error(__('You have no permission'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ if (!$params) {
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ $params = $this->preExcludeFields($params);
|
|
|
+ $result = false;
|
|
|
+ try {
|
|
|
+ //是否采用模型验证
|
|
|
+ if ($this->modelValidate) {
|
|
|
+ $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
+ $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
|
|
|
+ $row->validateFailException(true)->validate($validate);
|
|
|
+ }
|
|
|
+ if (!empty($params['u_id'])) {
|
|
|
+ $userWhere['u_id'] = $params['u_id'];
|
|
|
+ $user = $this->model->where($userWhere)->find();
|
|
|
+ if (!empty($user)) {
|
|
|
+ throw new Exception('前端用户ID已存在');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($params['mobile'])) {
|
|
|
+ $userWhere['mobile'] = $params['mobile'];
|
|
|
+ $user = $this->model->where($userWhere)->find();
|
|
|
+ if (!empty($user)) {
|
|
|
+ throw new Exception('手机号已存在');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $result = $row->allowField(true)->save($params);
|
|
|
+ } catch (ValidateException|PDOException|Exception $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ if ($result == false) {
|
|
|
+ $this->error(__('No rows were updated'));
|
|
|
+ }
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
+ $this->view->assign("row", $row);
|
|
|
+ return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|