dong bo du lieu mau khuon mat len may chu

This commit is contained in:
2020-12-22 10:09:26 +07:00
parent df644d539d
commit bba20c9c17
5 changed files with 191 additions and 3 deletions

View File

@@ -183,4 +183,9 @@ class ApiController extends Controller {
return $str;
}
public function actionSync() {
Yii::$app->response->format = "json";
return ["status" => true];
}
}

View File

@@ -467,4 +467,58 @@ class ListManagementController extends Controller {
}
}
public function actionSyncToServer() {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = "json";
return [
"title" => "<i class='fa fa-upload'></i> Đồng bộ lên máy chủ",
"form" => $this->renderPartial("list-to-server", [
"datas" => ListManagement::find()->orderBy(["code" => SORT_ASC])->all()
])
];
}
}
public function actionSyncFeatureToServer() {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "dev-dc.beetai.com";
if ($server_ip)
$ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
if ($device_id)
$id_camera = intval($device_id->data);
$StaffInfo = ListManagement::findOne(["code" => Yii::$app->request->post("id")]);
$lsImgs = json_decode($StaffInfo->image, true);
$images = [];
foreach ($lsImgs as $key => $value) {
$images[] = base64_encode(file_get_contents(Yii::$app->request->hostInfo . "/data/uploads/face/" . $value['url']));
}
$items = [
"name" => $StaffInfo->name,
"code" => $StaffInfo->code,
"department" => $StaffInfo->address,
"birthday" => date("Y-m-d", $StaffInfo->birthday),
"gender" => $StaffInfo == "Male" ? 1 : 0,
"telephone" => $StaffInfo->telephone,
"images" => $images
];
$res = json_decode(file_get_contents("https://" . $ip . "/api/oem/data_sync_pro", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
"id_camera" => $id_camera,
"items" => [$items]
])
]
])), true);
return $res;
//["status" => true];
}
}
}