stationModel = $stationModel; } /** * 列表 * @time 2021年05月21日 15:17 * @param Request $request */ public function index(Request $request): \think\Response { $field = $request->get('field')?:'id'; $order = $request->get('order')?:'desc'; return CatchResponse::paginate($this->stationModel->getStationList($field,$order)); } /** * 保存信息 * @time 2021年05月21日 15:17 * @param Request $request */ public function save(Request $request): \think\Response { $data = $request->post(); $location = explode(',', $data['area_id']); if(empty($location)){ return CatchResponse::fail('请选择所属区域'); } $dis = Db::table('areas')->where('id',end($location))->value('area_type'); if ($dis != 'county') { return CatchResponse::fail('区域请精确到县区'); } if(count($location) == 3){ $data['province_id'] = $location[0]; $data['city_id'] = $location[1]; $data['district_id'] = $location[2]; } if(count($location) == 2){ $data['city_id'] = $location[0]; $data['district_id'] = $location[1]; $data['province_id'] = Db::table('areas')->where('id',$location[0])->value('parent_id'); } if(count($location) == 1){ $data['district_id'] = $location[0]; $data['city_id'] = Db::table('areas')->where('id',$location[0])->value('parent_id'); $data['province_id'] = Db::table('areas')->where('id',$data['city_id'])->value('parent_id'); } //基站Mac校验 $data['station_mac'] = strtoupper(trim($data['station_mac'])); if (!$data['station_mac']) { return CatchResponse::fail('请输入基站Mac'); } $regex = "/^([A-F0-9]{12})$/"; if (!preg_match($regex, $data['station_mac'])) { return CatchResponse::fail('基站Mac格式不正确'); } if ($this->stationModel->where('station_mac', $data['station_mac'])->count()) { return CatchResponse::fail('该基站已存在'); } $data['station_code'] = substr($data['station_mac'], -6); if(!trim($data['station_name'])){ return CatchResponse::fail('请输入基站名称'); } if(!trim($data['longitude'])){ return CatchResponse::fail('请输入经度'); } if(!trim($data['latitude'])){ return CatchResponse::fail('请输入纬度'); } if(!trim($data['address'])){ return CatchResponse::fail('请输入安装地址'); } $data['station_type'] = 2; return CatchResponse::success($this->stationModel->storeBy($data)); } /** * 读取 * @time 2021年05月21日 15:17 * @param $id */ public function read($id): \think\Response { return CatchResponse::success($this->stationModel->findBy($id)); } /** * 更新 * @time 2021年05月21日 15:17 * @param Request $request * @param $id */ public function update(Request $request, $id): \think\Response { $data = $request->post(); $location = explode(',', $data['area_id']); if(empty($location)){ return CatchResponse::fail('请选择所属区域'); } $dis = Db::table('areas')->where('id',end($location))->value('area_type'); if ($dis != 'county') { return CatchResponse::fail('区域请精确到县区'); } if(count($location) == 3){ $data['province_id'] = $location[0]; $data['city_id'] = $location[1]; $data['district_id'] = $location[2]; } if(count($location) == 2){ $data['city_id'] = $location[0]; $data['district_id'] = $location[1]; $data['province_id'] = Db::table('areas')->where('id',$location[0])->value('parent_id'); } if(count($location) == 1){ $data['district_id'] = $location[0]; $data['city_id'] = Db::table('areas')->where('id',$location[0])->value('parent_id'); $data['province_id'] = Db::table('areas')->where('id',$data['city_id'])->value('parent_id'); } //基站Mac校验 $data['station_mac'] = strtoupper(trim($data['station_mac'])); if (!$data['station_mac']) { return CatchResponse::fail('请输入基站Mac'); } $regex = "/^([A-F0-9]{12})$/"; if (!preg_match($regex, $data['station_mac'])) { return CatchResponse::fail('基站Mac格式不正确'); } $gid = $this->stationModel->where('station_mac', $data['station_mac'])->value('id'); if ($gid && $gid != $id) { return CatchResponse::fail('该基站已存在'); } $data['station_code'] = substr($data['station_mac'], -6); if(!trim($data['station_name'])){ return CatchResponse::fail('请输入基站名称'); } if(!trim($data['longitude'])){ return CatchResponse::fail('请输入经度'); } if(!trim($data['latitude'])){ return CatchResponse::fail('请输入纬度'); } if(!trim($data['address'])){ return CatchResponse::fail('请输入安装地址'); } unset($data['creator_id']); return CatchResponse::success($this->stationModel->updateBy($id, $data)); } /** * 更新配置 * @time 2021年05月21日 15:17 * @param Request $request * @param $id */ public function updateStationConfig(Request $request, $id): \think\Response { $data = $request->post(); // var_dump($data); if($data['rfid_enable_throttle_rlian']){ $data['rfid_enable_throttle_rlian']=1; }else{ $data['rfid_enable_throttle_rlian']=0; } if($data['command']=='is_reboot_device'){ $data['is_reboot_device']=1; $data['is_restore_device']=0; }elseif($data['command']=='is_restore_device'){ $data['is_reboot_device']=0; $data['is_restore_device']=1; }else{ $data['is_reboot_device']=0; $data['is_restore_device']=0; } unset($data['command']); // var_dump($data); return CatchResponse::success( $this->stationModel->where('id', $id) ->update($data)); } /** * 删除 * @time 2021年05月21日 15:17 * @param $id */ public function delete($id): \think\Response { return CatchResponse::success($this->stationModel->deleteBy($id,true)); } /** * 获取全部数据 */ public function rangeData(Request $request): \think\Response { return CatchResponse::success($this->stationModel->getRangeData()); } /** * 导出定位基站 * * @time 2020年09月08日 * @param Excel $excel * @param DeviceExport $deviceExport * @throws \PhpOffice\PhpSpreadsheet\Exception * @return \think\response\Json */ public function export(Excel $excel, DwExport $dwExport) { return CatchResponse::success($excel->save($dwExport, Utils::publicPath('export/dwstations'), 'local', '定位基站')); } }