diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 78166b18..3eda5537 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -183,4 +183,9 @@ class ApiController extends Controller { return $str; } + public function actionSync() { + Yii::$app->response->format = "json"; + return ["status" => true]; + } + } diff --git a/controllers/ListManagementController.php b/controllers/ListManagementController.php index 40f4155b..ef90bfa9 100644 --- a/controllers/ListManagementController.php +++ b/controllers/ListManagementController.php @@ -467,4 +467,58 @@ class ListManagementController extends Controller { } } + public function actionSyncToServer() { + if (Yii::$app->request->isAjax) { + Yii::$app->response->format = "json"; + return [ + "title" => " Đồ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]; + } + } + } diff --git a/views/list-management/index.tpl b/views/list-management/index.tpl index 32003c05..ce220695 100644 --- a/views/list-management/index.tpl +++ b/views/list-management/index.tpl @@ -35,6 +35,7 @@ +
@@ -135,7 +136,7 @@
Xóa nhiều dữ liệu -

+

+

Đồng bộ với máy chủ

{**} - +

Đồng bộ từ thiết bị khác

diff --git a/views/list-management/list-to-server.tpl b/views/list-management/list-to-server.tpl new file mode 100644 index 00000000..90c4daca --- /dev/null +++ b/views/list-management/list-to-server.tpl @@ -0,0 +1,63 @@ +
+ + + + + + + + + + + + + + {foreach from=$datas item=arr} + + + + + + + + + + {/foreach} + +
IDNameGenderRegistration ImageBirthdayTelephoneDepartment
{$arr->code}{$arr->name}{$arr->gender} + {$images = json_decode($arr->image, true)} + {foreach from=$images item=img} +
+ +
+ {/foreach} +
{$arr->birthday|date_format:"%d/%m/%Y"}{$arr->telephone}{$arr->address}
+
+
+
+
+ Đã lựa chọn 0 đối tượng. +
+
+ +
+
+ + + + +
+
diff --git a/web/js/list-management.js b/web/js/list-management.js index fa9b7337..55725c98 100644 --- a/web/js/list-management.js +++ b/web/js/list-management.js @@ -484,4 +484,65 @@ function chooseStaff(e) { common.ajaxError(); } }); +} + +function _syncToServerForm(e) { + common.modalBlock(true); + $.ajax({ + url: $(e).attr("data-href"), + type: 'POST', + success: function (data) { + common.modalBlock(false); + common.modalOpenFullScreen(data.form, data.title); + }, + error: function (jqXHR, textStatus, errorThrown) { + common.modalBlock(false); + common.ajaxError(); + } + }); +} + +var progressToServer = 0; +var totalsToServer = 0; +function _syncToServer() { + var lists = []; + $.each($("#sync-lists").find(".success"), function () { + lists.push($(this).attr("data-id")); + }); + if (lists.length == 0) { + alert("Không có dữ liệu đồng bộ!"); + return; + } + common.modalBlock(true); + $("#progress-totals").html(lists.length); + $("#progress-form").removeClass("hidden"); + totalsToServer = lists.length; + for (var i = 0; i < lists.length; i++) { + syncFeatureToServer(lists[i]); + } +} + +function syncFeatureToServer(id) { + $.ajax({ + url: $("input[name='sync_feature_to_server_url']").val(), + type: 'POST', + data: { + id: id + }, + success: function (data) { + progressToServer++; + $("#progress-current").html(parseInt($("#progress-current").html()) + 1); + var percent = parseInt(progressToServer / totalsToServer * 100); + $("#progress").attr("aria-valuenow", percent); + $("#progress").attr("style", "width: " + percent + "%"); + $("#progress").html(percent + "%"); + if (percent >= 100) { + common.modalBlock(false); + alert("Đồng bộ dữ liệu hoàn thành"); + window.location.reload(true); + } + }, + error: function (jqXHR, textStatus, errorThrown) { + } + }); } \ No newline at end of file