123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\AuthGroup;
- use app\admin\model\AuthGroupAccess;
- use app\common\controller\Backend;
- use think\Db;
- use think\Session;
- /**
- *
- *
- * @icon fa fa-circle-o
- */
- class Intention extends Backend
- {
- private $status = [
- "PROTECTOR" => 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();
- $where1 = array('isdel'=>0);
- $total = $this->model
- ->where($where)
- ->where($where1)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where($where)
- ->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();
- }
-
- }
|