add feature enable/disable reception door log

This commit is contained in:
Roland Schneider 2017-02-28 20:29:10 +01:00
parent f27528d4cb
commit 1ff1d03a07
13 changed files with 223 additions and 115 deletions

View File

@ -1,2 +1,2 @@
* *
!.gitignore !.gitignore

32
clean_runtime.sh Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env bash
FITNESS_HOME=$(pwd)
echo ${FITNESS_HOME}
cd ${FITNESS_HOME}/backend
rm -r runtime
mkdir runtime
cd runtime
cat > .gitignore <<EOF
*
!.gitignore
EOF
cd ${FITNESS_HOME}/console
rm -r runtime
mkdir runtime
cd runtime
cat > .gitignore <<EOF
*
!.gitignore
EOF
cd ${FITNESS_HOME}/frontend
rm -r runtime
mkdir runtime
cd runtime
cat > .gitignore <<EOF
*
!.gitignore
EOF

View File

@ -376,6 +376,10 @@ class Helper {
return \Yii::$app->params ['ticket_create_price_editable'] == true ; return \Yii::$app->params ['ticket_create_price_editable'] == true ;
} }
public static function isKeyToggleDoorLogEnabled() {
return \Yii::$app->params ['key_toggle_door_log_enabled'] == true ;
}
public static function isReceptionTransferListToday(){ public static function isReceptionTransferListToday(){
return \Yii::$app->params['reception_transfer_list_only_today']; return \Yii::$app->params['reception_transfer_list_only_today'];
} }

View File

@ -54,6 +54,10 @@ return [
] ]
], ],
'newsletter_from' => 'noreply@fitnessadmin.hu', 'newsletter_from' => 'noreply@fitnessadmin.hu',
'newsletter_enabled' => false 'newsletter_enabled' => false,
/**
* if true, key in/out events will generate doorlog events
*/
'key_toggle_door_log_enabled' => false
]; ];

View File

