Protector.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\AuthGroupAccess;
  4. use app\common\controller\Backend;
  5. use think\Session;
  6. /**
  7. *
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Protector extends Backend
  12. {
  13. /**
  14. * Protector模型对象
  15. * @var \app\admin\model\Protector
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = model('Protector');
  22. }
  23. /**
  24. * 查看
  25. */
  26. public function index($status = false)
  27. {
  28. //设置过滤方法
  29. $this->request->filter(['strip_tags']);
  30. if ($this->request->isAjax())
  31. {
  32. //如果发送的来源是Selectpage,则转发到Selectpage
  33. if ($this->request->request('keyField'))
  34. {
  35. return $this->selectpage();
  36. }
  37. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  38. switch ($status){
  39. case 'protect': //保护中
  40. $total = $this->model
  41. ->where('status',0)
  42. ->where($where)
  43. ->order($sort, $order)
  44. ->count();
  45. $list = $this->model
  46. ->where('status',0)
  47. ->where($where)
  48. ->order($sort, $order)
  49. ->limit($offset, $limit)
  50. ->select();
  51. break;
  52. case 'overdue': //已过期
  53. $total = $this->model
  54. ->where('status',1)
  55. ->where($where)
  56. ->order($sort, $order)
  57. ->count();
  58. $list = $this->model
  59. ->where('status',1)
  60. ->where($where)
  61. ->order($sort, $order)
  62. ->limit($offset, $limit)
  63. ->select();
  64. break;
  65. case 'contract': //已签单
  66. $total = $this->model
  67. ->where('status',2)
  68. ->where($where)
  69. ->order($sort, $order)
  70. ->count();
  71. $list = $this->model
  72. ->where('status',2)
  73. ->where($where)
  74. ->order($sort, $order)
  75. ->limit($offset, $limit)
  76. ->select();
  77. break;
  78. }
  79. $list = collection($list)->toArray();
  80. $result = array("total" => $total, "rows" => $list);
  81. return json($result);
  82. }
  83. return $this->view->fetch('index');
  84. }
  85. /**
  86. * 添加
  87. */
  88. public function add()
  89. {
  90. if ($this->request->isPost())
  91. {
  92. $params = $this->request->post("row/a");
  93. if ($params)
  94. {
  95. if ($this->dataLimit && $this->dataLimitFieldAutoFill)
  96. {
  97. $params[$this->dataLimitField] = $this->auth->id;
  98. }
  99. try
  100. {
  101. //是否采用模型验证
  102. if ($this->modelValidate)
  103. {
  104. $name = basename(str_replace('\\', '/', get_class($this->model)));
  105. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
  106. $this->model->validate($validate);
  107. }
  108. //todo 根据单位名称查找数据 unit_name 如果有数据之间返回已存在数据
  109. $params['usr_id'] = Session::get('admin')['id']; //usr id
  110. $params['usr_nickname'] = Session::get('admin')['nickname']; //nickname
  111. $protect_count = Session::get('admin')['protect_count']; //保护个数
  112. $protect_day = Session::get('admin')['protect_day']; //保护天数
  113. $free_day = Session::get('admin')['free_day']; // 冻结天数
  114. $params['usr_depart'] = AuthGroupAccess::getGroupName($params['usr_id']); //获取所属组名
  115. // todo 获取当前时间戳作为 pro_date 保护时间 加上 protect_day 保护天数得到 保护ex_date到期时间 + 冻结天数 得到 free_date 冻结到期时间 status 设置为0存入库
  116. $result = $this->model->allowField(true)->save($params);
  117. if ($result !== false)
  118. {
  119. $this->success();
  120. }
  121. else
  122. {
  123. $this->error($this->model->getError());
  124. }
  125. }
  126. catch (\think\exception\PDOException $e)
  127. {
  128. $this->error($e->getMessage());
  129. }
  130. }
  131. $this->error(__('Parameter %s can not be empty', ''));
  132. }
  133. return $this->view->fetch();
  134. }
  135. }