Fences.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace catchAdmin\fences\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. use catchAdmin\fences\model\Fences as fencesModel;
  7. class Fences extends CatchController
  8. {
  9. protected $fencesModel;
  10. public function __construct(FencesModel $fencesModel)
  11. {
  12. $this->fencesModel = $fencesModel;
  13. }
  14. /**
  15. * 列表
  16. * @time 2021年06月07日 10:10
  17. * @param Request $request
  18. */
  19. public function index(Request $request) : \think\Response
  20. {
  21. return CatchResponse::paginate($this->fencesModel->getList());
  22. }
  23. /**
  24. * 列表
  25. * @time 2021年06月07日 10:10
  26. * @param Request $request
  27. */
  28. public function getSchoolFenceList(Request $request) : \think\Response
  29. {
  30. return CatchResponse::paginate($this->fencesModel->getSchoolFenceList());
  31. }
  32. /**
  33. * 列表
  34. * @time 2021年06月07日 10:10
  35. * @param Request $request
  36. */
  37. public function getKqFenceList(Request $request) : \think\Response
  38. {
  39. return CatchResponse::paginate($this->fencesModel->getKqFenceList());
  40. }
  41. /**
  42. * 保存信息
  43. * @time 2021年06月07日 10:10
  44. * @param Request $request
  45. */
  46. public function save(Request $request) : \think\Response
  47. {
  48. $post = $request->post();
  49. if (!isset($post['name']) || !$post['name']) {
  50. return CatchResponse::fail('围栏名称不能为空');
  51. }
  52. if (!isset($post['fence_shape']) || !$post['fence_shape']) {
  53. return CatchResponse::fail('获取围栏类型失败');
  54. }
  55. if (!isset($post['fence_info']) || !is_array($post['fence_info'])) {
  56. return CatchResponse::fail('获取围栏坐标数据失败');
  57. }
  58. // 进围栏
  59. if (isset($post['is_check_in']) && $post['is_check_in']) {
  60. if (!isset($post['in_fence_time_area']) || !is_array($post['in_fence_time_area'])) {
  61. return CatchResponse::fail('进围栏检测时间不能为空');
  62. }
  63. $post['is_check_in'] = 1;
  64. $post['in_fence_time_area'] = json_encode($post['in_fence_time_area']);
  65. } else {
  66. unset($post['in_fence_time_area']);
  67. }
  68. // 出围栏
  69. if (isset($post['is_check_out']) && $post['is_check_out']) {
  70. if (!isset($post['out_fence_time_area']) || !is_array($post['out_fence_time_area'])) {
  71. return CatchResponse::fail('出围栏检测时间不能为空');
  72. }
  73. $post['is_check_out'] = 1;
  74. $post['out_fence_time_area'] = json_encode($post['out_fence_time_area']);
  75. } else {
  76. unset($post['out_fence_time_area']);
  77. }
  78. // 检测名称重复
  79. $post['fence_info'] = json_encode($post['fence_info']);
  80. // $post['departments'] = json_encode($post['departments']);
  81. $post['departments'] = array_pop($post['departments']);
  82. $post['push_users'] = json_encode($post['push_users']);
  83. return CatchResponse::success($this->fencesModel->storeBy($post));
  84. }
  85. /**
  86. * 保存SOS围栏信息
  87. * @time 2021年06月07日 10:10
  88. * @param Request $request
  89. */
  90. public function saveSchoolFence(Request $request) : \think\Response
  91. {
  92. $post = $request->post();
  93. if (!isset($post['name']) || !$post['name']) {
  94. return CatchResponse::fail('围栏名称不能为空');
  95. }
  96. if (!isset($post['fence_shape']) || !$post['fence_shape']) {
  97. return CatchResponse::fail('获取围栏类型失败');
  98. }
  99. if (!isset($post['fence_info']) || !is_array($post['fence_info'])) {
  100. return CatchResponse::fail('获取围栏坐标数据失败');
  101. }
  102. $post['departments'] = array_pop($post['departments']);
  103. $post['fence_info'] = json_encode($post['fence_info']);
  104. $post['push_users'] = json_encode($post['push_users']);
  105. $post['fence_type'] = 2;
  106. return CatchResponse::success($this->fencesModel->storeBy($post));
  107. }
  108. /**
  109. * 保存SOS围栏信息
  110. * @time 2021年06月07日 10:10
  111. * @param Request $request
  112. */
  113. public function saveKqFence(Request $request) : \think\Response
  114. {
  115. $post = $request->post();
  116. if (!isset($post['name']) || !$post['name']) {
  117. return CatchResponse::fail('围栏名称不能为空');
  118. }
  119. if (!isset($post['fence_shape']) || !$post['fence_shape']) {
  120. return CatchResponse::fail('获取围栏类型失败');
  121. }
  122. if (!isset($post['fence_info']) || !is_array($post['fence_info'])) {
  123. return CatchResponse::fail('获取围栏坐标数据失败');
  124. }
  125. $post['departments'] = array_pop($post['departments']);
  126. $post['fence_info'] = json_encode($post['fence_info']);
  127. $post['push_users'] = json_encode($post['push_users']);
  128. $post['fence_type'] = 3;
  129. return CatchResponse::success($this->fencesModel->storeBy($post));
  130. }
  131. /**
  132. * 读取
  133. * @time 2021年06月07日 10:10
  134. * @param $id
  135. */
  136. public function read($id) : \think\Response
  137. {
  138. return CatchResponse::success($this->fencesModel->findBy($id));
  139. }
  140. /**
  141. * 更新
  142. * @time 2021年06月07日 10:10
  143. * @param Request $request
  144. * @param $id
  145. */
  146. public function update(Request $request, $id) : \think\Response
  147. {
  148. $post = $request->post();
  149. // 转化值
  150. if (isset($post['is_check_in'])) {
  151. $post['is_check_in'] = $post['is_check_in'] ? 1 : 0;
  152. }
  153. if (isset($post['is_check_out'])) {
  154. $post['is_check_out'] = $post['is_check_out'] ? 1 : 0;
  155. }
  156. if (isset($post['in_fence_time_area'])) {
  157. $post['in_fence_time_area'] = json_encode($post['in_fence_time_area']);
  158. }
  159. if (isset($post['out_fence_time_area'])) {
  160. $post['out_fence_time_area'] = json_encode($post['out_fence_time_area']);
  161. }
  162. if (isset($post['fence_info'])) {
  163. $post['fence_info'] = json_encode($post['fence_info']);
  164. }
  165. // if (isset($post['departments'])) {
  166. // $post['departments'] = json_encode($post['departments']);
  167. // }
  168. if (isset($post['push_users'])) {
  169. $post['push_users'] = json_encode($post['push_users']);
  170. }
  171. if(isset($post['departments']) && is_array($post['departments'])){
  172. $post['departments'] = array_pop($post['departments']);
  173. }
  174. return CatchResponse::success($this->fencesModel->updateBy($id, $post));
  175. }
  176. /**
  177. * 更新校园围栏信息
  178. * @time 2021年06月07日 10:10
  179. * @param Request $request
  180. * @param $id
  181. */
  182. public function editSchoolFence(Request $request, $id) : \think\Response
  183. {
  184. $post = $request->post();
  185. if (isset($post['fence_info'])) {
  186. $post['fence_info'] = json_encode($post['fence_info']);
  187. }
  188. if (isset($post['push_users'])) {
  189. $post['push_users'] = json_encode($post['push_users']);
  190. }
  191. $post['fence_type'] = 2;
  192. if(is_array($post['departments'])){
  193. $post['departments'] = array_pop($post['departments']);
  194. }
  195. return CatchResponse::success($this->fencesModel->updateBy($id, $post));
  196. }
  197. /**
  198. * 更新校园围栏信息
  199. * @time 2021年06月07日 10:10
  200. * @param Request $request
  201. * @param $id
  202. */
  203. public function editKqFence(Request $request, $id) : \think\Response
  204. {
  205. $post = $request->post();
  206. if (isset($post['fence_info'])) {
  207. $post['fence_info'] = json_encode($post['fence_info']);
  208. }
  209. if (isset($post['push_users'])) {
  210. $post['push_users'] = json_encode($post['push_users']);
  211. }
  212. $post['fence_type'] = 3;
  213. if(is_array($post['departments'])){
  214. $post['departments'] = array_pop($post['departments']);
  215. }
  216. return CatchResponse::success($this->fencesModel->updateBy($id, $post));
  217. }
  218. /**
  219. * 删除
  220. * @time 2021年06月07日 10:10
  221. * @param $id
  222. */
  223. public function delete($id) : \think\Response
  224. {
  225. return CatchResponse::success($this->fencesModel->deleteBy($id, true));
  226. }
  227. }