Intention.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\AuthGroup;
  4. use app\admin\model\AuthGroupAccess;
  5. use app\common\controller\Backend;
  6. use think\Db;
  7. use think\Session;
  8. /**
  9. *
  10. *
  11. * @icon fa fa-circle-o
  12. */
  13. class Intention extends Backend
  14. {
  15. private $status = [
  16. "PROTECTOR" => 0 , //保护中
  17. "OVERDUE" => 1, // 已过期
  18. "SIGN" => 2, // 已签单
  19. "FREE" => 3, // 冻结中
  20. "GIVEUP" => 4, // 已放弃
  21. ];
  22. //快速搜索的字段
  23. protected $searchFields = ['unit_name','contacts'];
  24. /**
  25. * 无需鉴权的方法,但需要登录
  26. * @var array
  27. */
  28. protected $noNeedRight = ['again','giveup','unittypelist'];
  29. /**
  30. * Intention模型对象
  31. * @var \app\admin\model\Intention
  32. */
  33. protected $model = null;
  34. public function _initialize()
  35. {
  36. parent::_initialize();
  37. $this->model = model('Intention');
  38. }
  39. /**
  40. * 查看
  41. */
  42. public function index()
  43. {
  44. //设置过滤方法
  45. $this->request->filter(['strip_tags']);
  46. if ($this->request->isAjax())
  47. {
  48. //如果发送的来源是Selectpage,则转发到Selectpage
  49. if ($this->request->request('keyField'))
  50. {
  51. return $this->selectpage();
  52. }
  53. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  54. $where1 = array('isdel'=>0);
  55. $total = $this->model
  56. ->where($where)
  57. ->where($where1)
  58. ->order($sort, $order)
  59. ->count();
  60. $list = $this->model
  61. ->where($where)
  62. ->where($where1)
  63. ->order($sort, $order)
  64. ->limit($offset, $limit)
  65. ->select();
  66. $list = collection($list)->toArray();
  67. $result = array("total" => $total, "rows" => $list);
  68. return json($result);
  69. }
  70. return $this->view->fetch();
  71. }
  72. /**
  73. * 添加
  74. */
  75. public function add()
  76. {
  77. if ($this->request->isPost())
  78. {
  79. $params = $this->request->post("row/a");
  80. if ($params)
  81. {
  82. if ($this->dataLimit && $this->dataLimitFieldAutoFill)
  83. {
  84. $params[$this->dataLimitField] = $this->auth->id;
  85. }
  86. try
  87. {
  88. //是否采用模型验证
  89. if ($this->modelValidate)
  90. {
  91. $name = basename(str_replace('\\', '/', get_class($this->model)));
  92. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
  93. $this->model->validate($validate);
  94. }
  95. $params['usr_id'] = Session::get('admin')['id']; //usr id
  96. $params['usr_nickname'] = Session::get('admin')['nickname']; //nickname
  97. $params['created_at'] = date('Y-m-d H:i:s'); //创建时间
  98. $params['usr_depart'] = Session::get('admin')['usr_depart']; //获取所属组名
  99. $params['depart_id'] = Session::get('admin')['depart_id']; //获取所属组id
  100. \app\admin\model\Intention::addUnitType($params['unit_type']);
  101. // 根据单位名称判断是否已经存在(已被保护)
  102. $res = \app\admin\model\Protector::unitNameIsExist($params['unit_name']);
  103. if($res){
  104. $this->error('"'.$res.'"已经被保护!');
  105. }
  106. $result = $this->model->allowField(true)->save($params);
  107. if ($result !== false)
  108. {
  109. $this->success();
  110. }
  111. else
  112. {
  113. $this->error($this->model->getError());
  114. }
  115. }
  116. catch (\think\exception\PDOException $e)
  117. {
  118. $this->error($e->getMessage());
  119. }
  120. }
  121. $this->error(__('Parameter %s can not be empty', ''));
  122. }
  123. return $this->view->fetch();
  124. }
  125. /**
  126. * 性质列表
  127. */
  128. public function unitTypeList()
  129. {
  130. $list = Db::table('unit_type')
  131. ->select();
  132. $searchlist = [];
  133. foreach ($list as $key => $value)
  134. {
  135. $searchlist[] = ['id'=>$value['name'], 'name' => $value['name']];
  136. }
  137. $data = ['rows' => $searchlist];
  138. return $data;
  139. }
  140. /**
  141. * 放弃
  142. */
  143. public function giveup() {
  144. try {
  145. //1.获取id
  146. $id = $this->request->post("id");
  147. //2.protector表 通过id 查找出数据
  148. $protector = \app\admin\model\Intention::get($id);
  149. //3.获取用户id
  150. $usr_id = Session::get('admin')['id'];
  151. //4.判断用户id和 protector的用户id是否一致 保存状态
  152. if ($usr_id != 1 && $protector['usr_id'] != $usr_id) {
  153. $this->error('请操作自己的数据!');
  154. }
  155. //5.保护到期时间设置现在 冻结算一下
  156. $free_day = Session::get('admin')['free_day'];
  157. $param['ex_date'] = date('Y-m-d');
  158. $param['free_date'] = date('Y-m-d', strtotime("+" . $free_day . " day"));
  159. // $param['status'] = $this->status['GIVEUP'];
  160. $param['isdel'] = 1;
  161. $param['id'] = $id;
  162. //6.入库
  163. $res = $this->model->allowField(true)->isUpdate(true)->save($param);
  164. if ($res) {
  165. $this->success('放弃成功!');
  166. }
  167. $this->error();
  168. } catch (\think\exception\PDOException $e)
  169. {
  170. $this->error($e->getMessage());
  171. }
  172. }
  173. public function follow($ids = NULL){
  174. $info = Db::table('follow')->where('type',1)->where('protect_id',$ids)->field('created_at','main')->select();
  175. if($_POST){
  176. $data = $this->request->post();
  177. $unit = Db::table('protector')->where('id',$data['id'])->field('unit_name')->find();
  178. $param['protect_id'] = $data['id'];
  179. $param['usr_id'] = Session::get('admin')['id'];
  180. $param['usr_nickname'] = $data['nickname'];
  181. $param['protect_name'] = $unit['unit_name'];
  182. $param['follow_time'] = $data['row']['follow_time'];
  183. $param['main'] = $data['row']['main'];
  184. $param['created_at'] = date('Y-m-d H:i:s');
  185. $param['type'] = 1;
  186. $res = Db::table('follow')->insert($param);
  187. if($res){
  188. $this->success();
  189. }else{
  190. $this->error('数据存储失败');
  191. }
  192. }
  193. $this->view->assign("info", $info);
  194. $this->view->assign("id", $ids);
  195. $this->view->assign("nickname", Session::get('admin')['nickname']);
  196. return $this->view->fetch();
  197. }
  198. }