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 @@ +
ID | +Name | +Gender | +Registration Image | +Birthday | +Telephone | +Department | +
---|---|---|---|---|---|---|
{$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} | +