update control logs

This commit is contained in:
dongpd 2020-12-04 15:13:14 +07:00
parent 3ef04dfb5a
commit 811ed32e04
13 changed files with 282 additions and 36 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace app\assets;
use yii\web\AssetBundle;
class ControlLogsAsset extends AssetBundle {
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
];
public $js = [
'js/control-logs.js'
];
public $depends = [
'yii\web\YiiAsset',
'app\assets\AppAsset',
'yii\jui\JuiAsset',
'yii\bootstrap\BootstrapAsset',
];
}

View File

@ -65,14 +65,12 @@ class ApiController extends Controller {
FileHelper::createDirectory($targetPath, 0777); FileHelper::createDirectory($targetPath, 0777);
file_put_contents($targetPath . "/" . $fileName, base64_decode($post['image'])); file_put_contents($targetPath . "/" . $fileName, base64_decode($post['image']));
if ($post["id"] == 0) {
$model = new CaptureLogs(); $model = new CaptureLogs();
$model->create([ $model->create([
"Staff" => 0, "Staff" => $post["id"],
"Time" => $time, "Time" => $time,
"Image" => $fileName "Image" => $fileName
]); ]);
}
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
return ["status" => "success"]; return ["status" => "success"];
} }

View File

@ -39,7 +39,8 @@ class CaptureLogsController extends Controller {
$this->view->title = "Capture Log"; $this->view->title = "Capture Log";
$searchModel = new CaptureLogsSearch(); $searchModel = new CaptureLogsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->query->andWhere(["BETWEEN", "time", $f, $t]); $dataProvider->query->andWhere(["capture_logs.staff_id" => 0]);
$dataProvider->query->andWhere(["BETWEEN", "capture_logs.time", $f, $t]);
$dataProvider->query->orderBy(["time" => SORT_DESC]); $dataProvider->query->orderBy(["time" => SORT_DESC]);
return $this->render('index', [ return $this->render('index', [

View File

@ -0,0 +1,72 @@
<?php
namespace app\controllers;
use Yii;
use app\models\CaptureLogs;
use app\models\CaptureLogsSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use app\models\ListManagement;
/**
* CaptureLogsController implements the CRUD actions for CaptureLogs model.
*/
class ControlLogsController extends Controller {
/**
* {@inheritdoc}
*/
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
public function actionIndex($from = "", $to = "", $name = "", $type = "all", $gender = "all") {
$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');
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');
}
$this->view->title = "Control Log";
$searchModel = new CaptureLogsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->query->andWhere(["<>", "capture_logs.staff_id", 0]);
$dataProvider->query->andWhere(["BETWEEN", "capture_logs.time", $f, $t]);
if ($name !== "")
$dataProvider->query->andWhere(["LIKE", "list_management.name", $name]);
if ($type !== "all")
$dataProvider->query->andWhere(["list_management.type" => $type]);
if ($gender !== "all")
$dataProvider->query->andWhere(["list_management.gender" => $gender]);
$dataProvider->query->orderBy(["time" => SORT_DESC]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'statusArray' => CaptureLogs::$statusArray,
'f' => $f,
't' => $t,
'typeArray' => ListManagement::$typeArray,
'genderArray' => ListManagement::$genderArray
]);
}
protected function findModel($id) {
if (($model = CaptureLogs::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -87,7 +87,9 @@ class ListManagementController extends Controller {
$images[] = ["url" => $url, "features" => $features['results'][0]['feature']]; $images[] = ["url" => $url, "features" => $features['results'][0]['feature']];
$listManagement->image = json_encode($images); $listManagement->image = json_encode($images);
$listManagement->time = time(); $listManagement->time = time();
return $listManagement->save(); $listManagement->save();
file_get_contents("http://localhost:2305/update-feature");
return ["status" => true];
} }
} else { } else {
$features = json_decode(common::requestToEngine("/get-feature", [ $features = json_decode(common::requestToEngine("/get-feature", [
@ -98,7 +100,9 @@ class ListManagementController extends Controller {
$data['image'] = json_encode([ $data['image'] = json_encode([
["url" => $url, "features" => $features['results'][0]['feature']] ["url" => $url, "features" => $features['results'][0]['feature']]
]); ]);
return $model->create($data); $model->create($data);
file_get_contents("http://localhost:2305/update-feature");
return ["status" => true];
} }
} }
} }
@ -116,7 +120,7 @@ class ListManagementController extends Controller {
"birthday" => date("d/m/Y", $ListManagement->birthday), "birthday" => date("d/m/Y", $ListManagement->birthday),
"telephone" => $ListManagement->telephone, "telephone" => $ListManagement->telephone,
"address" => $ListManagement->address, "address" => $ListManagement->address,
"image" => "/BiFace/data/uploads/face/" . $images[0]['url'] "image" => "/data/uploads/face/" . $images[0]['url']
]; ];
} }
} }
@ -131,14 +135,18 @@ class ListManagementController extends Controller {
$model->birthday = $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U'); $model->birthday = $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U');
$model->telephone = $data['telephone']; $model->telephone = $data['telephone'];
$model->address = $data['address']; $model->address = $data['address'];
return $model->save(); $model->save();
file_get_contents("http://localhost:2305/update-feature");
return true;
} }
} }
public function actionDelete() { public function actionDelete() {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
$data = Yii::$app->request->post(); $data = Yii::$app->request->post();
return $this->findModel($data['id'])->delete(); $this->findModel($data['id'])->delete();
file_get_contents("http://localhost:2305/update-feature");
return true;
} }
} }
@ -153,7 +161,9 @@ class ListManagementController extends Controller {
$features[] = $value; $features[] = $value;
} }
$model->image = json_encode($features); $model->image = json_encode($features);
return $model->save(); $model->save();
file_get_contents("http://localhost:2305/update-feature");
return true;
} }
} }
@ -168,7 +178,9 @@ class ListManagementController extends Controller {
public function actionBatchDelete() { public function actionBatchDelete() {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
$data = Yii::$app->request->post(); $data = Yii::$app->request->post();
return ListManagement::deleteAll(["IN", "id", $data['lists']]); ListManagement::deleteAll(["IN", "id", $data['lists']]);
file_get_contents("http://localhost:2305/update-feature");
return true;
} }
} }

