đồng bộ dữ liệu lên máy chủ
This commit is contained in:
@@ -10,6 +10,8 @@ namespace app\commands;
|
||||
|
||||
use yii\console\Controller;
|
||||
use yii\console\ExitCode;
|
||||
use app\models\CaptureLogs;
|
||||
use app\models\ListManagement;
|
||||
|
||||
/**
|
||||
* This command echoes the first argument that you have entered.
|
||||
@@ -28,32 +30,33 @@ class SyncController extends Controller {
|
||||
*/
|
||||
public function actionIndex() {
|
||||
if ($this->is_connected()) {
|
||||
$sync = \app\models\SyncUrl::find()->one();
|
||||
if ($sync) {
|
||||
$logs = \app\models\FaceLogs::find()->all();
|
||||
foreach ($logs as $key => $value) {
|
||||
$options = [
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST",
|
||||
'content' => json_encode([
|
||||
"camera_id" => $value->camera_id,
|
||||
"confidence" => $value->confidence,
|
||||
"enable_door" => $value->enable_door,
|
||||
"encoded_person_image" => $value->encoded_person_image,
|
||||
"frametime" => $value->frametime,
|
||||
"id" => $value->face_id,
|
||||
"image" => $value->image,
|
||||
"name" => $value->name,
|
||||
"person_id" => $value->person_id,
|
||||
"status" => $value->status,
|
||||
"stt" => $value->stt,
|
||||
"timezone" => $value->timezone
|
||||
]),
|
||||
]
|
||||
];
|
||||
file_get_contents($sync->data, false, stream_context_create($options));
|
||||
$value->delete();
|
||||
$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);
|
||||
|
||||
$ls = CaptureLogs::find()->andWhere(['<>', 'staff_id', 0])->andWhere(['sync_status' => 0])->all();
|
||||
foreach ($ls as $key => $value) {
|
||||
$staffInfo = ListManagement::findOne($value->staff_id);
|
||||
$res = json_decode(file_get_contents("https://" . $ip . "/api/box/oem_face_recognition", false, stream_context_create([
|
||||
'http' => [
|
||||
'header' => "Content-Type: application/json",
|
||||
'method' => "POST",
|
||||
'content' => json_encode([
|
||||
'image' => base64_encode(file_get_contents(Yii::getAlias('@webroot') . "/data/uploads/face/" . $value->image)),
|
||||
'camera_id' => strval($id_camera),
|
||||
'frametime' => date("Y-m-d H:i:s", $value->time),
|
||||
'idCard' => $staffInfo ? strval($staffInfo->code) : "0"
|
||||
])
|
||||
]
|
||||
])), true);
|
||||
if ($res['status'] == 10000) {
|
||||
$value->sync_status = 1;
|
||||
$value->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user