model = new \app\common\model\user4s\Visit; $this->user_model = new \app\common\model\user4s\User(); $this->type_model = new \app\common\model\user4s\Visittype(); $this->log_model = new \app\common\model\user4s\Visitlog(); $this->view->assign("statusList", $this->model->getStatusList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //当前是否为关联查询 $this->relationSearch = true; //设置过滤方法 $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(); //var_dump($this->request->request()); $list = $this->model ->with(['visittype', 'user', 'admin']) ->where($where) ->order($sort, $order) ->paginate($limit); foreach ($list as $row) { } $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } /** * 添加 */ public function add() { if (!$this->request->isPost()) { $user4s_id = $this->request->get("user4s_id/d"); if ($user4s_id > 0) { $user4s=$this->user_model->get($user4s_id); //var_dump($user4s); if(isset($user4s->id)){ $this->view->assign("user4s", $user4s); } } } return parent::add(); } /** * 编辑 */ 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)) { 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) { $params = $this->preExcludeFields($params); $result = false; $this->model->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(true)->validate($validate); } $result = $row->allowField(true)->save($params); $this->model->commit(); } catch (ValidateException $e) { $this->model->rollback(); $this->error($e->getMessage()); } catch (PDOException $e) { $this->model->rollback(); $this->error($e->getMessage()); } catch (Exception $e) { $this->model->rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success(); } else { $this->error(__('No rows were updated')); } } $this->error(__('Parameter %s can not be empty', '')); } $this->view->assign("row", $row); return $this->view->fetch(); } /** * 回访记录 没有使用提交记录 提交在visitlog->add中 */ public function visitlog($vid = null) { if ($this->request->isPost()) { $this->token(); } $row = $this->model->get($vid); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } $all_type = $this->type_model->where('deletetime', null)->column('id,name'); $all_star = array( 1=>'★', 2=>'★★', 3=>'★★★', 4=>'★★★★', 5=>'★★★★★', ); if ($this->request->isAjax()) { //当前是否为关联查询 $this->relationSearch = true; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } $where_v = ['visit_id'=>$row->id]; list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->log_model ->with(['visittype', 'user', 'visit','admin']) ->where($where) ->where($where_v) ->order($sort, $order) ->paginate($limit); foreach ($list as &$item) { //$item->visit_time_f=date('Y-m-d',$item->visit_time); //var_dump($item->visit_time_f); $item->star_f = $all_star[$item->star]; } //var_dump($list->items()); $result = array("total" => $list->total(), "rows" => $list->items(),'all_star'=>$all_star); return json($result); } if ($this->request->isPost()) { $params = $this->request->post("row/a"); //回访记录 if (!empty($params['inscom']) && !empty($params['insdate'])) { $log_data = array( 'user4s_id' => $row->id, 'admin_id'=>$this->auth->id, 'inscom'=>$params['inscom'], 'insdate'=>$params['insdate'], 'star'=>$params['star'], 'description'=>$params['description'] ); $this->Inslog_model = new \app\common\model\user4s\Inslog(); $this->Inslog_model->isUpdate(false)->save($log_data); $user_data = array( 'inscom'=>$params['inscom'], 'insdate'=>$params['insdate'], ); $this->model->save($user_data, ['id' => $row->id]); }else{ $this->error('请填写续保信息',url('user4s/user/expireins',['user4s_id'=>$row->id])); } $this->success('续保成功!',url('user4s/user/expireins',['user4s_id'=>$row->id])); } $this->view->assign("now", date('Y-m-d')); $this->view->assign("all_star", $all_star); $this->view->assign('row', $row); return $this->view->fetch(); } /** * 记录回访情况 废弃 未使用 */ public function pushlog($vid = null) { if ($this->request->isPost()) { $this->token(); } $row = $this->model->get($vid); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } $all_type = $this->type_model->where('deletetime', null)->column('id,name'); $all_star = array( 1=>'★', 2=>'★★', 3=>'★★★', 4=>'★★★★', 5=>'★★★★★', ); if ($this->request->isAjax()) { //当前是否为关联查询 $this->relationSearch = true; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } $where_v = ['visit_id'=>$row->id]; list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->log_model ->with(['visittype', 'user', 'visit','admin']) ->where($where) ->where($where_v) ->order($sort, $order) ->paginate($limit); foreach ($list as &$item) { $item->visit_time_f=date('Y-m-d',$item->visit_time); //var_dump($item->visit_time_f); $item->star_f = $all_star[$item->star]; } //var_dump($list->items()); $result = array("total" => $list->total(), "rows" => $list->items(),'all_star'=>$all_star); return json($result); } if ($this->request->isPost()) { $params = $this->request->post("row/a"); //回访记录 if (!empty($params['inscom']) && !empty($params['insdate'])) { $log_data = array( 'user4s_id' => $row->id, 'admin_id'=>$this->auth->id, 'inscom'=>$params['inscom'], 'insdate'=>$params['insdate'], 'star'=>$params['star'], 'description'=>$params['description'] ); $this->Inslog_model = new \app\common\model\user4s\Inslog(); $this->Inslog_model->isUpdate(false)->save($log_data); $user_data = array( 'inscom'=>$params['inscom'], 'insdate'=>$params['insdate'], ); $this->model->save($user_data, ['id' => $row->id]); }else{ $this->error('请填写续保信息',url('user4s/user/expireins',['user4s_id'=>$row->id])); } $this->success('续保成功!',url('user4s/user/expireins',['user4s_id'=>$row->id])); } $this->view->assign("now", date('Y-m-d')); $this->view->assign("all_star", $all_star); $this->view->assign('row', $row); return $this->view->fetch(); } }