0 , //保护中 "OVERDUE" => 1, // 已过期 "SIGN" => 2, // 已签单 "FREE" => 3, // 冻结中 "GIVEUP" => 4, // 已放弃 ]; //快速搜索的字段 protected $searchFields = ['unit_name','contacts']; /** * 无需鉴权的方法,但需要登录 * @var array */ protected $noNeedRight = ['again','giveup','unittypelist']; /** * Intention模型对象 * @var \app\admin\model\Intention */ protected $model = null; public function _initialize() { parent::_initialize(); $this->model = model('Intention'); } /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $rules = AuthGroup::getRulesByGroupId(Session::get('admin')['depart_id']); if($rules == '*'){ $where_usr_id = false; // 管理员可以看到所有 } else { $auth_group = Db::table('auth_group')->select(); // 所有组别 $depart_id = Session::get('admin')['depart_id']; // 所属组别 // 获取所有子级部门 $arr = AuthGroup::getSubs($auth_group,$depart_id); array_push($arr,$depart_id); // 只能查看自己和自己子级的保护客户和签单客户 $where_usr_id = ['depart_id'=>['in',$arr]]; } $where1 = array('isdel'=>0); $total = $this->model ->where($where) ->where($where_usr_id) ->where($where1) ->order($sort, $order) ->count(); $list = $this->model ->where($where) ->where($where_usr_id) ->where($where1) ->order($sort, $order) ->limit($offset, $limit) ->select(); $list = collection($list)->toArray(); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 添加 */ public function add() { if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { if ($this->dataLimit && $this->dataLimitFieldAutoFill) { $params[$this->dataLimitField] = $this->auth->id; } try { //是否采用模型验证 if ($this->modelValidate) { $name = basename(str_replace('\\', '/', get_class($this->model))); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate; $this->model->validate($validate); } $params['usr_id'] = Session::get('admin')['id']; //usr id $params['usr_nickname'] = Session::get('admin')['nickname']; //nickname $params['created_at'] = date('Y-m-d H:i:s'); //创建时间 $params['usr_depart'] = Session::get('admin')['usr_depart']; //获取所属组名 $params['depart_id'] = Session::get('admin')['depart_id']; //获取所属组id \app\admin\model\Intention::addUnitType($params['unit_type']); // 根据单位名称判断是否已经存在(已被保护) $res = \app\admin\model\Protector::unitNameIsExist($params['unit_name']); if($res){ $this->error('"'.$res.'"已经被保护!'); } $result = $this->model->allowField(true)->save($params); if ($result !== false) { $this->success(); } else { $this->error($this->model->getError()); } } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } $this->error(__('Parameter %s can not be empty', '')); } return $this->view->fetch(); } /** * 性质列表 */ public function unitTypeList() { $list = Db::table('unit_type') ->select(); $searchlist = []; foreach ($list as $key => $value) { $searchlist[] = ['id'=>$value['name'], 'name' => $value['name']]; } $data = ['rows' => $searchlist]; return $data; } /** * 放弃 */ public function giveup() { try { //1.获取id $id = $this->request->post("id"); //2.protector表 通过id 查找出数据 $protector = \app\admin\model\Intention::get($id); //3.获取用户id $usr_id = Session::get('admin')['id']; //4.判断用户id和 protector的用户id是否一致 保存状态 if ($usr_id != 1 && $protector['usr_id'] != $usr_id) { $this->error('请操作自己的数据!'); } //5.保护到期时间设置现在 冻结算一下 $free_day = Session::get('admin')['free_day']; $param['ex_date'] = date('Y-m-d'); $param['free_date'] = date('Y-m-d', strtotime("+" . $free_day . " day")); // $param['status'] = $this->status['GIVEUP']; $param['isdel'] = 1; $param['id'] = $id; //6.入库 $res = $this->model->allowField(true)->isUpdate(true)->save($param); if ($res) { $this->success('放弃成功!'); } $this->error(); } catch (\think\exception\PDOException $e) { $this->error($e->getMessage()); } } public function follow($ids = NULL){ $info = Db::table('follow')->where('type',1)->where('protect_id',$ids)->field('created_at','main')->select(); if($_POST){ $data = $this->request->post(); $unit = Db::table('protector')->where('id',$data['id'])->field('unit_name')->find(); $param['protect_id'] = $data['id']; $param['usr_id'] = Session::get('admin')['id']; $param['usr_nickname'] = $data['nickname']; $param['protect_name'] = $unit['unit_name']; $param['follow_time'] = $data['row']['follow_time']; $param['main'] = $data['row']['main']; $param['created_at'] = date('Y-m-d H:i:s'); $param['type'] = 1; $res = Db::table('follow')->insert($param); if($res){ $this->success(); }else{ $this->error('数据存储失败'); } } $this->view->assign("info", $info); $this->view->assign("id", $ids); $this->view->assign("nickname", Session::get('admin')['nickname']); return $this->view->fetch(); } }