add newsletter
This commit is contained in:
@@ -37,7 +37,7 @@ class DoorlogController extends Controller{
|
||||
$log->id_card = 9719;
|
||||
$log->id_customer = 5559;
|
||||
$log->id_ticket_current = $ticket;
|
||||
$log->direction = 7;
|
||||
$log->direction = 3;
|
||||
$log->id_key = 1;
|
||||
$log->type = 0;
|
||||
$log->source_app = DoorLog::$SOURCE_APP_FITNESS_ADMIN;
|
||||
@@ -58,7 +58,7 @@ class DoorlogController extends Controller{
|
||||
$log->id_card = 9719;
|
||||
$log->id_customer = 5559;
|
||||
$log->id_ticket_current = $ticket;
|
||||
$log->direction = 5;
|
||||
$log->direction = 1;
|
||||
$log->id_key = null;
|
||||
$log->type = 0;
|
||||
$log->source_app = DoorLog::$SOURCE_APP_FITNESS_ADMIN;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace console\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models;
|
||||
use yii\console\Controller;
|
||||
use common\models\Ticket;
|
||||
use common\models\Customer;
|
||||
@@ -11,6 +10,8 @@ use yii\db\Query;
|
||||
use yii\db\Expression;
|
||||
use common\components\WarnMailModel;
|
||||
use common\components\Helper;
|
||||
use common\models\Newsletter;
|
||||
use common\models\Log;
|
||||
|
||||
class TicketController extends Controller {
|
||||
public function actionIndex() {
|
||||
@@ -64,6 +65,10 @@ class TicketController extends Controller {
|
||||
'ticket.end' => new Expression ( 'DATE_ADD(CURDATE(),INTERVAL ' . $dayCount . ' DAY)' )
|
||||
] );
|
||||
|
||||
$query->andWhere([
|
||||
['<','ticket.usage_count' ,'ticket.max_usage_count']
|
||||
]);
|
||||
|
||||
$recepients = $query->all ();
|
||||
|
||||
\Yii::info ( "Bérlet lejár figyelmeztetés küldése: " . $dayCount . " nap múlva "
|
||||
@@ -97,4 +102,89 @@ class TicketController extends Controller {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function actionDaily(){
|
||||
set_time_limit(0);
|
||||
$this->actionWarnExpire();
|
||||
$this->actionNewsletter();
|
||||
}
|
||||
|
||||
public function actionNewsletter(){
|
||||
set_time_limit(0);
|
||||
$q1 = Newsletter::find();
|
||||
$q1->andWhere(['sent' => Newsletter::$SENT_NOT]);
|
||||
$q1->andWhere(['status' => Newsletter::$STATUS_ACTIVE]);
|
||||
|
||||
$newsletters = $q1->all();
|
||||
|
||||
if ( count($newsletters) == 0 ){
|
||||
\Yii::info("Nincs elküldendő hírlevél");
|
||||
}
|
||||
|
||||
$q2 = new Query();
|
||||
$q2->distinct();
|
||||
$q2->select(['customer.email as customer_email','customer.name as customer_name']);
|
||||
$q2->from("customer");
|
||||
$q2->innerJoin("ticket","ticket.id_card = customer.id_customer_card");
|
||||
// $q2->andWhere(['status' => Customer::STATUS_ACTIVE ]);
|
||||
$q2->andWhere(['newsletter' => Customer::$ENABLED ]);
|
||||
$q2->andWhere(['>=' ,'ticket.end',new Expression('DATE( DATE_ADD(NOW(),INTERVAL -3 MONTH) )')]);
|
||||
|
||||
|
||||
$customers = $q2->all();
|
||||
|
||||
\Yii::info("Hírlevél küldése " .count($customers) . " vendégnek!" );
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($newsletters as $newsletter ){
|
||||
$i = 0;
|
||||
foreach ($customers as $customer ){
|
||||
|
||||
try{
|
||||
$log = "Sending Newsletter";
|
||||
$log .="[id_newsletter=".$newsletter->id_newsletter ."]";
|
||||
$log .="[customer_email=" . $customer['customer_email'] . "]";
|
||||
\Yii::info($log);
|
||||
$message = \Yii::$app->mailer->compose ( );
|
||||
|
||||
$replacePairs = [
|
||||
'{vendeg_neve}' => $customer['customer_name']
|
||||
];
|
||||
|
||||
$mailBody = $newsletter->body;
|
||||
$mailBody = strtr($mailBody, $replacePairs );
|
||||
$mailSubject = $newsletter->subject;
|
||||
$mailSubject = strtr($mailSubject, $replacePairs );
|
||||
|
||||
$message
|
||||
->setFrom ( [ \Yii::$app->params['newsletter_from'] => Helper::getCompanyName() ])
|
||||
->setTo ( [
|
||||
$customer['customer_email']
|
||||
])
|
||||
->setHtmlBody( $mailBody )
|
||||
->setSubject ( $mailSubject )
|
||||
->send ();
|
||||
|
||||
}catch (\Exception $ex){
|
||||
\Yii::error("Nem sikerült hírlevelet kikülden: Hírlevél azonosító=" .$newsletter->id_newsletter. ";Vendég azonosító ". $customer['customer_name'] ) ;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
$newsletter->sent = Newsletter::$SENT_TRUE;
|
||||
$newsletter->sent_at = Helper::getDateTimeString();
|
||||
$newsletter->save(false);
|
||||
|
||||
// Log::log([
|
||||
// 'type' =>Log::$TYPE_LOGIN,
|
||||
// 'message' => $message
|
||||
// ]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Schema;
|
||||
use yii\db\Migration;
|
||||
|
||||
class m160516_114454_add__customer_newsletter extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->addColumn("customer", "newsletter", "int default 1");
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m160516_114454_add__customer_newsletter cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
45
console/migrations/m160516_122708_add_newsletter.php
Normal file
45
console/migrations/m160516_122708_add_newsletter.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Schema;
|
||||
use yii\db\Migration;
|
||||
|
||||
class m160516_122708_add_newsletter extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$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('{{%newsletter}}', [
|
||||
'id_newsletter' => $this->primaryKey(),
|
||||
'subject' => $this->string(),
|
||||
'body' => $this->text(),
|
||||
'status' => $this->integer(11),
|
||||
'sent' => $this->integer(),
|
||||
'sent_at' => $this->dateTime( ),
|
||||
'created_at' => $this->dateTime()->notNull(),
|
||||
'updated_at' => $this->dateTime()->notNull(),
|
||||
], $tableOptions);
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m160516_122708_add_newsletter cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user