diff --git a/backend/controllers/SiteController.php b/backend/controllers/SiteController.php index b0aadb1..162051e 100644 --- a/backend/controllers/SiteController.php +++ b/backend/controllers/SiteController.php @@ -9,6 +9,7 @@ use yii\filters\VerbFilter; use backend\models\UploadForm; use common\components\Helper; use common\models\User; +use common\models\Log; /** * Site controller @@ -74,6 +75,16 @@ class SiteController extends Controller ]; if ($model->load(Yii::$app->request->post()) && $model->login()) { + $geoip = Helper::getGeoIp(); + + $user = User::findOne(\Yii::$app->user->id); + $message = "Bejelentkezés: " .$user->username. " Ip cím:". $geoip->ip . " Város: " . $geoip->city; + + Log::log([ + 'type' =>Log::$TYPE_LOGIN, + 'message' => $message + ]); + $this->sendLoginMail(); return $this->goBack(); diff --git a/common/models/Customer.php b/common/models/Customer.php index ba2d763..f4866b2 100644 --- a/common/models/Customer.php +++ b/common/models/Customer.php @@ -3,6 +3,7 @@ namespace common\models; use Yii; +use common\models\BaseFitnessActiveRecord; /** * This is the model class for table "customer". @@ -29,7 +30,7 @@ use Yii; * @property string $created_at * @property string $updated_at */ -class Customer extends \yii\db\ActiveRecord +class Customer extends BaseFitnessActiveRecord { const STATUS_DELETED = 0; @@ -49,6 +50,7 @@ class Customer extends \yii\db\ActiveRecord { return 'customer'; } + /** * @inheritdoc diff --git a/common/models/DoorLog.php b/common/models/DoorLog.php index 1c334b2..52a0e6a 100644 --- a/common/models/DoorLog.php +++ b/common/models/DoorLog.php @@ -138,6 +138,9 @@ class DoorLog extends \yii\db\ActiveRecord 17 => "Bérlet érvényességi időn kívüli KI olvastatás (nem enged)", 19 => "Bérlet érvényességi időn kívüli BE olvastatás (nem enged)", + + 128 => "Vésznyitás", + 256 => "Kártya tiltva -> információ mező", ]; } diff --git a/common/models/Log.php b/common/models/Log.php new file mode 100644 index 0000000..60de4f0 --- /dev/null +++ b/common/models/Log.php @@ -0,0 +1,98 @@ + Yii::t('common/log', 'Id Log'), + 'type' => Yii::t('common/log', 'Type'), + 'message' => Yii::t('common/log', 'Message'), + 'url' => Yii::t('common/log', 'Url'), + 'app' => Yii::t('common/log', 'App'), + 'id_user' => Yii::t('common/log', 'Id User'), + 'id_transfer' => Yii::t('common/log', 'Id Transfer'), + 'id_money_movement' => Yii::t('common/log', 'Id Money Movement'), + 'id_ticket' => Yii::t('common/log', 'Id Ticket'), + 'id_sale' => Yii::t('common/log', 'Id Sale'), + 'id_customer' => Yii::t('common/log', 'Id Customer'), + 'id_account' => Yii::t('common/log', 'Id Account'), + 'id_account_state' => Yii::t('common/log', 'Id Account State'), + 'id_key' => Yii::t('common/log', 'Id Key'), + 'id_product' => Yii::t('common/log', 'Id Product'), + 'id_door_log' => Yii::t('common/log', 'Id Door Log'), + 'created_at' => Yii::t('common/log', 'Created At'), + 'updated_at' => Yii::t('common/log', 'Updated At'), + ]; + } + + + public static function info($message ){ + self::log(['type' =>self::$TYPE_INFO, 'message' => $message]); + } + public static function log( $config ){ + \Yii::info( "Log :" . VarDumper::dump( $config) ) ; + $model = new Log($config); + $model->app = \Yii::$app->name; + $model->url = Url::canonical(); + $model->id_user = \Yii::$app->user->id; + $model->save(); + } + +} diff --git a/common/models/Ticket.php b/common/models/Ticket.php index f3c4cc0..b368598 100644 --- a/common/models/Ticket.php +++ b/common/models/Ticket.php @@ -37,18 +37,26 @@ class Ticket extends \common\models\BaseFitnessActiveRecord const STATUS_INACTIVE = 20; public static $SQL_UPDATE = "UPDATE card as c1 - left JOIN ( select distinct ticket.id_card as id_card from ticket - where ticket.start <= CURDATE() and ticket.end >= curdate() and ticket.status = 10 ) as t - on t.id_card = c1.id_card - SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end - WHERE c1.type <> 50"; + left JOIN ( select distinct ticket.id_card as id_card ,ticket.id_ticket as id_ticket from ticket + where ticket.start <= CURDATE() + and ticket.end >= curdate() and ticket.status = 10 + and ticket.usage_count < ticket.max_usage_count + order by id_ticket desc limit 1 ) as t + on t.id_card = c1.id_card + SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end + , c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket end + WHERE c1.type <> 50"; public static $SQL_UPDATE_CARD = "UPDATE card as c1 - left JOIN ( select distinct ticket.id_card as id_card from ticket - where ticket.start <= CURDATE() and ticket.end >= curdate() and ticket.status = 10 ) as t - on t.id_card = c1.id_card - SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end - WHERE c1.type <> 50 and c1.id_card = :id"; + left JOIN ( select distinct ticket.id_card as id_card ,ticket.id_ticket as id_ticket from ticket + where ticket.start <= CURDATE() + and ticket.end >= curdate() and ticket.status = 10 + and ticket.usage_count < ticket.max_usage_count + order by id_ticket desc limit 1 ) as t + on t.id_card = c1.id_card + SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end + , c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket end + WHERE c1.type <> 50 and c1.id_card = :id"; /** diff --git a/console/migrations/m160316_063618_create__table__log.php b/console/migrations/m160316_063618_create__table__log.php new file mode 100644 index 0000000..3c0f159 --- /dev/null +++ b/console/migrations/m160316_063618_create__table__log.php @@ -0,0 +1,75 @@ +db->driverName === 'mysql') { + // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; + } + + $this->createTable( '{{%log}}', [ + 'id_log' => $this->primaryKey(), + 'type' => $this->integer(11), + 'message' => $this->string(), + 'url' => $this->text(), + 'app' => $this->string(50), + 'id_user' => $this->integer(11), + 'id_transfer' => $this->integer(11), + 'id_money_movement' => $this->integer(11), + 'id_ticket' => $this->integer(11), + 'id_sale' => $this->integer(11), + 'id_customer' => $this->integer(11), + 'id_account' => $this->integer(11), + 'id_account_state' => $this->integer(11), + 'id_key' => $this->integer(11), + 'id_product' => $this->integer(11), + 'id_door_log' => $this->integer(11), + 'created_at' => $this->dateTime()->notNull(), + 'updated_at' => $this->dateTime()->notNull(), + ], $tableOptions ); + + } + + public function down() + { + $this->dropTable("{{%log}}"); + } + + /* + // Use safeUp/safeDown to run migration code within a transaction + public function safeUp() + { + } + + public function safeDown() + { + } + */ +} diff --git a/frontend/controllers/AccountController.php b/frontend/controllers/AccountController.php index f1d44e9..6850191 100644 --- a/frontend/controllers/AccountController.php +++ b/frontend/controllers/AccountController.php @@ -10,6 +10,8 @@ use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\base\Object; +use common\models\Log; +use common\models\User; /** * AccountController implements the CRUD actions for Account model. @@ -43,6 +45,12 @@ class AccountController extends Controller if ($model->load(Yii::$app->request->post()) && $model->writeToSession()) { Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'Default account is set!') ); + + $user = User::findOne(\Yii::$app->user->id); + Log::log([ 'type' => Log::$TYPE_DEFAULT_ACCOUNT, + 'message' => "Alapértelmezett kassza - Felhasználó: " . $user->username . " - Kassza: " . Account::readDefaultObject()->name, + 'id_account' => Account::readDefault(), + ]); return $this->redirect(['product/sale']); } return $this->render('select', [ diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index db1c268..0d327a0 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -16,6 +16,7 @@ use frontend\models\CustomerCreate; use common\models\Image; use frontend\models\ContractForm; use yii\base\Exception; +use common\models\Log; /** * CustomerController implements the CRUD actions for Customer model. @@ -127,6 +128,13 @@ class CustomerController extends Controller if ($model->load(Yii::$app->request->post()) && $model->save()) { $this->saveBinaryImage($model); \Yii::$app->session->setFlash( 'success','Vendég létrehozva!' ); + + Log::log([ + 'type' =>Log::$TYPE_CREATE_CUSTOMER, + 'message' => 'Új vendég:' .$model->name, + 'id_customer' => $model->id_customer + ]); + return $this->redirect(['update', 'number' => $model->cardNumber]); } else { return $this->render('create', [ diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 10b124a..6247449 100644 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -14,6 +14,7 @@ use yii\filters\VerbFilter; use yii\filters\AccessControl; use common\models\User; use common\components\Helper; +use common\models\Log; /** * Site controller @@ -90,6 +91,17 @@ class SiteController extends Controller $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { + + $geoip = Helper::getGeoIp(); + + $user = User::findOne(\Yii::$app->user->id); + $message = "Bejelentkezés: " .$user->username. " Ip cím:". $geoip->ip . " Város: " . $geoip->city; + + Log::log([ + 'type' =>Log::$TYPE_LOGIN, + 'message' => $message + ]); + $this->sendLoginIp(); // return $this->goBack();