BiFace_Server_Lite/controllers/ListManagementController.php
2021-06-07 13:55:54 +07:00

784 lines
35 KiB
PHP

<?php
namespace app\controllers;
use Yii;
use app\models\ListManagement;
use app\models\ListManagementSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use app\models\CaptureLogs;
use app\models\common;
use yii\helpers\FileHelper;
/**
* ListMamagementController implements the CRUD actions for ListMamagement model.
*/
class ListManagementController extends Controller {
/**
* {@inheritdoc}
*/
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
public function actionIndex($from = "", $to = "", $name = "", $type = "all", $gender = "all", $id = "") {
$f = date_format(date_create_from_format('H:i d/m/Y', "00:00 " . date("d/m/Y")), 'U');
$t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U');
$this->view->title = "Quản lý mẫu";
$searchModel = new ListManagementSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if ($from !== "" && $to !== "") {
$f = date_format(date_create_from_format('H:i d/m/Y', $from), 'U');
$t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U');
$dataProvider->query->andWhere(["BETWEEN", "time", $f, $t]);
}
if ($id !== "")
$dataProvider->query->andWhere(["LIKE", "code", $id]);
if ($name !== "")
$dataProvider->query->andWhere(["LIKE", "name", $name]);
if ($type !== "all")
$dataProvider->query->andWhere(["type" => $type]);
if ($gender !== "all")
$dataProvider->query->andWhere(["gender" => $gender]);
$dataProvider->query->orderBy(["time" => SORT_DESC]);
// $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
// 'http' => [
// 'header' => "Content-Type: application/json",
// 'method' => "POST"
// ]
// ])), true);
// $data = json_decode($tempConfig['data'], true);
// $last = \app\models\ListManagement::find()->orderBy(['id' => SORT_DESC])->limit(1)->one();
// if (!is_object($last))
// $last = (object) ['id' => 0];
// $idAuto = $data['data']['box_id'] . "_" . ($last->id + 1);
$updating = \app\models\SyncUrl::findOne(['key_config' => 'updating']);
if (!$updating) {
$model = new \app\models\SyncUrl();
$model->create([
'key_config' => "updating",
'data' => "false"
]);
$updating = \app\models\SyncUrl::findOne(['key_config' => 'updating']);
}
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'f' => $f,
't' => $t,
'typeArray' => ListManagement::$typeArray,
'genderArray' => ListManagement::$genderArray,
// 'idAuto' => $idAuto,
"staffArray" => ListManagement::staffArray(),
"updating" => $updating
]);
}
public function actionAdd() {
$model = new ListManagement();
Yii::$app->response->format = "json";
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$check = ListManagement::findOne(['code' => $data['code']]);
if ($check)
return ["status" => false];
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $data['image'], "type" => "raw"]
]
]), true);
$data['image'] = json_encode([
[
"url" => $data['image'],
"features" => $features['results'][0]['feature'],
"features512" => isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : []
]
]);
$model->create($data);
file_get_contents("http://localhost:2305/update-feature");
return ["status" => true];
}
}
public function actionCreate() {
$model = new ListManagement();
Yii::$app->response->format = "json";
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$listManagement = ListManagement::findOne(['code' => $data['code']]);
$url = CaptureLogs::findOne($data['id'])->image;
if ($listManagement) {
$images = json_decode($listManagement->image, true);
if (count($images) >= \Yii::$app->params['maxPicture'])
return ["status" => false, "text" => "Mỗi đối tượng chỉ nhận tối đa " . \Yii::$app->params['maxPicture'] . " hình ảnh mẫu"];
$add = true;
foreach ($images as $key => $value) {
if (isset($value['urlOld']) && $value['urlOld'] === $url)
$add = false;
}
if ($add) {
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
$targetPath = $RootFolder . "/face";
FileHelper::createDirectory($targetPath, 0777);
$fileName = "face_" . common::generateRandomString() . "_" . time() . ".png";
$img = file_get_contents("http://localhost/data/uploads/face/" . $url);
$fileTarget = $targetPath . "/" . $fileName;
if (!$this->resizeImg($img, $fileTarget))
$fileName = $url;
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
]
]), true);
$images[] = [
"url" => $fileName,
"urlOld" => $url,
"features" => $features['results'][0]['feature'],
"features512" => isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : []
];
$listManagement->type = $data['type'];
$listManagement->name = $data['name'];
$listManagement->abbreviated_name = $data['abbreviated_name'];
$listManagement->gender = $data['gender'];
$listManagement->birthday = $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U');
$listManagement->telephone = $data['telephone'];
$listManagement->address = $data['address'];
$listManagement->image = json_encode($images);
$listManagement->last_modified = time();
$listManagement->save();
common::updateFeature([
"cmd" => "update",
"id" => $listManagement->id,
"name" => common::convert_vi_to_en($listManagement->name),
"features" => $listManagement->allFeatures
]);
return ["status" => true];
}
return ["status" => false, "text" => "Hình ảnh này đã được chọn làm mẫu cho đối tượng này!"];
} else {
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
$targetPath = $RootFolder . "/face";
FileHelper::createDirectory($targetPath, 0777);
$fileName = "face_" . common::generateRandomString() . "_" . time() . ".png";
$img = file_get_contents("http://localhost/data/uploads/face/" . $url);
$fileTarget = $targetPath . "/" . $fileName;
if (!$this->resizeImg($img, $fileTarget))
$fileName = $url;
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
]
]), true);
$data['image'] = json_encode([
[
"url" => $fileName,
"urlOld" => $url,
"features" => $features['results'][0]['feature'],
"features512" => isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : []
]
]);
$model->create($data);
file_get_contents("http://localhost:2305/update-feature");
return ["status" => true];
}
}
}
public function actionFormUpdate() {
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$ListManagement = $this->findModel($data['id']);
$images = json_decode($ListManagement->image, true);
Yii::$app->response->format = "json";
return [
"type" => $ListManagement->type,
"code" => $ListManagement->code,
"name" => $ListManagement->name,
"abbreviated_name" => $ListManagement->abbreviated_name,
"gender" => $ListManagement->gender,
"birthday" => date("d/m/Y", $ListManagement->birthday),
"telephone" => $ListManagement->telephone,
"address" => $ListManagement->address,
"image" => count($images) > 0 ? "/data/uploads/face/" . $images[0]['url'] : "/images/user2-160x160.jpg",
"canUpload" => count($images) >= Yii::$app->params['maxPicture'] ? false : true
];
}
}
public function actionUpdate() {
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$model = $this->findModel($data['id']);
$check = ListManagement::findOne(['code' => $data['code']]);
if ($check && $check->id != $model->id)
return false;
if ($data['image'] !== "") {
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
$targetPath = $RootFolder . "/face";
FileHelper::createDirectory($targetPath, 0777);
$fileName = "face_" . common::generateRandomString() . "_" . time() . ".png";
$img = file_get_contents("http://localhost/data/uploads/face/" . $data['image']);
$fileTarget = $targetPath . "/" . $fileName;
if (!$this->resizeImg($img, $fileTarget))
$fileName = $data['image'];
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
]
]), true);
$images = json_decode($model->image, true);
$images[] = [
"url" => $fileName,
"urlOld" => $data['image'],
"features" => $features['results'][0]['feature'],
"features512" => isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : []
];
$model->image = json_encode($images);
}
$model->code = $data['code'];
$model->type = $data['type'];
$model->name = $data['name'];
$model->abbreviated_name = $data['abbreviated_name'];
$model->gender = $data['gender'];
$model->birthday = $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U');
$model->telephone = $data['telephone'];
$model->address = $data['address'];
$model->last_modified = time();
$model->save();
common::updateFeature([
"cmd" => "update",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
return true;
}
}
public function actionDelete() {
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$model = $this->findModel($data['id']);
$images = json_decode($model->image, true);
foreach ($images as $k => $v) {
unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $v['url']);
}
common::updateFeature([
"cmd" => "delete",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => []
]);
$model->delete();
return true;
}
}
public function actionDeleteFeature() {
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$model = $this->findModel($data['id']);
$images = json_decode($model->image, true);
$features = [];
foreach ($images as $key => $value) {
if ($value['url'] !== $data['image'])
$features[] = $value;
else {
unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value['url']);
}
}
$model->image = json_encode($features);
$model->save();
common::updateFeature([
"cmd" => "update",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
return true;
}
}
protected function findModel($id) {
if (($model = ListManagement::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionBatchDelete() {
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
Yii::$app->response->format = "json";
foreach ($data['lists'] as $key => $value) {
$staff = ListManagement::findOne($value);
if ($staff) {
$images = json_decode($staff->image, true);
foreach ($images as $k => $v) {
unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $v['url']);
}
if (count($data['lists']) <= 10)
common::updateFeature([
"cmd" => "delete",
"id" => $staff->id,
"name" => common::convert_vi_to_en($staff->name),
"features" => []
]);
$staff->delete();
}
}
if (count($data['lists']) > 10)
file_get_contents("http://localhost:2305/update-feature");
return true;
}
}
public function actionUpload() {
if (Yii::$app->request->post()) {
$model = new common();
Yii::$app->response->format = "json";
$url = $model->UploadFile("AnhNhanVien", ["PNG", "JPG", "JPEG", "GIF"], "temp");
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/" . $url, "type" => "crop"]
]
]), true);
unlink("/var/www/html/BiFace_Server_Lite/web/" . $url);
if ($features['results'][0]['crop'] === "") {
return ["status" => false];
} else {
$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($features['results'][0]['crop']));
return ["status" => true, "url" => $fileName, "dataPath" => "data/uploads/face/"];
}
}
}
public function actionFormSync() {
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$results = json_decode(file_get_contents("http://" . $data['ip'] . "/api/data", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode(ListManagement::nameArray())
]
])), true);
$filters = [];
foreach ($results as $key => $value) {
$filters[$value['code']] = $value['code'] . " - " . $value['name'] . " - " . $value['address'];
}
Yii::$app->response->format = "json";
return [
"title" => $data['ip'],
"form" => $this->renderPartial("list", [
"results" => $results,
"typeArray" => ListManagement::$typeArray,
"filters" => $filters,
"ip" => $data['ip']
])
];
}
}
public function actionSyncFromServer() {
if (Yii::$app->request->isAjax) {
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "https://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);
$datas = json_decode(file_get_contents($ip . "/api/oem/get_all_image", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
"id_camera" => $id_camera,
"ids_staff" => [],
"objs_staff" => []
])
]
])), true);
$filters = [];
foreach ($datas['data'] as $key => $value) {
$filters[$value['id']] = $value['code'] . " - " . $value['name'] . " - " . $value['department'];
}
Yii::$app->response->format = "json";
return [
"title" => "<i class='fa fa-download'></i> Đồng bộ từ máy chủ",
"form" => $this->renderPartial("list-server", [
"datas" => $datas['data'],
"filters" => $filters,
"allID" => ListManagement::getAllID()
])
];
}
}
public function getCurrentTime() {
$time = microtime();
$time = explode(' ', $time);
return $time[1] + $time[0];
}
public function extractFeature($images, $files_name, $staff_id, $currentImg = false) {
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
$targetPath = $RootFolder . "/face";
FileHelper::createDirectory($targetPath, 0777);
$extractFeature = [];
$ft = [];
$currentArr = [];
if ($currentImg) {
foreach ($currentImg as $key => $value) {
if (isset($value['serverKey']))
$currentArr[] = $value['serverKey'];
}
$ft = $currentImg;
}
foreach ($images as $key => $value) {
if ($key < Yii::$app->params['maxPicture'] && !in_array($files_name[$key], $currentArr)) {
$fileName = "face_" . $staff_id . "_" . common::generateRandomString() . "_" . time() . ".png";
$start = $this->getCurrentTime();
$img = false;
try {
$img = file_get_contents(str_replace("&amp;", "&", $value));
} catch (\Exception $e) {
}
$finish = $this->getCurrentTime();
$temp["getIMG"] = round(($finish - $start), 4);
if ($img && $img !== "null") {
$fileTarget = $targetPath . "/" . $fileName;
$start = $this->getCurrentTime();
if (!$this->resizeImg($img, $fileTarget)) {
file_put_contents($fileTarget, $img);
}
$finish = $this->getCurrentTime();
$temp["saveIMG"] = round(($finish - $start), 4);
$start = $this->getCurrentTime();
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
],
"type" => "128"
]), true);
$finish = $this->getCurrentTime();
$temp["extract"] = round(($finish - $start), 4);
$ft[] = [
"serverKey" => $files_name[$key],
"url" => $fileName,
"urlOld" => $fileName,
"features" => $features['results'][0]['feature'],
"features512" => []//isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : []
];
}
$extractFeature[] = $temp;
}
}
return [
"time" => $extractFeature,
"features" => $ft
];
}
public function actionSyncFeature() {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$processTime = [];
$totalStart = $this->getCurrentTime();
$totals = intval(Yii::$app->request->post("totals"));
$data = Yii::$app->request->post("id"); //$res['data'][0];
$start = $this->getCurrentTime();
$model = ListManagement::findOne(['staff_id' => $data['id']]);
$finish = $this->getCurrentTime();
$processTime["getLM"] = round(($finish - $start), 4);
$ft = [];
if ($model) {
if (isset($data['images'])) {
$extractFeature = $this->extractFeature($data['images'], $data['files_name'], $data['id'], json_decode($model->image, true));
$processTime["extractFeature"] = $extractFeature['time'];
$ft = $extractFeature['features'];
}
$model->abbreviated_name = $data['abbreviated_name'];
$model->code = $data['code'];
$model->name = $data['name'];
$model->address = $data['department'];
$model->image = json_encode($ft);
$model->last_modified = time();
$model->save();
// if ($totals <= 10)
// common::updateFeature([
// "cmd" => "update",
// "id" => $model->id,
// "name" => common::convert_vi_to_en($model->name),
// "features" => $model->allFeatures
// ]);
} else {
if (isset($data['images'])) {
$extractFeature = $this->extractFeature($data['images'], $data['files_name'], $data['id']);
$processTime["extractFeature"] = $extractFeature['time'];
$ft = $extractFeature['features'];
}
$start = $this->getCurrentTime();
$model = new ListManagement();
$model->create([
'code' => strval($data['code']),
'type' => "wl",
'name' => $data['name'],
'abbreviated_name' => $data['abbreviated_name'],
'staff_id' => $data['id'],
'image' => json_encode($ft),
'gender' => "Male",
'birthday' => "",
'telephone' => "",
'address' => $data['department']
]);
$finish = $this->getCurrentTime();
$processTime["insertDB"] = round(($finish - $start), 4);
// if ($totals <= 10)
// common::updateFeature([
// "cmd" => "create",
// "id" => $model->id,
// "name" => common::convert_vi_to_en($model->name),
// "features" => $model->allFeatures
// ]);
}
$totalFinish = $this->getCurrentTime();
$processTime["total"] = round(($totalFinish - $totalStart), 4);
$processTime["id"] = strval($data['code']);
return $processTime; //["status" => true];
}
}
public function actionSyncFeatureFromDevice() {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$data = Yii::$app->request->post();
$totals = intval($data['totals']);
$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 = [];
$imagesReverse = array_reverse($value['images']);
foreach ($imagesReverse as $k => $v) {
if ($k < Yii::$app->params['maxPicture']) {
$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,
"urlOld" => $fileName,
"features" => $v['features'],
"features512" => isset($v['features512']) ? $v['features512'] : []
];
}
}
$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 = $value['birthday'];
$model->telephone = $value['telephone'];
$model->address = $value['department'];
$model->save();
if ($totals <= 10)
common::updateFeature([
"cmd" => "update",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
} 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['department'],
'time' => $value['time']
]);
if ($totals <= 10)
common::updateFeature([
"cmd" => "create",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
}
}
return ["status" => true];
}
}
public function actionUpdateFeature() {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = "json";
file_get_contents("http://localhost:2305/update-feature?total=" . ListManagement::find()->count());
return ["status" => true];
}
}
public function actionChooseStaff() {
if (Yii::$app->request->post()) {
$post = Yii::$app->request->post();
$staff = ListManagement::findOne(['code' => $post['code']]);
Yii::$app->response->format = "json";
return [
"name" => $staff->name,
"gender" => $staff->gender,
"birthday" => date("d/m/Y", $staff->birthday),
"telephone" => $staff->telephone,
"department" => $staff->address,
"abbreviated_name" => $staff->abbreviated_name
];
}
}
public function actionSyncToServer() {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = "json";
$datas = ListManagement::find()->orderBy(["code" => SORT_ASC])->all();
$filters = [];
foreach ($datas as $key => $value) {
$filters[$value->staff_id] = $value->code . " - " . $value->name . " - " . $value->address;
}
return [
"title" => "<i class='fa fa-upload'></i> Đồng bộ lên máy chủ",
"form" => $this->renderPartial("list-to-server", [
"datas" => $datas,
"filters" => $filters
])
];
}
}
public function actionSyncFeatureToServer() {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "https://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(["staff_id" => Yii::$app->request->post("id")]);
$lsImgs = json_decode($StaffInfo->image, true);
$images = [];
foreach ($lsImgs as $key => $value) {
if (!isset($value['serverKey']) || (isset($value['serverKey']) && $value['serverKey'] == "")) {
try {
$images[] = base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value['url']));
} catch (\Exception $e) {
}
}
}
if (count($images) == 0)
return ["status" => true, "text" => "Dữ liệu không đổi"];
$items = [
"id" => $StaffInfo->staff_id,
"name" => $StaffInfo->name,
"abbreviated_name" => $StaffInfo->abbreviated_name,
"code" => $StaffInfo->code,
"department" => $StaffInfo->address,
"birthday" => date("Y-m-d", $StaffInfo->birthday),
"gender" => $StaffInfo == "Male" ? 1 : 0,
"telephone" => $StaffInfo->telephone,
"images" => $images
];
$start = $this->getCurrentTime();
try {
$res = json_decode(file_get_contents($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);
if ($res['status'] == 10000) {
$resData = $res['data'];
for ($i = 0; $i < count($lsImgs); $i++) {
$lsImgs[$i]['serverKey'] = isset($resData[$i]) ? $resData[$i] : "";
}
$StaffInfo->image = json_encode($lsImgs);
$StaffInfo->save();
}
} catch (\Exception $e) {
}
$finish = $this->getCurrentTime();
$processTime = round(($finish - $start), 4);
return $processTime; //$res; //["status" => true];
}
}
public function resizeImg($img, $fileTarget) {
$im = imagecreatefromstring($img);
$width = imagesx($im);
$height = imagesy($im);
$newwidth = 224;
$newheight = 224;
if ($width > $newwidth && $height > $newheight) {
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, $fileTarget);
imagedestroy($thumb);
imagedestroy($im);
return true;
}
return false;
}
public function actionTest() {
return file_get_contents("http://minio1.beetai.com/biface-school/origin/385/454_20201126101221879048.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20201230%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201230T081350Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=df7586a01bb128c0585edd87d1024b1ddb33483fd335e81238103fd2467b4772");
}
}