model = new \app\admin\model\service\skill\Perfect; $this->view->assign("applytypeList", $this->model->getApplytypeList()); $this->view->assign("sexList", $this->model->getSexList()); $this->view->assign("eduList", $this->model->getEduList()); $this->view->assign("experList", $this->model->getExperList()); $this->view->assign("stateList", $this->model->getStateList()); } /** * 查看 * @return string|\think\response\Json * @throws \think\Exception * @throws \think\exception\DbException */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if (false === $this->request->isAjax()) { return $this->view->fetch(); } //如果发送的来源是 Selectpage,则转发到 Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $list = $this->model ->where($where) ->where('applytype',1) ->order($sort, $order) ->paginate($limit); foreach ($list as $row) { $row->goodsname = $row->goods_ids?(new Goods())->getGoodsList($row->goods_ids):''; $row->skill_cate_name = $row->skill_cate_id?\app\admin\model\service\skill\Skillcate::where('id',$row->skill_cate_id)->value('name'):''; $row->create_time = date("Y-m-d H:i",$row->createtime); $row->update_time = $row->updatetime ? date("Y-m-d H:i",$row->updatetime):''; } $result = ['total' => $list->total(), 'rows' => $list->items()]; return json($result); } /** * 编辑 * @param $ids * @return string|void * @throws \think\Exception * @throws \think\exception\DbException */ public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $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 . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } $result = $row->allowField(true)->save($params); if($params['state'] == 1) { $data = db('service_apply_skill')->where('id',$row->id)->find(); $skill = new Skill(); $skill->allowField(true)->save($data,['user_id'=>$row->user_id]); } Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } public function agree($ids = null) { $row = $this->model->get($ids); $params['state'] = 1; $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 . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } $result = $row->allowField(true)->save($params); $data = db('service_apply_skill')->where('id',$row->id)->find(); unset($data['id']); $skill = new Skill(); $skill->allowField(true)->save($data,['user_id'=>$row->user_id]); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success('信息已更新'); } public function refuse($ids = null) { $row = $this->model->get($ids); if (false === $this->request->isPost()) { $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); $params['state'] = -1; $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 . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } $result = $row->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } }