123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <?php
- namespace catchAdmin\fences\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use catchAdmin\fences\model\Fences as fencesModel;
- class Fences extends CatchController
- {
- protected $fencesModel;
-
- public function __construct(FencesModel $fencesModel)
- {
- $this->fencesModel = $fencesModel;
- }
-
- /**
- * 列表
- * @time 2021年06月07日 10:10
- * @param Request $request
- */
- public function index(Request $request) : \think\Response
- {
- return CatchResponse::paginate($this->fencesModel->getList());
- }
- /**
- * 列表
- * @time 2021年06月07日 10:10
- * @param Request $request
- */
- public function getSchoolFenceList(Request $request) : \think\Response
- {
- return CatchResponse::paginate($this->fencesModel->getSchoolFenceList());
- }
- /**
- * 列表
- * @time 2021年06月07日 10:10
- * @param Request $request
- */
- public function getKqFenceList(Request $request) : \think\Response
- {
- return CatchResponse::paginate($this->fencesModel->getKqFenceList());
- }
-
- /**
- * 保存信息
- * @time 2021年06月07日 10:10
- * @param Request $request
- */
- public function save(Request $request) : \think\Response
- {
- $post = $request->post();
-
- if (!isset($post['name']) || !$post['name']) {
- return CatchResponse::fail('围栏名称不能为空');
- }
- if (!isset($post['fence_shape']) || !$post['fence_shape']) {
- return CatchResponse::fail('获取围栏类型失败');
- }
- if (!isset($post['fence_info']) || !is_array($post['fence_info'])) {
- return CatchResponse::fail('获取围栏坐标数据失败');
- }
- // 进围栏
- if (isset($post['is_check_in']) && $post['is_check_in']) {
- if (!isset($post['in_fence_time_area']) || !is_array($post['in_fence_time_area'])) {
- return CatchResponse::fail('进围栏检测时间不能为空');
- }
- $post['is_check_in'] = 1;
- $post['in_fence_time_area'] = json_encode($post['in_fence_time_area']);
- } else {
- unset($post['in_fence_time_area']);
- }
- // 出围栏
- if (isset($post['is_check_out']) && $post['is_check_out']) {
- if (!isset($post['out_fence_time_area']) || !is_array($post['out_fence_time_area'])) {
- return CatchResponse::fail('出围栏检测时间不能为空');
- }
- $post['is_check_out'] = 1;
- $post['out_fence_time_area'] = json_encode($post['out_fence_time_area']);
- } else {
- unset($post['out_fence_time_area']);
- }
-
- // 检测名称重复
- $post['fence_info'] = json_encode($post['fence_info']);
- // $post['departments'] = json_encode($post['departments']);
- $post['departments'] = array_pop($post['departments']);
- $post['push_users'] = json_encode($post['push_users']);
- return CatchResponse::success($this->fencesModel->storeBy($post));
- }
-
- /**
- * 保存SOS围栏信息
- * @time 2021年06月07日 10:10
- * @param Request $request
- */
- public function saveSchoolFence(Request $request) : \think\Response
- {
- $post = $request->post();
-
- if (!isset($post['name']) || !$post['name']) {
- return CatchResponse::fail('围栏名称不能为空');
- }
- if (!isset($post['fence_shape']) || !$post['fence_shape']) {
- return CatchResponse::fail('获取围栏类型失败');
- }
- if (!isset($post['fence_info']) || !is_array($post['fence_info'])) {
- return CatchResponse::fail('获取围栏坐标数据失败');
- }
- $post['departments'] = array_pop($post['departments']);
- $post['fence_info'] = json_encode($post['fence_info']);
- $post['push_users'] = json_encode($post['push_users']);
- $post['fence_type'] = 2;
- return CatchResponse::success($this->fencesModel->storeBy($post));
- }
-
- /**
- * 保存SOS围栏信息
- * @time 2021年06月07日 10:10
- * @param Request $request
- */
- public function saveKqFence(Request $request) : \think\Response
- {
- $post = $request->post();
-
- if (!isset($post['name']) || !$post['name']) {
- return CatchResponse::fail('围栏名称不能为空');
- }
- if (!isset($post['fence_shape']) || !$post['fence_shape']) {
- return CatchResponse::fail('获取围栏类型失败');
- }
- if (!isset($post['fence_info']) || !is_array($post['fence_info'])) {
- return CatchResponse::fail('获取围栏坐标数据失败');
- }
- $post['departments'] = array_pop($post['departments']);
- $post['fence_info'] = json_encode($post['fence_info']);
- $post['push_users'] = json_encode($post['push_users']);
- $post['fence_type'] = 3;
- return CatchResponse::success($this->fencesModel->storeBy($post));
- }
- /**
- * 读取
- * @time 2021年06月07日 10:10
- * @param $id
- */
- public function read($id) : \think\Response
- {
- return CatchResponse::success($this->fencesModel->findBy($id));
- }
-
- /**
- * 更新
- * @time 2021年06月07日 10:10
- * @param Request $request
- * @param $id
- */
- public function update(Request $request, $id) : \think\Response
- {
- $post = $request->post();
- // 转化值
- if (isset($post['is_check_in'])) {
- $post['is_check_in'] = $post['is_check_in'] ? 1 : 0;
- }
- if (isset($post['is_check_out'])) {
- $post['is_check_out'] = $post['is_check_out'] ? 1 : 0;
- }
- if (isset($post['in_fence_time_area'])) {
- $post['in_fence_time_area'] = json_encode($post['in_fence_time_area']);
- }
- if (isset($post['out_fence_time_area'])) {
- $post['out_fence_time_area'] = json_encode($post['out_fence_time_area']);
- }
- if (isset($post['fence_info'])) {
- $post['fence_info'] = json_encode($post['fence_info']);
- }
- // if (isset($post['departments'])) {
- // $post['departments'] = json_encode($post['departments']);
- // }
- if (isset($post['push_users'])) {
- $post['push_users'] = json_encode($post['push_users']);
- }
- if(isset($post['departments']) && is_array($post['departments'])){
- $post['departments'] = array_pop($post['departments']);
- }
- return CatchResponse::success($this->fencesModel->updateBy($id, $post));
- }
-
- /**
- * 更新校园围栏信息
- * @time 2021年06月07日 10:10
- * @param Request $request
- * @param $id
- */
- public function editSchoolFence(Request $request, $id) : \think\Response
- {
- $post = $request->post();
-
- if (isset($post['fence_info'])) {
- $post['fence_info'] = json_encode($post['fence_info']);
- }
- if (isset($post['push_users'])) {
- $post['push_users'] = json_encode($post['push_users']);
- }
- $post['fence_type'] = 2;
- if(is_array($post['departments'])){
- $post['departments'] = array_pop($post['departments']);
- }
-
- return CatchResponse::success($this->fencesModel->updateBy($id, $post));
- }
- /**
- * 更新校园围栏信息
- * @time 2021年06月07日 10:10
- * @param Request $request
- * @param $id
- */
- public function editKqFence(Request $request, $id) : \think\Response
- {
- $post = $request->post();
-
- if (isset($post['fence_info'])) {
- $post['fence_info'] = json_encode($post['fence_info']);
- }
- if (isset($post['push_users'])) {
- $post['push_users'] = json_encode($post['push_users']);
- }
- $post['fence_type'] = 3;
- if(is_array($post['departments'])){
- $post['departments'] = array_pop($post['departments']);
- }
-
- return CatchResponse::success($this->fencesModel->updateBy($id, $post));
- }
- /**
- * 删除
- * @time 2021年06月07日 10:10
- * @param $id
- */
- public function delete($id) : \think\Response
- {
- return CatchResponse::success($this->fencesModel->deleteBy($id, true));
- }
- }
|