[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ], ]; } public function actionSaveLogs() { if (Yii::$app->request->post()) { $post = Yii::$app->request->bodyParams; $model = new \app\models\FaceLogs(); $model->create($post); Yii::$app->response->format = "json"; return ["stt" => true]; } } public function actionSyncUrl() { if (Yii::$app->request->post()) { $post = Yii::$app->request->bodyParams; $sync = \app\models\SyncUrl::find()->one(); if ($sync) { $sync->data = $post['url']; $sync->save(); } else { $model = new \app\models\SyncUrl(); $model->create($post); } Yii::$app->response->format = "json"; return ["stt" => true]; } } 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'])); $model = new CaptureLogs(); $model->create([ "Staff" => $post["id"], "Time" => $time, "Image" => $fileName ]); Yii::$app->response->format = "json"; return ["status" => "success"]; } } public function actionGetAllFeatures() { $listManagement = ListManagement::find()->all(); $allFeatures = []; foreach ($listManagement as $key => $value) { $features = json_decode($value->image, true); $f = []; foreach ($features as $k => $v) { $f[] = $v['features']; } $allFeatures[] = [ "id" => $value->id, "name" => $value->name, "features" => $f ]; } Yii::$app->response->format = "json"; return $allFeatures; } 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; } }