add feature enable/disable reception door log
This commit is contained in:
parent
f27528d4cb
commit
1ff1d03a07
32
clean_runtime.sh
Executable file
32
clean_runtime.sh
Executable 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
|
||||
@ -376,6 +376,10 @@ class Helper {
|
||||
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(){
|
||||
return \Yii::$app->params['reception_transfer_list_only_today'];
|
||||
}
|
||||
|
||||
@ -54,6 +54,10 @@ return [
|
||||
]
|
||||
],
|
||||
'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
|
||||
|
||||
];
|
||||
|
||||
119
common/data/trigger/trigger.cutler.sql
Normal file
119
common/data/trigger/trigger.cutler.sql
Normal 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
|
||||
@ -174,6 +174,10 @@ class DoorLog extends \yii\db\ActiveRecord
|
||||
|
||||
public static function mkDoorLog($direction,$card,$customer = null,$key = null){
|
||||
|
||||
if ( !Helper::isKeyToggleDoorLogEnabled() ){
|
||||
return;
|
||||
}
|
||||
|
||||
$dlog = new DoorLog();
|
||||
$dlog->id_card = $card->id_card;
|
||||
|
||||
|
||||
@ -1,39 +1,21 @@
|
||||
<?php
|
||||
namespace console\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models;
|
||||
use /** @noinspection PhpUnusedAliasInspection */
|
||||
Yii;
|
||||
use yii\console\Controller;
|
||||
use common\models\Ticket;
|
||||
use common\models\DoorLog;
|
||||
use yii\helpers\VarDumper;
|
||||
use common\models\Customer;
|
||||
use common\models\Log;
|
||||
|
||||
class DoorlogController extends Controller{
|
||||
|
||||
|
||||
public $ticket;
|
||||
|
||||
|
||||
// public function options($actionID)
|
||||
// {
|
||||
// return ['ticket'];
|
||||
// }
|
||||
|
||||
// public function optionAliases()
|
||||
// {
|
||||
// return ['t' => 'ticket'];
|
||||
// }
|
||||
|
||||
|
||||
|
||||
public function actionIn($ticket)
|
||||
{
|
||||
|
||||
$log = new DoorLog();
|
||||
//5559 9719
|
||||
|
||||
$log->id_card = 9719;
|
||||
$log->id_customer = 5559;
|
||||
$log->id_ticket_current = $ticket;
|
||||
@ -44,9 +26,6 @@ class DoorlogController extends Controller{
|
||||
$log->id_account = null;
|
||||
$log->card_flag = 0;
|
||||
$log->flag_out= 0;
|
||||
|
||||
|
||||
|
||||
$log->save(false);
|
||||
}
|
||||
|
||||
@ -94,8 +73,8 @@ class DoorlogController extends Controller{
|
||||
$tickets = Ticket::find()->andWhere(['in','id_ticket_type' ,[54,55,56,57]])->all();
|
||||
|
||||
|
||||
|
||||
foreach ($tickets as $ticket){
|
||||
/** @var /common/models/Ticket $ticket */
|
||||
foreach ($tickets as $ticket){
|
||||
$cache = [];
|
||||
|
||||
$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 ){
|
||||
|
||||
foreach ($cache as $item){
|
||||
|
||||
echo $item['id'];
|
||||
echo "/";
|
||||
echo $item['count'];
|
||||
echo "\r\n";
|
||||
|
||||
$t = Ticket::findOne($ticket->id_ticket);
|
||||
|
||||
|
||||
$elotte = $t->usage_count;
|
||||
$t->usage_count = $t->usage_count + 1;
|
||||
$t->count_move_out = $t->usage_count;
|
||||
|
||||
$t->save(false);
|
||||
|
||||
$log = new Log();
|
||||
$log->type = 30;
|
||||
$log->id_ticket = $ticket->id_ticket;
|
||||
@ -153,18 +126,17 @@ class DoorlogController extends Controller{
|
||||
$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->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 );
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,3 +2,4 @@
|
||||
|
||||
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 doorlog/delete-old
|
||||
@ -6,7 +6,6 @@ use frontend\models\TowelForm;
|
||||
use Yii;
|
||||
use common\models\Customer;
|
||||
use frontend\models\ReceptionForm;
|
||||
use frontend\models\CustomerSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
@ -14,7 +13,6 @@ use common\models\Card;
|
||||
use frontend\models\CustomerUpdate;
|
||||
use frontend\models\CustomerCreate;
|
||||
use common\models\Image;
|
||||
use yii\base\Exception;
|
||||
use common\models\Log;
|
||||
|
||||
/**
|
||||
@ -56,15 +54,13 @@ class CustomerController extends Controller
|
||||
$model->number = $number;
|
||||
|
||||
$model->readCard();
|
||||
$model->mkDoorLog();
|
||||
// $model->mkDoorLog();
|
||||
|
||||
if ( $model->isFreeCard() ){
|
||||
return $this->redirect([ 'create', 'number' => $model->card->number ]);
|
||||
}else if ( $model->isCardWithKey()){
|
||||
return $this->redirect([ 'product/sale', 'number' => $model->card->number ]);
|
||||
}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() ){
|
||||
return $this->redirect([ 'ticket/create', 'number' => $model->card->number ]);
|
||||
}
|
||||
@ -73,38 +69,6 @@ class CustomerController extends Controller
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$model = new TowelForm();
|
||||
@ -185,7 +149,9 @@ class CustomerController extends Controller
|
||||
if ( $number != null ){
|
||||
$card = Card::readCard($number);
|
||||
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.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
|
||||
@ -104,8 +104,6 @@ class KeyController extends Controller
|
||||
return $this->redirect(['product/sale', 'number' => $model->keyCard->number ]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->redirect(['customer/reception', 'number' => $number ]);
|
||||
|
||||
}
|
||||
|
||||
@ -53,6 +53,36 @@ class ReceptionForm extends Model
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
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(){
|
||||
|
||||
$this->number = Helper::fixAsciiChars( $this->number );
|
||||
@ -71,9 +101,6 @@ class ReceptionForm extends Model
|
||||
|
||||
$this->card = $query->one();
|
||||
|
||||
if ( $this->card == null ){
|
||||
|
||||
}
|
||||
|
||||
if ( $this->card != null ){
|
||||
$this->customer = $this->card->customer;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user