model = new \app\admin\model\User; } /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->with('group') ->where($where) ->order($sort, $order) ->paginate($limit); $rows = []; foreach ($list as $k => $v) { $v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname); $v->hidden(['password', 'salt']); $item = $v->toArray(); // 手机号全量展示(v1.0.8): // 微信登录注册的会员默认没有绑定手机号(fa_user.mobile 为空), // 此时回落到「该会员最近一条发布信息里的联系电话」,并标记来源 mobile_source=post; // 两者都没有则返回空串,前端显示「未绑定」。 $mobile = trim((string)$item['mobile']); if ($mobile === '') { $postPhone = Db::name('fc_post') ->where('user_id', $v->id) ->where('phone', '<>', '') ->whereNull('deletetime') ->order('id desc') ->value('phone'); if ($postPhone) { $item['mobile'] = (string)$postPhone; $item['mobile_source'] = 'post'; } } $rows[] = $item; } $result = ["total" => $list->total(), "rows" => $rows]; return json($result); } return $this->view->fetch(); } /** * 添加 */ public function add() { if ($this->request->isPost()) { $this->token(); } return parent::add(); } /** * 编辑 */ 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')); } $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker'])); return parent::edit($ids); } /** * 删除 */ public function del($ids = "") { if (!$this->request->isPost()) { $this->error(__("Invalid parameters")); } $ids = $ids ? $ids : $this->request->post("ids"); $row = $this->model->get($ids); $this->modelValidate = true; if (!$row) { $this->error(__('No Results were found')); } Auth::instance()->delete($row['id']); $this->success(); } }