// +---------------------------------------------------------------------- namespace app\talent\controller; use app\admin\model\UserModel; use app\talent\model\TalentModel; use cmf\controller\AdminBaseController; class AdminTalentController extends AdminBaseController { public function index() { $param = $this->request->param(); //搜索条件 $where = []; if (!empty($param['name'])) { $where[] = ['name', 'like', "%{$param['name']}%"]; } if (!empty($param['card_no'])) { $where[] = ['card_no', 'like', "%{$param['card_no']}%"]; } if (!empty($param['mobile'])) { $where[] = ['mobile', '=', $param['mobile']]; } $list = TalentModel::where($where)->paginate(10, false, ['query' => $param]); $this->assign('name', isset($param['name']) ? $param['name'] : ''); $this->assign('card_no', isset($param['card_no']) ? $param['card_no'] : ''); $this->assign('mobile', isset($param['mobile']) ? $param['mobile'] : ''); $this->assign('list', $list->items()); $this->assign('page', $list->render()); return $this->fetch(); } public function add() { return $this->fetch(); } public function addPost() { if ($this->request->isPost()) { $data = $this->request->post(); TalentModel::create($data); $this->success('添加成功!', url('index')); } } public function edit() { $id = $this->request->param('id', 0, 'intval'); $info = TalentModel::get($id); $this->assign('info', $info); return $this->fetch(); } public function editPost() { if ($this->request->isPost()) { $data = $this->request->post(); TalentModel::update($data, ['id' => $data['id']]); $this->success('编辑成功!', url('index')); } } public function delete() { $id = $this->request->param('id', 0, 'intval'); TalentModel::destroy($id); UserModel::update(['talent_id' => 0], ['talent_id' => $id]); $this->success('删除成功'); } public function clearBind() { $id = $this->request->param('id', 0, 'intval'); UserModel::update(['talent_id' => 0], ['talent_id' => $id]); $this->success('操作成功'); } public function setting() { $setting = cmf_get_option('talent_setting'); $this->assign($setting); return $this->fetch(); } public function settingPost() { $post = array_map('trim', $this->request->param()); if (strlen($post['mobile']) != 11) { $this->error('手机号格式错误。'); } cmf_set_option('talent_setting', $post); $this->success("保存成功!"); } }