@ -0,0 +1,119 @@
DROP TRIGGER IF EXISTS trigger_inc_ticket_usage_count;
CREATE TRIGGER trigger_inc_ticket_usage_count
AFTER INSERT ON `door_log` FOR EACH ROW
begin
DECLARE p_count_all Integer;
DECLARE p_count_all_2 Integer;
DECLARE p_from DATETIME;
DECLARE p_usage_count Integer;
DECLARE p_max_usage_count Integer;
DECLARE p_mo_ticket_id Integer;
DECLARE p_mo_ticket_max_usage_count Integer;
DECLARE p_allow_multiple_enter boolean;
DECLARE p_allow_enter boolean;
delete from devlog;
IF NEW.id_customer is not null and NEW.id_card is not null
THEN
IF (NEW.direction = 7 or New.direction = 3 ) and NEW.id_ticket_current is not null
then
INSERT INTO devlog ( msg) values('belepes feldoglozas indit');
select count(*) into @p_count_all from door_log where created_at >= CURDATE() and id_ticket_current = New.id_ticket_current and ( direction = 7 or direction = 3);
INSERT INTO devlog ( msg) values( concat( 'count all' ,@p_count_all ) );
IF @p_count_all = 1
THEN
select usage_count, max_usage_count into @p_usage_count ,@p_max_usage_count from ticket where id_ticket = NEW.id_ticket_current;
update ticket set usage_count = usage_count +1 where id_ticket = NEW.id_ticket_current;
INSERT INTO log (type,message, app, id_ticket, id_door_log,created_at, updated_at)
values(
30, concat('Bérlet használat (elotte: ',@p_usage_count, ' > utana: ' , @p_usage_count +1 , ' max: ', @p_max_usage_count, ')' ), ' trigger_inc_ticket',New.id_ticket_current, New.id_door_log,now(),now());
else
select min(created_at) + INTERVAL (3 * FLOOR( ( ( HOUR( TIMEDIFF( min(created_at) , now() ) ) /3 ) ) ) ) hour as last_date
into @p_from
from door_log
where created_at > CURDATE() and id_customer is not null and id_ticket_current = NEW.id_ticket_current and ( direction = 7 or direction = 3);
select count(*) into @p_count_all_2 from door_log where created_at >= @p_from and id_ticket_current = New.id_ticket_current and ( direction = 7 or direction = 3);
INSERT INTO devlog ( msg) values(CONCAT( 'Belépések száma az aktuális 3 órás intervalumban: ', @p_count_all_2) );
IF @p_count_all_2 = 1
THEN
INSERT INTO devlog ( msg) values( 'Az aktuális intervallumban ez az első belépés, usage_count növelése' );
select usage_count, max_usage_count into @p_usage_count ,@p_max_usage_count from ticket where id_ticket = NEW.id_ticket_current;
update ticket set usage_count = usage_count +1 where id_ticket = New.id_ticket_current;
INSERT INTO log (type,message, app, id_ticket, id_door_log,created_at, updated_at)
values(
40, concat('Bérlet használat/egy nap tobbszori (elotte: ',@p_usage_count, ' > utana: ' , @p_usage_count +1 , ' max: ', @p_max_usage_count, ')' ), ' trigger_inc_ticket',New.id_ticket_current, New.id_door_log,now(),now());
END IF;
END IF;
End IF;
IF NEW.direction = 5 or New.direction = 1
then
INSERT INTO devlog ( msg) values('Kilépés van folyamatban, kilépések számának beállítása');
update ticket set count_move_out = usage_count where id_ticket = NEW.id_ticket_current;
END IF;
INSERT INTO devlog ( msg) values( 'Kártya validáció módosítása' );
UPDATE card as c1
left JOIN ( select ticket.id_card as id_card , max(ticket.id_ticket) as id_ticket
from ticket
where ticket.start <= CURDATE()
and ticket.end >= curdate()
and ticket.status = 10
and ticket.count_move_out < ticket.max_usage_count
and ticket.id_card = New.id_card
group by id_card
order by id_card desc ) as t
on t.id_card = c1.id_card
SET c1.validity = case when t.id_card is null then ( c1.validity | 1 << 0 ) else ( c1.validity & ~(1 << 0) ) end
, 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 = New.id_card;
IF NEW.direction = 5 or New.direction = 1
then
select max(ticket.id_ticket) into @p_mo_ticket_id
from ticket
where ticket.start <= CURDATE()
and ticket.end >= curdate()
and ticket.status = 10
and ticket.count_move_out < ticket.max_usage_count
and ticket.id_card = New.id_card
group by id_card
order by id_card desc;
set @p_allow_enter = true;
update card set
flag_out = ( flag_out | 1 << 1 ) ,
flag = case when @p_allow_enter then ( flag & ~(1 << 1) ) else ( flag | 1 << 1 ) end
WHERE type <> 50 and id_card = New.id_card;
END IF;
IF (NEW.direction = 7 or New.direction = 3 ) and NEW.id_ticket_current is not null
THEN
update card set
flag_out = ( flag_out & ~(1 << 1 ) ) ,
flag = ( flag | 1 << 1 )
WHERE type <> 50 and id_card = New.id_card;
END IF;
END IF;
END

View File

