|
|
@@ -3,15 +3,32 @@ require '../vendor/autoloader.php';
|
|
|
$server = $_GET["server"];
|
|
|
$localhost = $_GET["localhost"];
|
|
|
$path=$_GET["path"];
|
|
|
+$time=$_GET["time"];
|
|
|
|
|
|
-$client = new \GuzzleHttp\Client();
|
|
|
-$response = $client->request('POST', $server.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'sync','time'=>'1']]);
|
|
|
-$serverJson=$response->getBody();
|
|
|
-$serverData = json_decode($serverJson);
|
|
|
+$message="";
|
|
|
|
|
|
+$response=["message"=>"","time"=>0,"row"=>0];
|
|
|
|
|
|
-$response = $client->request('POST', $localhost.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'sync','time'=>'1']]);
|
|
|
+$client = new \GuzzleHttp\Client();
|
|
|
|
|
|
+$response = $client->request('POST', $server.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'sync','time'=>$time]]);
|
|
|
+$serverJson=$response->getBody();
|
|
|
+$serverData = json_decode($serverJson);
|
|
|
+$response["row"]=count($serverData);
|
|
|
+if($response["row"]>0){
|
|
|
+ $response["time"]=$serverData[$response["row"]-1]->modify_time;
|
|
|
+}
|
|
|
+else{
|
|
|
+ echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
|
|
+ exit;
|
|
|
+}
|
|
|
+$aIdList=array();
|
|
|
+foreach($serverData as $sd){
|
|
|
+ $aIdList[]=$sd->guid;
|
|
|
+}
|
|
|
+$sIdlist = implode(",",$aIdList);
|
|
|
+// 拉 id 列表
|
|
|
+$response = $client->request('POST', $localhost.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'sync','id'=>$sIdlist]]);
|
|
|
$strLocalData = $response->getBody();
|
|
|
$localData = json_decode($strLocalData);
|
|
|
|
|
|
@@ -21,7 +38,7 @@ $insert_to_server=array();
|
|
|
$update_to_server=array();
|
|
|
$insert_to_local=array();
|
|
|
$update_to_local=array();
|
|
|
-echo "<h3>{$path}</h3>";
|
|
|
+$message .= "<h3>{$path}</h3>";
|
|
|
foreach($localData as $local){
|
|
|
$localindex[$local->guid][0]=$local->modify_time;
|
|
|
$localindex[$local->guid][1]=false;
|
|
|
@@ -56,7 +73,7 @@ foreach($localindex as $x=>$x_value){
|
|
|
|
|
|
$syncCount = count($insert_to_server)+count($update_to_server)+count($insert_to_local)+count($update_to_local);
|
|
|
if($syncCount==0){
|
|
|
- echo "与服务器数据完全一致,无需更新。<br>";
|
|
|
+ $message .= "与服务器数据完全一致,无需更新。<br>";
|
|
|
}
|
|
|
else{
|
|
|
//start sync
|
|
|
@@ -64,13 +81,13 @@ else{
|
|
|
/*
|
|
|
|
|
|
*/
|
|
|
- echo "需要插入服务器".count($insert_to_server)."条记录<br>";
|
|
|
+ $message .= "需要插入服务器".count($insert_to_server)."条记录<br>";
|
|
|
|
|
|
$idInLocal = json_encode($insert_to_server, JSON_UNESCAPED_UNICODE);
|
|
|
$response = $client->request('POST', $localhost.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'get','id'=>"{$idInLocal}"]]);
|
|
|
$localData=$response->getBody();
|
|
|
$response = $client->request('POST', $server.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'insert','data'=>"{$localData}"]]);
|
|
|
- echo $response->getBody()."<br>";
|
|
|
+ $message .= $response->getBody()."<br>";
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -78,41 +95,42 @@ else{
|
|
|
/*
|
|
|
|
|
|
*/
|
|
|
- echo "需要更新到服务器".count($update_to_server)."条记录<br>";
|
|
|
+ $message .= "需要更新到服务器".count($update_to_server)."条记录<br>";
|
|
|
|
|
|
$idInLocal = json_encode($update_to_server, JSON_UNESCAPED_UNICODE);
|
|
|
$response = $client->request('POST', $localhost.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'get','id'=>"{$idInLocal}"]]);
|
|
|
$localData=$response->getBody();
|
|
|
$response = $client->request('POST', $server.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'update','data'=>"{$localData}"]]);
|
|
|
- echo $response->getBody()."<br>";
|
|
|
+ $message .= $response->getBody()."<br>";
|
|
|
|
|
|
}
|
|
|
|
|
|
if(count($insert_to_local)>0){
|
|
|
|
|
|
- echo "需要新增到本地".count($insert_to_local)."条记录<br>";
|
|
|
+ $message .= "需要新增到本地".count($insert_to_local)."条记录<br>";
|
|
|
|
|
|
$idInServer = json_encode($insert_to_local, JSON_UNESCAPED_UNICODE);
|
|
|
$response = $client->request('POST', $server.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'get','id'=>"{$idInServer}"]]);
|
|
|
$serverData=$response->getBody();
|
|
|
$response = $client->request('POST', $localhost.'/app/'.$path, ['verify' => false,'form_params'=>['op'=>'insert','data'=>"{$serverData}"]]);
|
|
|
- echo $response->getBody()."<br>";
|
|
|
+ $message .= $response->getBody()."<br>";
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
if(count($update_to_local)>0){
|
|
|
|
|
|
- echo "需要更新到本地".count($update_to_local)."条记录<br>";
|
|
|
+ $message .= "需要更新到本地".count($update_to_local)."条记录<br>";
|
|
|
|
|
|
$idInServer = json_encode($update_to_local, JSON_UNESCAPED_UNICODE);
|
|
|
$response = $client->request('POST', $server.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'get','id'=>"{$idInServer}"]]);
|
|
|
$serverData=$response->getBody();
|
|
|
$response = $client->request('POST', $localhost.'/app/'.$path,['verify' => false,'form_params'=>['op'=>'update','data'=>"{$serverData}"]]);
|
|
|
- echo $response->getBody()."<br>";
|
|
|
+ $message .= $response->getBody()."<br>";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+$response["message"]=$message;
|
|
|
|
|
|
?>
|