View File

@ -62,4 +62,22 @@ class CaptureLogsGrid {
}; };
} }
public static function birthday() {
return function($model) {
$staff = $model->listManagement;
return date("d/m/Y", $staff->birthday);
};
}
public static function registrationImage() {
return function($model) {
$staff = $model->listManagement;
$images = json_decode($staff->image, true);
return Html::img("/data/uploads/face/" . $images[0]['url'], [
"class" => "img-thumbnail",
"style" => "width: 150px;height:150px;"
]);
};
}
} }

View File

@ -40,9 +40,11 @@ class CaptureLogs extends \yii\db\ActiveRecord {
return [ return [
'id' => 'ID', 'id' => 'ID',
'time' => 'Time', 'time' => 'Time',
'image' => 'Image', 'image' => 'Live Image',
'status' => 'Status', 'status' => 'Status',
'remark' => 'Remark', 'remark' => 'Remark',
'staff_name' => "Name",
'staff_image' => "Registration Image"
]; ];
} }
@ -69,4 +71,8 @@ class CaptureLogs extends \yii\db\ActiveRecord {
1 => "List management" 1 => "List management"
]; ];
public function getListManagement() {
return $this->hasOne(ListManagement::className(), ["id" => "staff_id"]);
}
} }

View File

@ -10,24 +10,24 @@ use app\models\CaptureLogs;
/** /**
* CaptureLogsSearch represents the model behind the search form of `app\models\CaptureLogs`. * CaptureLogsSearch represents the model behind the search form of `app\models\CaptureLogs`.
*/ */
class CaptureLogsSearch extends CaptureLogs class CaptureLogsSearch extends CaptureLogs {
{
public $staff_name;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function rules() public function rules() {
{
return [ return [
[['id', 'time', 'status'], 'integer'], [['id', 'time', 'status'], 'integer'],
[['image', 'remark'], 'safe'], [['image', 'remark', 'staff_name'], 'safe'],
]; ];
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function scenarios() public function scenarios() {
{
// bypass scenarios() implementation in the parent class // bypass scenarios() implementation in the parent class
return Model::scenarios(); return Model::scenarios();
} }
@ -39,9 +39,9 @@ class CaptureLogsSearch extends CaptureLogs
* *
* @return ActiveDataProvider * @return ActiveDataProvider
*/ */
public function search($params) public function search($params) {
{
$query = CaptureLogs::find(); $query = CaptureLogs::find();
$query->joinWith("listManagement");
// add conditions that should always apply here // add conditions that should always apply here
@ -69,4 +69,5 @@ class CaptureLogsSearch extends CaptureLogs
return $dataProvider; return $dataProvider;
} }
} }

View File

@ -41,11 +41,6 @@ use yii\widgets\ActiveForm;
<i class="fa fa-cogs"></i> Cấu hình <i class="fa fa-cogs"></i> Cấu hình
</a> </a>
</li> </li>
<li class="<?php if (Yii::$app->controller->id == "dashboard") echo "active"; ?>">
<a href="<?php echo yii\helpers\Url::to(['/dashboard']); ?>">
<i class="fa fa-database"></i> Dữ liệu
</a>
</li>
<li> <li>
<a href="<?php echo yii\helpers\Url::to(['/config/reset']); ?>" onclick="common.reset(this);return false;"> <a href="<?php echo yii\helpers\Url::to(['/config/reset']); ?>" onclick="common.reset(this);return false;">
<i class="fa fa-refresh"></i> Reset thiết bị <i class="fa fa-refresh"></i> Reset thiết bị
@ -61,6 +56,11 @@ use yii\widgets\ActiveForm;
<i class="fa fa-camera"></i> Capture log <i class="fa fa-camera"></i> Capture log
</a> </a>
</li> </li>
<li class="<?php if (Yii::$app->controller->id == "control-logs") echo "active"; ?>">
<a href="<?php echo yii\helpers\Url::to(['/control-logs']); ?>">
<i class="fa fa-database"></i> Control log
</a>
</li>
</ul> </ul>
</div> </div>
<div class="navbar-custom-menu"> <div class="navbar-custom-menu">

View File

@ -0,0 +1,102 @@
{extends file=$smarty.current_dir|cat:'/../extends.tpl'}
{use class="yii\helpers\Url"}
{use class="yii\grid\GridView"}
{use class="app\assets\ControlLogsAsset"}
{ControlLogsAsset::register($this)|void}
{block name='content'}
<style>
.row{
margin-bottom: 5px;
}
input{
width: 100%;
}
.table-striped > tbody > tr:nth-of-type(odd){
background-color: rgb(210, 210, 210);
}
</style>
<div class="row">
<div class="col-md-10" style="max-height: 850px;overflow-y: auto;">
{GridView::widget([
'dataProvider' => $dataProvider,
'layout'=> \app\helpers\CaptureLogsGrid::getLayout(),
'tableOptions' => [
'class' => 'table table-striped table-bordered',
'style' => 'background:#fff;min-width:700px;'
],
'rowOptions' => \app\helpers\CaptureLogsGrid::rows(),
'columns' => [
[
'attribute' => 'id',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center']
],
[
'attribute' => 'time',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center'],
'value' => \app\helpers\CaptureLogsGrid::time()
],
[
'attribute' => 'staff_image',
'format' => 'raw',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center', 'style' => 'width:15%'],
'value' => \app\helpers\CaptureLogsGrid::registrationImage()
],
[
'attribute' => 'image',
'format' => "raw",
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center', 'style' => 'width:15%'],
'value' => \app\helpers\CaptureLogsGrid::image()
],
'listManagement.name',
'listManagement.gender',
'listManagement.telephone',
[
'attribute' => 'listManagement.birthday',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center'],
'value' => \app\helpers\CaptureLogsGrid::birthday()
],
'listManagement.address'
]
])}
</div>
<div class="col-md-2" style="padding-right: 30px;">
<h4>Tìm kiếm dữ liệu</h4>
<div class="form-group">
<label class="control-label">Từ</label>
<input type="text" class="form-control datepicker" value="{$f|date_format:"H:i d/m/Y"}" name="From">
</div>
<div class="form-group">
<label class="control-label">Đến</label>
<input type="text" class="form-control datepicker" value="{$t|date_format:"H:i d/m/Y"}" name="To">
</div>
<div class="form-group">
<label class="control-label">Name</label>
<input type="text" class="form-control" value="{Yii::$app->request->get("name")}" name="NameSearch">
</div>
<div class="form-group">
<label class="control-label">Type</label>
<select class="form-control" name="TypeSearch">
<option value="all">All</option>
{html_options options=$typeArray selected=Yii::$app->request->get("type")}
</select>
</div>
<div class="form-group">
<label class="control-label">Gender</label>
<select class="form-control" name="GenderSearch">
<option value="all">All</option>
{html_options options=$genderArray selected=Yii::$app->request->get("gender")}
</select>
</div>
<div class="text-center">
<button class="btn btn-info" onclick="_search(this);" data-href="{Url::to(['/control-logs'])}">
<i class="fa fa-search"></i> Tìm kiếm
</button>
</div>
</div>
</div>
{/block}

View File

@ -136,12 +136,12 @@
</div> </div>
</div> </div>
</div> </div>
<hr style="border-top: 1px solid #000;"> {*<hr style="border-top: 1px solid #000;">
<div class="text-center"> <div class="text-center">
<button class="btn btn-info" onclick="_form();"> <button class="btn btn-info" onclick="_form();">
<i class="fa fa-plus-circle"></i> Thêm mới <i class="fa fa-plus-circle"></i> Thêm mới
</button> </button>
</div> </div>*}
</div> </div>
</div> </div>
<div style="width: 300px;position: absolute;" id="menu" class="hidden"> <div style="width: 300px;position: absolute;" id="menu" class="hidden">
@ -166,7 +166,7 @@
<div class="row"> <div class="row">
<div class="col-md-4 text-center"> <div class="col-md-4 text-center">
<img src="" class="img-thumbnail" id="FaceImage" style="width: 150px;height: 150px;"> <img src="" class="img-thumbnail" id="FaceImage" style="width: 150px;height: 150px;">
<div class=""> <div class="" id="upload-btn">
<input type="file" name="AnhNhanVien" id="AnhNhanVien"> <input type="file" name="AnhNhanVien" id="AnhNhanVien">
<input type="hidden" name="AnhNhanVienUrl" value=""> <input type="hidden" name="AnhNhanVienUrl" value="">
<input type="hidden" name="url_upload_staff_image" value="{Url::to(['upload'])}"> <input type="hidden" name="url_upload_staff_image" value="{Url::to(['upload'])}">

11
web/js/control-logs.js Normal file
View File

@ -0,0 +1,11 @@
$(function () {
common.dateTimePickerByClass("datepicker", "HH:mm DD/MM/YYYY");
});
function _search(e) {
var location = $(e).attr("data-href") + "?from=" + $("input[name='From']").val() + "&to=" + $("input[name='To']").val();
location = location + "&name=" + $("input[name='NameSearch']").val();
location = location + "&type=" + $("select[name='TypeSearch']").val();
location = location + "&gender=" + $("select[name='GenderSearch']").val();
window.location = location;
}

View File

@ -59,6 +59,7 @@ function _formModified(e) {
}, },
success: function (data) { success: function (data) {
common.modalBlock(false); common.modalBlock(false);
$("#upload-btn").addClass("hidden");
$("select[name='Type']").val(data.type); $("select[name='Type']").val(data.type);
$("input[name='Name']").val(data.name); $("input[name='Name']").val(data.name);
$("select[name='Gender']").val(data.gender); $("select[name='Gender']").val(data.gender);
@ -186,6 +187,7 @@ function batchDelete(e) {
function _form() { function _form() {
$("#form").removeClass("hidden"); $("#form").removeClass("hidden");
$("#upload-btn").removeClass("hidden");
$("#FaceImage").attr("src", "/images/user2-160x160.jpg"); $("#FaceImage").attr("src", "/images/user2-160x160.jpg");
} }