Browse Source

本地同步数据到线上

master
wanghongjun 3 years ago
parent
commit
20b7f82c8f
  1. 150
      source/application/api/controller/pass/Create.php
  2. 21
      source/application/task/controller/Pass.php
  3. 20
      source/application/task/controller/Passall.php
  4. 21
      source/application/task/controller/Passreal.php

150
source/application/api/controller/pass/Create.php

@ -0,0 +1,150 @@
<?php
namespace app\api\controller\pass;
use app\api\controller\Controller;
use app\common\exception\BaseException;
use think\Db;
class Create extends Controller
{
protected $token = '9c4cb25665cf08667c815420ab383cb5';
/**
* API基类初始化
* @throws BaseException
* @throws \think\exception\DbException
*/
public function _initialize()
{
$this->getToken();
}
/**
* 获取请求token
* @return mixed
* @throws BaseException
*/
private function getToken()
{
if (!$token = $this->request->param('token')) {
throw new BaseException(['msg' => '缺少必要的参数:token']);
}
$validateToken = md5($this->token . date('Ymd'));
if ($validateToken != $token) {
throw new BaseException(['msg' => '错误参数:token']);
}
if (!$data = $this->request->param('data')) {
throw new BaseException(['msg' => '缺少必要的参数:data']);
} else {
$data = json_decode(html_entity_decode($data),true);
if (empty($data)) throw new BaseException(['msg' => '参数为空:data']);
if (!is_array($data)) throw new BaseException(['msg' => '数据有误:data']);
}
}
/**
* 创建客流统计数据
* @return array
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function createPassengerFlow()
{
$data_json = $this->request->param('data');
$data = json_decode(html_entity_decode($data_json),true);
Db::table('bt_passenger_flow')->where('id','>',1)->delete();
foreach ($data 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' => $val['granularity']
];
Db::table('bt_passenger_flow')->insert($insert_arr);
}
return $this->renderSuccess();
}
/**
* 创建总客流统计数据
* @return array
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function createPassengerFlowAll()
{
$data_json = $this->request->param('data');
$data = json_decode(html_entity_decode($data_json),true);
Db::table('bt_passenger_flow_all')->where('id','>',1)->delete();
foreach ($data 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' => $val['granularity'],
'date' => $val['date']
];
Db::table('bt_passenger_flow_all')->insert($insert_arr);
}
return $this->renderSuccess();
}
/**
* 创建总客流统计数据
* @return array
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function createPassengerFlowReal()
{
$data_json = $this->request->param('data');
$data = json_decode(html_entity_decode($data_json),true);
Db::table('bt_passenger_flow_real')->where('id','>',1)->delete();
foreach ($data as $val) {
$insert_arr = [
'groupId' => $val['groupId'],
'regionId' => $val['regionId'],
'statisticsTime' => $val['statisticsTime'],
'enter' => $val['enter'],
'exit' => $val['exit'],
'pass' => $val['pass'],
'holdValue' => $val['holdValue'],
'allEnter' => $val['allEnter'],
'allExit' => $val['allExit']
];
Db::table('bt_passenger_flow_real')->insert($insert_arr);
}
return $this->renderSuccess();
}
}

21
source/application/task/controller/Pass.php

@ -36,8 +36,9 @@ class Pass
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups";
$delete = Db::table('bt_passenger_flow')->where('id','>',1)->delete();
// $delete = Db::table('bt_passenger_flow')->where('id','>',1)->delete();
$requestData = [];
try {
foreach ($arr as $granularity => $value) {
@ -72,6 +73,7 @@ class Pass
];
Db::table('bt_passenger_flow')->insert($insert_arr);
$requestData[] = $insert_arr;
}
}
@ -79,6 +81,23 @@ class Pass
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/createPassengerFlow';
$result = postToken($createUrl,$json_data,false,[],$token);
$result = json_decode($result,true);
if ($result['code'] != 1) exit($result['msg']);
}
return true;
}
}

20
source/application/task/controller/Passall.php

@ -42,7 +42,8 @@ class Passall
];
$delete = Db::table('bt_passenger_flow_all')->where('id','>',1)->delete();
Db::table('bt_passenger_flow_all')->where('id','>',1)->delete();
$requestData = [];
try {
@ -82,6 +83,7 @@ class Passall
];
Db::table('bt_passenger_flow_all')->insert($insert_arr);
$requestData[] = $insert_arr;
}
}
@ -89,6 +91,22 @@ class Passall
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;
}
}

21
source/application/task/controller/Passreal.php

@ -16,7 +16,8 @@ class Passreal
{
$config = config('api_config');
$delete = Db::table('bt_passenger_flow_real')->where('id','>',1)->delete();
Db::table('bt_passenger_flow_real')->where('id','>',1)->delete();
$requestData = [];
try{
@ -48,12 +49,30 @@ class Passreal
];
Db::table('bt_passenger_flow_real')->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/bt_passenger_flow_real';
$result = postToken($createUrl,$json_data,false,[],$token);
$result = json_decode($result,true);
if ($result['code'] != 1) exit($result['msg']);
}
return true;
}
}
Loading…
Cancel
Save