update biface local

This commit is contained in:
2020-12-01 16:47:43 +07:00
parent 73b44eb2af
commit efb4113001
21 changed files with 883 additions and 57 deletions

View File

@@ -5,6 +5,8 @@ namespace app\controllers;
use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\helpers\FileHelper;
use app\models\CaptureLogs;
/**
* CardController implements the CRUD actions for Card model.
@@ -51,4 +53,37 @@ class ApiController extends Controller {
}
}
public function actionGetLogs() {
if (Yii::$app->request->post()) {
$post = Yii::$app->request->bodyParams;
$time = date_format(date_create_from_format('Y-m-d H:i:s', $post['time']), 'U');
$key = $this->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($post['image']));
if ($post["id"] == 0) {
$model = new CaptureLogs();
$model->create([
"Time" => $time,
"Image" => $fileName
]);
}
Yii::$app->response->format = "json";
return ["status" => "success"];
}
}
public function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
}

View File

@@ -6,21 +6,14 @@ use Yii;
use app\models\CaptureLogs;
use app\models\CaptureLogsSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\helpers\Url;
/**
* ScriptController implements the CRUD actions for Script model.
* CaptureLogsController implements the CRUD actions for CaptureLogs model.
*/
class CaptureLogsController extends Controller {
public function init() {
parent::init();
if (Yii::$app->user->isGuest) {
return $this->redirect(['/site/login']);
}
}
/**
* {@inheritdoc}
*/
@@ -35,20 +28,71 @@ class CaptureLogsController extends Controller {
];
}
/**
* Lists all Script models.
* @return mixed
*/
public function actionIndex() {
$this->view->title = "Ảnh mẫu";
public function actionIndex($from = "", $to = "") {
$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 = "Capture Log";
$searchModel = new CaptureLogsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->query->andWhere(["BETWEEN", "time", $f, $t]);
$dataProvider->query->orderBy(["time" => SORT_DESC]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'statusArray' => CaptureLogs::$statusArray,
'f' => $f,
't' => $t
]);
}
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
public function actionCreate() {
$model = new CaptureLogs();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
public function actionUpdate($id) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
public function actionDelete($id) {
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
protected function findModel($id) {
if (($model = CaptureLogs::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@@ -170,7 +170,7 @@ class ConfigController extends Controller {
]
];
$ip = "192.168.0.42";
$tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadAPIConfig", false, stream_context_create($options)), true);
$tempConfig = json_decode(file_get_contents("http://192.168.1.241:4004/ReadAPIConfig", false, stream_context_create($options)), true);
if ($tempConfig['status']) {
$t = json_decode($tempConfig['data'], true);
$temp = explode("/", $t['url']);

View File

@@ -0,0 +1,93 @@
<?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;
/**
* 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 = "") {
$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 = "List management";
$searchModel = new ListManagementSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->query->andWhere(["BETWEEN", "time", $f, $t]);
$dataProvider->query->orderBy(["time" => SORT_DESC]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'f' => $f,
't' => $t,
'typeArray' => ListManagement::$typeArray
]);
}
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
public function actionCreate() {
$model = new ListManagement();
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$data['image'] = \app\models\CaptureLogs::findOne($data['id'])->image;
return $model->create($data);
}
}
public function actionUpdate($id) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
public function actionDelete($id) {
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
protected function findModel($id) {
if (($model = ListManagement::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}