gioi han so mau cho 1 doi tuong

This commit is contained in:
dongpd 2020-12-22 16:17:34 +07:00
parent 40df99acd9
commit fc0f2ccc0f
5 changed files with 51 additions and 30 deletions

View File

@ -2,5 +2,6 @@
return [
'adminEmail' => 'admin@example.com',
"maxLogs" => 100000
"maxLogs" => 100000,
"maxPicture" => 5
];

View File

@ -108,6 +108,8 @@ class ListManagementController extends Controller {
$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 ($value['url'] === $url)
@ -135,6 +137,7 @@ class ListManagementController extends Controller {
file_get_contents("http://localhost:2305/update-feature");
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 {
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
@ -169,7 +172,8 @@ class ListManagementController extends Controller {
"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"
"image" => count($images) > 0 ? "/data/uploads/face/" . $images[0]['url'] : "/images/user2-160x160.jpg",
"canUpload" => count($images) >= Yii::$app->params['maxPicture'] ? false : true
];
}
}
@ -372,6 +376,7 @@ class ListManagementController extends Controller {
$targetPath = $RootFolder . "/face";
FileHelper::createDirectory($targetPath, 0777);
foreach ($data['images'] as $key => $value) {
if ($key < Yii::$app->params['maxPicture']) {
$key = common::generateRandomString();
$fileName = "face_" . $key . "_" . time() . ".png";
$img = file_get_contents($value);
@ -389,6 +394,7 @@ class ListManagementController extends Controller {
];
}
}
}
$model = ListManagement::findOne(['code' => $data['idStaff']]);
if ($model) {
$model->name = $data['name'];
@ -427,13 +433,19 @@ class ListManagementController extends Controller {
foreach ($results as $key => $value) {
$images = [];
foreach ($value['images'] 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, "features" => $v['features']];
$images[] = [
"url" => $fileName,
"features" => $v['features'],
"features512" => isset($v['features512']) ? $v['features512'] : []
];
}
}
$model = ListManagement::findOne(['code' => $value['code']]);
if ($model) {

View File

@ -58,11 +58,10 @@
'value' => \app\helpers\CaptureLogsGrid::confidence()
],
[
'attribute' => 'remark',
'attribute' => 'sync_status',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center']
],
'sync_status'
]
]
])}
</div>

View File

@ -55,8 +55,13 @@ function _save(e) {
id: $("input[name='CaptureLogsID']").val()
},
success: function (data) {
common.modalBlock(false);
if (data.status) {
alert("Đã thêm dữ liệu thành công!");
window.location.reload(true);
} else {
alert(data.text);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);

View File

@ -60,6 +60,10 @@ function _formModified(e) {
},
success: function (data) {
common.modalBlock(false);
if (data.canUpload)
$("#upload-btn").removeClass("hidden");
else
$("#upload-btn").addClass("hidden");
$("select[name='Type']").val(data.type);
$("select[name='Code']").val(data.code);
$("input[name='Name']").val(data.name);