add log table
This commit is contained in:
parent
3aa90ec98e
commit
16d25abd7c
@ -9,6 +9,7 @@ use yii\filters\VerbFilter;
|
|||||||
use backend\models\UploadForm;
|
use backend\models\UploadForm;
|
||||||
use common\components\Helper;
|
use common\components\Helper;
|
||||||
use common\models\User;
|
use common\models\User;
|
||||||
|
use common\models\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Site controller
|
* Site controller
|
||||||
@ -74,6 +75,16 @@ class SiteController extends Controller
|
|||||||
];
|
];
|
||||||
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
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();
|
$this->sendLoginMail();
|
||||||
|
|
||||||
return $this->goBack();
|
return $this->goBack();
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace common\models;
|
namespace common\models;
|
||||||
|
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use common\models\BaseFitnessActiveRecord;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the model class for table "customer".
|
* This is the model class for table "customer".
|
||||||
@ -29,7 +30,7 @@ use Yii;
|
|||||||
* @property string $created_at
|
* @property string $created_at
|
||||||
* @property string $updated_at
|
* @property string $updated_at
|
||||||
*/
|
*/
|
||||||
class Customer extends \yii\db\ActiveRecord
|
class Customer extends BaseFitnessActiveRecord
|
||||||
{
|
{
|
||||||
|
|
||||||
const STATUS_DELETED = 0;
|
const STATUS_DELETED = 0;
|
||||||
@ -50,6 +51,7 @@ class Customer extends \yii\db\ActiveRecord
|
|||||||
return 'customer';
|
return 'customer';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -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)",
|
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)",
|
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ő",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
98
common/models/Log.php
Normal file
98
common/models/Log.php
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace common\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\helpers\Url;
|
||||||
|
use yii\helpers\VarDumper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the model class for table "log".
|
||||||
|
*
|
||||||
|
* @property integer $id_log
|
||||||
|
* @property integer $type
|
||||||
|
* @property string $message
|
||||||
|
* @property string $url
|
||||||
|
* @property string $app
|
||||||
|
* @property integer $id_user
|
||||||
|
* @property integer $id_transfer
|
||||||
|
* @property integer $id_money_movement
|
||||||
|
* @property integer $id_ticket
|
||||||
|
* @property integer $id_sale
|
||||||
|
* @property integer $id_customer
|
||||||
|
* @property integer $id_account
|
||||||
|
* @property integer $id_account_state
|
||||||
|
* @property integer $id_key
|
||||||
|
* @property integer $id_product
|
||||||
|
* @property integer $id_door_log
|
||||||
|
* @property string $created_at
|
||||||
|
* @property string $updated_at
|
||||||
|
*/
|
||||||
|
class Log extends \yii\db\ActiveRecord
|
||||||
|
{
|
||||||
|
|
||||||
|
public static $TYPE_INFO = 10;
|
||||||
|
public static $TYPE_ERR = 20;
|
||||||
|
public static $TYPE_TICKET_USAGE_FIRST = 30;
|
||||||
|
public static $TYPE_TICKET_USAGE_MULTIPLE = 40;
|
||||||
|
public static $TYPE_LOGIN = 50;
|
||||||
|
public static $TYPE_DEFAULT_ACCOUNT= 60;
|
||||||
|
public static $TYPE_CREATE_CUSTOMER= 70;
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public static function tableName()
|
||||||
|
{
|
||||||
|
return 'log';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function attributeLabels()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id_log' => 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -37,18 +37,26 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
|||||||
const STATUS_INACTIVE = 20;
|
const STATUS_INACTIVE = 20;
|
||||||
|
|
||||||
public static $SQL_UPDATE = "UPDATE card as c1
|
public static $SQL_UPDATE = "UPDATE card as c1
|
||||||
left JOIN ( select distinct ticket.id_card as id_card from ticket
|
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 ) as t
|
where ticket.start <= CURDATE()
|
||||||
on t.id_card = c1.id_card
|
and ticket.end >= curdate() and ticket.status = 10
|
||||||
SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end
|
and ticket.usage_count < ticket.max_usage_count
|
||||||
WHERE c1.type <> 50";
|
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
|
public static $SQL_UPDATE_CARD = "UPDATE card as c1
|
||||||
left JOIN ( select distinct ticket.id_card as id_card from ticket
|
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 ) as t
|
where ticket.start <= CURDATE()
|
||||||
on t.id_card = c1.id_card
|
and ticket.end >= curdate() and ticket.status = 10
|
||||||
SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end
|
and ticket.usage_count < ticket.max_usage_count
|
||||||
WHERE c1.type <> 50 and c1.id_card = :id";
|
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";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
75
console/migrations/m160316_063618_create__table__log.php
Normal file
75
console/migrations/m160316_063618_create__table__log.php
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use yii\db\Schema;
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
class m160316_063618_create__table__log extends Migration
|
||||||
|
{
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* log
|
||||||
|
id_log
|
||||||
|
type
|
||||||
|
message
|
||||||
|
url
|
||||||
|
app
|
||||||
|
id_user
|
||||||
|
id_transfer
|
||||||
|
id_money_movement
|
||||||
|
id_ticket
|
||||||
|
id_sale
|
||||||
|
id_customer
|
||||||
|
id_card
|
||||||
|
id_account
|
||||||
|
id_account_state
|
||||||
|
id_key
|
||||||
|
id_product
|
||||||
|
id_door_log
|
||||||
|
* */
|
||||||
|
|
||||||
|
$tableOptions = null;
|
||||||
|
if ($this->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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
@ -10,6 +10,8 @@ use yii\web\Controller;
|
|||||||
use yii\web\NotFoundHttpException;
|
use yii\web\NotFoundHttpException;
|
||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
use yii\base\Object;
|
use yii\base\Object;
|
||||||
|
use common\models\Log;
|
||||||
|
use common\models\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AccountController implements the CRUD actions for Account model.
|
* 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()) {
|
if ($model->load(Yii::$app->request->post()) && $model->writeToSession()) {
|
||||||
Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'Default account is set!') );
|
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->redirect(['product/sale']);
|
||||||
}
|
}
|
||||||
return $this->render('select', [
|
return $this->render('select', [
|
||||||
|
|||||||
@ -16,6 +16,7 @@ use frontend\models\CustomerCreate;
|
|||||||
use common\models\Image;
|
use common\models\Image;
|
||||||
use frontend\models\ContractForm;
|
use frontend\models\ContractForm;
|
||||||
use yii\base\Exception;
|
use yii\base\Exception;
|
||||||
|
use common\models\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CustomerController implements the CRUD actions for Customer model.
|
* 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()) {
|
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||||
$this->saveBinaryImage($model);
|
$this->saveBinaryImage($model);
|
||||||
\Yii::$app->session->setFlash( 'success','Vendég létrehozva!' );
|
\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]);
|
return $this->redirect(['update', 'number' => $model->cardNumber]);
|
||||||
} else {
|
} else {
|
||||||
return $this->render('create', [
|
return $this->render('create', [
|
||||||
|
|||||||
@ -14,6 +14,7 @@ use yii\filters\VerbFilter;
|
|||||||
use yii\filters\AccessControl;
|
use yii\filters\AccessControl;
|
||||||
use common\models\User;
|
use common\models\User;
|
||||||
use common\components\Helper;
|
use common\components\Helper;
|
||||||
|
use common\models\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Site controller
|
* Site controller
|
||||||
@ -90,6 +91,17 @@ class SiteController extends Controller
|
|||||||
|
|
||||||
$model = new LoginForm();
|
$model = new LoginForm();
|
||||||
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
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();
|
$this->sendLoginIp();
|
||||||
|
|
||||||
// return $this->goBack();
|
// return $this->goBack();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user