add automatic warn email about ticket expiration
This commit is contained in:
@@ -1,21 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace console\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models;
|
||||
use yii\console\Controller;
|
||||
use common\models\Ticket;
|
||||
use common\models\Customer;
|
||||
use yii\db\Query;
|
||||
use yii\db\Expression;
|
||||
use common\components\WarnMailModel;
|
||||
use common\components\Helper;
|
||||
|
||||
class TicketController extends Controller{
|
||||
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
class TicketController extends Controller {
|
||||
public function actionIndex() {
|
||||
$connection = \Yii::$app->db;
|
||||
$command = $connection->createCommand( Ticket::$SQL_UPDATE );
|
||||
$result = $command->execute();
|
||||
\Yii::info("Tickets updated: " . $result );
|
||||
echo "Tickets updated: " . $result ;
|
||||
$command = $connection->createCommand ( Ticket::$SQL_UPDATE );
|
||||
$result = $command->execute ();
|
||||
\Yii::info ( "Tickets updated: " . $result );
|
||||
echo "Tickets updated: " . $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatikus email figyelmeztetés küldése vendégeknek, akiknek a beállított nap(ok) múlva
|
||||
* lejár a bérlete
|
||||
;*
|
||||
*/
|
||||
public function actionWarnExpire() {
|
||||
\Yii::info ( "Bérlet lejár figyelmeztetés küldése" );
|
||||
$warnEnabled = \Yii::$app->params ['warn_ticket_expire_enabled'];
|
||||
$warnDays = \Yii::$app->params ['warn_ticket_expire_days'];
|
||||
|
||||
if (! $warnEnabled) {
|
||||
\Yii::info ( "Bérlet lejár figyelmeztetés küldése kikapcsolva" );
|
||||
return;
|
||||
}
|
||||
|
||||
if (! isset ( $warnDays ) || count ( $warnDays ) == 0) {
|
||||
\Yii::info ( "Bérlet lejár figyelmeztetés küldése: nincsenek napok beállítva" );
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $warnDays as $warnDayConfig ) {
|
||||
$dayCount = $warnDayConfig ['day'];
|
||||
|
||||
$query = new Query ();
|
||||
$query->distinct ( true );
|
||||
$query->select ( [
|
||||
'customer.email as customer_email',
|
||||
'customer.name as customer_name',
|
||||
'ticket_type.name as ticket_type_name',
|
||||
'ticket_type.price_brutto as ticket_type_price_brutto'
|
||||
]
|
||||
);
|
||||
$query->from ( 'customer' );
|
||||
$query->innerJoin ( "ticket", "customer.id_customer_card = ticket.id_card " );
|
||||
$query->innerJoin ( "ticket_type", "ticket.id_ticket_type = ticket_type.id_ticket_type " );
|
||||
$query->andWhere ( [
|
||||
'ticket.status' => Ticket::STATUS_ACTIVE ,
|
||||
'customer.warn_mail_ticket_expire_enabled' => Customer::$ENABLED
|
||||
] );
|
||||
$query->andWhere ( [
|
||||
'ticket.end' => new Expression ( 'DATE_ADD(CURDATE(),INTERVAL ' . $dayCount . ' DAY)' )
|
||||
] );
|
||||
|
||||
$recepients = $query->all ();
|
||||
|
||||
\Yii::info ( "Bérlet lejár figyelmeztetés küldése: " . $dayCount . " nap múlva "
|
||||
. count ( $recepients ) . " vendég bérlete jár le."
|
||||
);
|
||||
|
||||
|
||||
foreach ( $recepients as $recepient ) {
|
||||
|
||||
$recepientEmail = $recepient['customer_email'];
|
||||
|
||||
$model = new WarnMailModel(
|
||||
[
|
||||
'day' => $dayCount,
|
||||
'company' => Helper::getCompanyName(),
|
||||
'ticketTypeName' => $recepient['ticket_type_name'],
|
||||
'ticketTypePriceBrutto' => $recepient['ticket_type_price_brutto'],
|
||||
'customerName' => $recepient['customer_name']
|
||||
]
|
||||
);
|
||||
|
||||
$message = \Yii::$app->mailer->compose ( 'warn_expire', [
|
||||
'model' => $model,
|
||||
] );
|
||||
|
||||
$message
|
||||
->setFrom ( "noreply@fitnessadmin.hu" )
|
||||
->setTo ( $recepientEmail )
|
||||
->setSubject ( "Értesítés - " . Helper::getCompanyName()." - Bérleted ".$dayCount." nap múlva lejár" )
|
||||
->send ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user