@ -174,6 +174,10 @@ class DoorLog extends \yii\db\ActiveRecord
public static function mkDoorLog($direction,$card,$customer = null,$key = null){ public static function mkDoorLog($direction,$card,$customer = null,$key = null){
if ( !Helper::isKeyToggleDoorLogEnabled() ){
return;
}
$dlog = new DoorLog(); $dlog = new DoorLog();
$dlog->id_card = $card->id_card; $dlog->id_card = $card->id_card;

View File

@ -1,39 +1,21 @@
<?php <?php
namespace console\controllers; namespace console\controllers;
use Yii; use /** @noinspection PhpUnusedAliasInspection */
use common\models; Yii;
use yii\console\Controller; use yii\console\Controller;
use common\models\Ticket; use common\models\Ticket;
use common\models\DoorLog; use common\models\DoorLog;
use yii\helpers\VarDumper;
use common\models\Customer;
use common\models\Log; use common\models\Log;
class DoorlogController extends Controller{ class DoorlogController extends Controller{
public $ticket; public $ticket;
// public function options($actionID)
// {
// return ['ticket'];
// }
// public function optionAliases()
// {
// return ['t' => 'ticket'];
// }
public function actionIn($ticket) public function actionIn($ticket)
{ {
$log = new DoorLog(); $log = new DoorLog();
//5559 9719 //5559 9719
$log->id_card = 9719; $log->id_card = 9719;
$log->id_customer = 5559; $log->id_customer = 5559;
$log->id_ticket_current = $ticket; $log->id_ticket_current = $ticket;
@ -44,9 +26,6 @@ class DoorlogController extends Controller{
$log->id_account = null; $log->id_account = null;
$log->card_flag = 0; $log->card_flag = 0;
$log->flag_out= 0; $log->flag_out= 0;
$log->save(false); $log->save(false);
} }
@ -92,12 +71,12 @@ class DoorlogController extends Controller{
public function actionFixmissing(){ public function actionFixmissing(){
$tickets = Ticket::find()->andWhere(['in','id_ticket_type' ,[54,55,56,57]])->all(); $tickets = Ticket::find()->andWhere(['in','id_ticket_type' ,[54,55,56,57]])->all();
/** @var /common/models/Ticket $ticket */
foreach ($tickets as $ticket){ foreach ($tickets as $ticket){
$cache = []; $cache = [];
$doorlogs = DoorLog::find()->andWhere( [ 'id_ticket_current' => $ticket->id_ticket, 'direction' => 7 ])->all(); $doorlogs = DoorLog::find()->andWhere( [ 'id_ticket_current' => $ticket->id_ticket, 'direction' => 7 ])->all();
@ -129,23 +108,17 @@ class DoorlogController extends Controller{
} }
if ( count($cache) > 0 ){ if ( count($cache) > 0 ){
foreach ($cache as $item){ foreach ($cache as $item){
echo $item['id']; echo $item['id'];
echo "/"; echo "/";
echo $item['count']; echo $item['count'];
echo "\r\n"; echo "\r\n";
$t = Ticket::findOne($ticket->id_ticket); $t = Ticket::findOne($ticket->id_ticket);
$elotte = $t->usage_count; $elotte = $t->usage_count;
$t->usage_count = $t->usage_count + 1; $t->usage_count = $t->usage_count + 1;
$t->count_move_out = $t->usage_count; $t->count_move_out = $t->usage_count;
$t->save(false); $t->save(false);
$log = new Log(); $log = new Log();
$log->type = 30; $log->type = 30;
$log->id_ticket = $ticket->id_ticket; $log->id_ticket = $ticket->id_ticket;
@ -153,18 +126,17 @@ class DoorlogController extends Controller{
$log->id_door_log = $item['id']; $log->id_door_log = $item['id'];
$log->message = "FixMissing: Bérlet használat (elotte: " . $elotte ." > utana: " . $t->usage_count . " max: ". $t->max_usage_count .")"; $log->message = "FixMissing: Bérlet használat (elotte: " . $elotte ." > utana: " . $t->usage_count . " max: ". $t->max_usage_count .")";
$log->save(false); $log->save(false);
} }
} }
} }
} }
public function actionDeleteOld(){
$sql = "DELETE FROM door_log WHERE created_at < DATE_SUB(NOW(), INTERVAL 3 MONTH);";
$cmd = \Yii::$app->db->createCommand($sql);
$count = $cmd->execute();
\Yii::info("Door logs deleted: " . $count );
}
} }

View File

@ -1,2 +1,2 @@
* *
!.gitignore !.gitignore

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/index php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/index
php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/daily php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/daily
php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii doorlog/delete-old

View File

@ -6,7 +6,6 @@ use frontend\models\TowelForm;
use Yii; use Yii;
use common\models\Customer; use common\models\Customer;
use frontend\models\ReceptionForm; use frontend\models\ReceptionForm;
use frontend\models\CustomerSearch;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
@ -14,7 +13,6 @@ use common\models\Card;
use frontend\models\CustomerUpdate; use frontend\models\CustomerUpdate;
use frontend\models\CustomerCreate; use frontend\models\CustomerCreate;
use common\models\Image; use common\models\Image;
use yii\base\Exception;
use common\models\Log; use common\models\Log;
/** /**
@ -56,15 +54,13 @@ class CustomerController extends Controller
$model->number = $number; $model->number = $number;
$model->readCard(); $model->readCard();
$model->mkDoorLog(); // $model->mkDoorLog();
if ( $model->isFreeCard() ){ if ( $model->isFreeCard() ){
return $this->redirect([ 'create', 'number' => $model->card->number ]); return $this->redirect([ 'create', 'number' => $model->card->number ]);
}else if ( $model->isCardWithKey()){ }else if ( $model->isCardWithKey()){
return $this->redirect([ 'product/sale', 'number' => $model->card->number ]); return $this->redirect([ 'product/sale', 'number' => $model->card->number ]);
}else if ( $model->isCustomerWithTicket()){ }else if ( $model->isCustomerWithTicket()){
// return $this->redirect([ 'product/sale', 'number' => $model->card->number ]);
// return $this->redirect([ 'customer/reception', 'number' => $model->card->number ]);
}else if ( $model->isCardWithCustomer() ){ }else if ( $model->isCardWithCustomer() ){
return $this->redirect([ 'ticket/create', 'number' => $model->card->number ]); return $this->redirect([ 'ticket/create', 'number' => $model->card->number ]);
} }
@ -72,38 +68,6 @@ class CustomerController extends Controller
return $this->render('reception',['model' => $model]); return $this->render('reception',['model' => $model]);
} }
/**
* Lists all Customer models.
* @return mixed
*/
/*
public function actionIndex()
{
$searchModel = new CustomerSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
*/
/**
* Displays a single Customer model.
* @param null $number
* @return mixed
* @internal param int $id
*/
/*
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
*/
public function actionTowel($number = null) public function actionTowel($number = null)
{ {
@ -185,7 +149,9 @@ class CustomerController extends Controller
if ( $number != null ){ if ( $number != null ){
$card = Card::readCard($number); $card = Card::readCard($number);
if ( $card != null ){ if ( $card != null ){
$model = CustomerUpdate::find()->innerJoin(Card::tableName(), "customer.id_customer_card = card.id_card")->andWhere( [ 'customer.id_customer_card' => $card->id_card ])->one(); $model = CustomerUpdate::find()
->innerJoin(Card::tableName(), "customer.id_customer_card = card.id_card")
->andWhere( [ 'customer.id_customer_card' => $card->id_card ])->one();
} }
} }
@ -239,25 +205,6 @@ class CustomerController extends Controller
} }
} }
// s
/**
* Deletes an existing Customer model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
/*
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
*/
/** /**
* Finds the Customer model based on its primary key value. * Finds the Customer model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown. * If the model is not found, a 404 HTTP exception will be thrown.

View File

@ -103,11 +103,9 @@ class KeyController extends Controller
if ( isset( $model->keyCard ) ){ if ( isset( $model->keyCard ) ){
return $this->redirect(['product/sale', 'number' => $model->keyCard->number ]); return $this->redirect(['product/sale', 'number' => $model->keyCard->number ]);
} }
return $this->redirect(['customer/reception', 'number' => $number ]); return $this->redirect(['customer/reception', 'number' => $number ]);
} }

View File

@ -52,7 +52,37 @@ class ReceptionForm extends Model
'verifyCode' => 'Verification Code', 'verifyCode' => 'Verification Code',
]; ];
} }
public function preReadCard(){
$this->number = Helper::fixAsciiChars( $this->number );
$query = Card::find();
$query->leftJoin("card_key_assignment", 'card.id_card = card_key_assignment.id_card');
$query->leftJoin("key", 'key.id_key = card_key_assignment.id_key');
$query->andWhere(['or',
['and',[ 'in','card.number' , [$this->number]],"trim(coalesce(card.number, '')) <>'' " ],
['and', ['in','card.rfid_key' ,[ $this->number] ],"trim(coalesce(card.rfid_key, '')) <>'' "],
['and',[ 'in','key.number' , [$this->number]],"trim(coalesce(key.number, '')) <>'' " ],
['and', ['in','key.rfid_key' ,[ $this->number] ],"trim(coalesce(key.rfid_key, '')) <>'' "]
]);
$this->card = $query->one();
if ( $this->card == null ){
}
if ( $this->card != null ){
$this->customer = $this->card->customer;
$this->readValidTickets();
}
}
public function readCard(){ public function readCard(){
$this->number = Helper::fixAsciiChars( $this->number ); $this->number = Helper::fixAsciiChars( $this->number );
@ -71,10 +101,7 @@ class ReceptionForm extends Model
$this->card = $query->one(); $this->card = $query->one();
if ( $this->card == null ){
}
if ( $this->card != null ){ if ( $this->card != null ){
$this->customer = $this->card->customer; $this->customer = $this->card->customer;
$this->readValidTickets(); $this->readValidTickets();

View File

@ -1,2 +1,2 @@
* *
!.gitignore !.gitignore