diff --git a/tasks/Lib.php b/tasks/Lib.php new file mode 100644 index 0000000..9edbc2c --- /dev/null +++ b/tasks/Lib.php @@ -0,0 +1,96 @@ + 'baz001', # 分馆代码 + 'name' => '宝安图书馆', # 单位名称 + 'cameraId' => '9,7,6,4,2,1,67,3', # 客流系统内分馆摄像头 + ], [ + 'groupId' => 'BAF055', + 'name' => '1990分馆', + 'cameraId' => '134,135', + ] + ]; + + public function run() + { + $config = $this->config('api_config'); + + $requestData = []; + + $allData = $this->getBaoAnLibData(); + + $tempAllArr = [ + 'groupId' => 'lib001', + 'groupName' => '图书馆' + ]; + foreach ($allData as $allKey => $allValue) { + foreach ($allValue as $aKey => $aValue) { + $tempAllArr[$allKey."_".$aKey] = $aValue; + } + } + $requestData[] = $tempAllArr; + + + $libData = $this->getBaoAnLibData(true); + + foreach ($libData as $row) { + $tempArr = [ + 'groupId' => $row['groupId'], + 'groupName' => $row['name'] + ]; + foreach ($row['data'] as $key => $value) { + foreach ($value as $k => $v) { + $tempArr[$key."_".$k] = $v; + } + } + $requestData[] = $tempArr; + } + + $requestRes = $this->request_create_data($requestData,'/api/library.pass/create',$config['host_path']); + + if (!$requestRes['status']) { + return $requestRes['msg']; + } + + + return true; + } + + /** + * @param $is_group + * @return array|mixed + */ + public function getBaoAnLibData($is_group = false) + { + if ($is_group) { + + $data = []; + foreach ($this->libCameraId as $value) { + $url = $this->libUrl . '&cameraid=' . $value['cameraId']; + $result = $this->curl_post($url); + $result = json_decode($result,true); + $data[] = [ + 'data' => $result, + 'groupId' => $value['groupId'], + 'name' => $value['name'] + ]; + } + return $data; + } else { + + $result = $this->curl_post($this->libUrl); + return json_decode($result,true); + } + } +} + +$lib = new Lib(); +echo $lib->run(); \ No newline at end of file