[ 'startTime' => $dateData['day']['c_start_time'],// 当天开始时间 'endTime' => date("c"),// 当天结束时间 'granularity' => 'daily' ], 'week' => [ 'startTime' => $dateData['week']['c_start_time'], 'endTime' => date("c"), 'granularity' => 'daily' ], 'month' =>[ 'startTime' => $dateData['month']['c_start_time'], 'endTime' => date("c"), 'granularity' => 'monthly' ], 'year' =>[ 'startTime' => date("c",strtotime("-10 year")), 'endTime' => date("c",time()), 'granularity' => 'yearly' ] ]; Db::table('bt_passenger_flow_all')->where('id','>',1)->delete(); $requestData = []; try { foreach ($dateArr as $date => $value) { $url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups"; $granularity = $value['granularity']; $dataArr = [ 'granularity' => $granularity, 'startTime' => $value['startTime'], 'endTime' => $value['endTime'], 'ids' => '01' // --- --- // ]; $json_data = json_encode($dataArr); $result = postToken($url,$json_data,false,[],$token); $res_data = json_decode($result,true); if ($res_data['code'] != 0) throw new \Exception('请求失败'); $list = (array)$res_data['data']['list']; foreach ($list as $val) { $insert_arr = [ 'groupId' => $val['groupId'], 'groupName' => $val['groupName'], 'flowInNum' => $val['flowInNum'], 'flowOutNum' => $val['flowOutNum'], 'noRepeatInNum' => $val['noRepeatInNum'], 'noRepeatOutNum' => $val['noRepeatOutNum'], 'holdValue' => $val['holdValue'], 'createTime' => $val['createTime'], 'updateTime' => $val['updateTime'], 'netValue' => $val['netValue'], 'statTime' => $val['statTime'], 'granularity' => $granularity, 'date' => $date, ]; Db::table('bt_passenger_flow_all')->insert($insert_arr); $requestData[] = $insert_arr; } } } catch (\Exception $e) { exit( $e->getMessage() ); } if (!empty($requestData)) { $token = '9c4cb25665cf08667c815420ab383cb5'; $data = [ 'data' => json_encode($requestData), 'token' => md5('9c4cb25665cf08667c815420ab383cb5' . date('Ymd')) ]; $json_data = json_encode($data); $createUrl = $config['host_path'] . '/api/pass.create/createPassengerFlowAll'; $result = postToken($createUrl,$json_data,false,[],$token); $result = json_decode($result,true); if ($result['code'] != 1) exit($result['msg']); } return true; } }