modelClass = new UserModel; $this->assign('groupCache', UserGroup::column('name', 'id')); } /** * 会员列表 */ public function index() { $this->relationSearch = true; if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } [$page, $limit, $where, $sort, $order] = $this->buildTableParames(); $list = $this->modelClass ->withJoin(['group' => ['id', 'name']]) ->where($where) ->page($page, $limit) ->select(); $total = $this->modelClass ->withJoin(['group']) ->where($where) ->order($sort, $order) ->count(); $result = ["code" => 0, "count" => $total, "data" => $list]; return json($result); } return $this->fetch(); } /** * 会员增加 */ public function add() { if ($this->request->isPost()) { $params = $this->request->post("row/a"); try { $this->validate($params, 'app\admin\validate\user\User'); } catch (ValidateException $e) { $this->error($e->getMessage()); } if (Auth::instance()->register($params['username'], $params['password'], $params['email'], $params['mobile'], $params)) { $this->success("添加会员成功!", url("index")); } else { $this->error(Auth::instance()->getError() ?: '添加会员失败!'); } } else { return $this->fetch(); } } /** * 会员编辑 */ public function edit() { if ($this->request->isPost()) { $userid = $this->request->param('id/d', 0); $params = $this->request->post("row/a"); try { $this->validate($params, 'app\admin\validate\user\User.edit'); } catch (ValidateException $e) { $this->error($e->getMessage()); } //获取用户信息 $row = UserModel::find($userid); if (empty($row)) { $this->error('该会员不存在!'); } $row->save($params); $this->success("更新成功!", url("index")); } else { $userid = $this->request->param('id/d', 0); $data = $this->modelClass->find($userid); if (empty($data)) { $this->error("该会员不存在!"); } $this->assign("data", $data); return $this->fetch(); } } /** * 会员删除 */ public function del() { $ids = $this->request->param('id/a', null); if (empty($ids)) { $this->error('请选择需要删除的会员!'); } if (!is_array($ids)) { $ids = [0 => $ids]; } foreach ($ids as $uid) { Auth::instance()->delete($uid); } $this->success("删除成功!"); } }