123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\AuthGroupAccess;
- use app\common\controller\Backend;
- use think\Session;
- /**
- *
- *
- * @icon fa fa-circle-o
- */
- class Protector extends Backend
- {
-
- /**
- * Protector模型对象
- * @var \app\admin\model\Protector
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('Protector');
- }
- /**
- * 查看
- */
- public function index($status = false)
- {
- //设置过滤方法
- $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();
- switch ($status){
- case 'protect': //保护中
- $total = $this->model
- ->where('status',0)
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where('status',0)
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- break;
- case 'overdue': //已过期
- $total = $this->model
- ->where('status',1)
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where('status',1)
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- break;
- case 'contract': //已签单
- $total = $this->model
- ->where('status',2)
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where('status',2)
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- break;
- }
- $list = collection($list)->toArray();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch('index');
- }
- /**
- * 添加
- */
- 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);
- }
- //todo 根据单位名称查找数据 unit_name 如果有数据之间返回已存在数据
- $params['usr_id'] = Session::get('admin')['id']; //usr id
- $params['usr_nickname'] = Session::get('admin')['nickname']; //nickname
-
- $protect_count = Session::get('admin')['protect_count']; //保护个数
- $protect_day = Session::get('admin')['protect_day']; //保护天数
- $free_day = Session::get('admin')['free_day']; // 冻结天数
- $params['usr_depart'] = AuthGroupAccess::getGroupName($params['usr_id']); //获取所属组名
-
- // todo 获取当前时间戳作为 pro_date 保护时间 加上 protect_day 保护天数得到 保护ex_date到期时间 + 冻结天数 得到 free_date 冻结到期时间 status 设置为0存入库
- $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();
- }
- }
|