đồng bộ dữ liệu giữa các thiết bị
This commit is contained in:
@@ -268,45 +268,6 @@ class ListManagementController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function actionSync($ip) {
|
||||
if (Yii::$app->request->post()) {
|
||||
$data = Yii::$app->request->post();
|
||||
$results = json_decode(file_get_contents("http://" . $ip . "/api/full-data", false, stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST",
|
||||
'content' => json_encode($data['lists'])
|
||||
]
|
||||
])), true);
|
||||
foreach ($results as $key => $value) {
|
||||
$images = [];
|
||||
foreach ($value['image'] as $k => $v) {
|
||||
$key = common::generateRandomString();
|
||||
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
|
||||
$targetPath = $RootFolder . "/face";
|
||||
$fileName = "face_" . $key . "_" . time() . ".png";
|
||||
FileHelper::createDirectory($targetPath, 0777);
|
||||
file_put_contents($targetPath . "/" . $fileName, base64_decode($v['url']));
|
||||
$images[] = ["url" => $fileName, "features" => $v['features']];
|
||||
}
|
||||
$model = new ListManagement();
|
||||
$model->create([
|
||||
'type' => $value['type'],
|
||||
'name' => $value['name'],
|
||||
'image' => json_encode($images),
|
||||
'gender' => $value['gender'],
|
||||
'birthday' => date("d/m/Y", $value['birthday']),
|
||||
'telephone' => $value['telephone'],
|
||||
'address' => $value['address'],
|
||||
'time' => $value['time']
|
||||
]);
|
||||
}
|
||||
file_get_contents("http://localhost:2305/update-feature");
|
||||
Yii::$app->response->format = "json";
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
public function actionSyncFromServer() {
|
||||
if (Yii::$app->request->isAjax) {
|
||||
$datas = json_decode(file_get_contents("https://dev-dc.beetai.com/api/oem/get_all_image", false, stream_context_create([
|
||||
@@ -382,6 +343,57 @@ class ListManagementController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function actionSyncFeatureFromDevice() {
|
||||
if (Yii::$app->request->post()) {
|
||||
Yii::$app->response->format = "json";
|
||||
$data = Yii::$app->request->post();
|
||||
$results = json_decode(file_get_contents("http://" . $data['ip'] . "/api/full-data", false, stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST",
|
||||
'content' => json_encode([$data['id']])
|
||||
]
|
||||
])), true);
|
||||
foreach ($results as $key => $value) {
|
||||
$images = [];
|
||||
foreach ($value['image'] as $k => $v) {
|
||||
$key = common::generateRandomString();
|
||||
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
|
||||
$targetPath = $RootFolder . "/face";
|
||||
$fileName = "face_" . $key . "_" . time() . ".png";
|
||||
FileHelper::createDirectory($targetPath, 0777);
|
||||
file_put_contents($targetPath . "/" . $fileName, base64_decode($v['url']));
|
||||
$images[] = ["url" => $fileName, "features" => $v['features']];
|
||||
}
|
||||
$model = ListManagement::findOne(['code' => $value['code']]);
|
||||
if ($model) {
|
||||
$model->type = $value['type'];
|
||||
$model->name = $value['name'];
|
||||
$model->image = json_encode($images);
|
||||
$model->gender = $value['gender'];
|
||||
$model->birthday = date("d/m/Y", $value['birthday']);
|
||||
$model->telephone = $value['telephone'];
|
||||
$model->address = $value['address'];
|
||||
$model->save();
|
||||
} else {
|
||||
$model = new ListManagement();
|
||||
$model->create([
|
||||
'code' => $value['code'],
|
||||
'type' => $value['type'],
|
||||
'name' => $value['name'],
|
||||
'image' => json_encode($images),
|
||||
'gender' => $value['gender'],
|
||||
'birthday' => date("d/m/Y", $value['birthday']),
|
||||
'telephone' => $value['telephone'],
|
||||
'address' => $value['address'],
|
||||
'time' => $value['time']
|
||||
]);
|
||||
}
|
||||
}
|
||||
return ["status" => true];
|
||||
}
|
||||
}
|
||||
|
||||
public function actionUpdateFeature() {
|
||||
if (Yii::$app->request->isAjax) {
|
||||
Yii::$app->response->format = "json";
|
||||
|
||||
Reference in New Issue
Block a user