add newsletter changes

This commit is contained in:
Roland Schneider 2016-05-26 08:50:10 +02:00
parent 07d5041126
commit 1fed67a650
16 changed files with 335 additions and 34 deletions

View File

@ -285,6 +285,10 @@ class Helper {
return \Yii::$app->params ['company'] == 'movar'; return \Yii::$app->params ['company'] == 'movar';
} }
public static function isCompanyGyor() {
return \Yii::$app->params ['company'] == 'gyor';
}
public static function isUserCartOn() { public static function isUserCartOn() {
return \Yii::$app->params ['user_cart_on'] == true; return \Yii::$app->params ['user_cart_on'] == true;
} }
@ -392,5 +396,14 @@ class Helper {
return $randomString; return $randomString;
} }
public static function getWebUrl(){
if ( self::isCompanyMovar()){
return "https://fitnessadmin.hu/fitness-web";
}else if ( self::isCompanyGyor()){
return "https://fitnessadmin.hu/cutler";
}else{
return "https://localhost/fitness-web";
}
}
} }

View File

@ -10,6 +10,8 @@ class WarnMailModel extends Model{
public $ticketTypeName; public $ticketTypeName;
public $ticketTypePriceBrutto; public $ticketTypePriceBrutto;
public $customerName; public $customerName;
public $idCustomer;
public $newsletterToken;

View File

@ -1,3 +1,8 @@
<?php
use yii\helpers\Html;
use yii\helpers\Url;
use common\components\Helper;
?>
<h1 style="font-size: 12px;">Kedves <?php echo $model->customerName?>!</h1> <h1 style="font-size: 12px;">Kedves <?php echo $model->customerName?>!</h1>
<p style="font-size: 12px;"> <p style="font-size: 12px;">
Tájékoztatjuk, hogy az alábbi bérlete <?php echo $model->day?> nap múlva lejár: Tájékoztatjuk, hogy az alábbi bérlete <?php echo $model->day?> nap múlva lejár:
@ -13,6 +18,10 @@
<p style="font-size: 12px;"> <p style="font-size: 12px;">
<?php echo $model->company ?> <?php echo $model->company ?>
</p> </p>
<p>
<?php $link = ( Helper::getWebUrl() ) . "/frontend/web/index.php?r=site/newsletter-subscribe&id=".$model->idCustomer."&token=".$model->newsletterToken; ?>
<?php //echo Html::a("Szeretnék hírlevelet kapni", $link )?>
</p>
<p> <p>
Ez egy automatikus e-mail üzenet, amelyre nem tud válaszolni. Ez egy automatikus e-mail üzenet, amelyre nem tud válaszolni.
</p> </p>

View File

@ -43,6 +43,9 @@ class Log extends BaseFitnessActiveRecord
public static $TYPE_PROCUREMENT_UPDATE = 80; public static $TYPE_PROCUREMENT_UPDATE = 80;
public static $TYPE_TICKET_COUNT_MOVE_OUT = 90; public static $TYPE_TICKET_COUNT_MOVE_OUT = 90;
public static $TYPE_WASTE = 100; public static $TYPE_WASTE = 100;
public static $TYPE_NEWSLETTER_SUBSCRIBE = 110;
public static $TYPE_NEWSLETTER_UNSUBSCRIBE = 120;
/** /**
* @inheritdoc * @inheritdoc
*/ */
@ -110,4 +113,15 @@ class Log extends BaseFitnessActiveRecord
$model->save(false); $model->save(false);
} }
/**
* create a log from the console app
* */
public static function logC( $config ){
$model = new Log($config);
$model->app = "Fitness rendszer";
$model->url = "console";
$model->id_user = 1;
$model->save(false);
}
} }

View File

@ -12,6 +12,7 @@ use common\components\WarnMailModel;
use common\components\Helper; use common\components\Helper;
use common\models\Newsletter; use common\models\Newsletter;
use common\models\Log; use common\models\Log;
use yii\helpers\Html;
class TicketController extends Controller { class TicketController extends Controller {
public function actionIndex() { public function actionIndex() {
@ -48,6 +49,8 @@ class TicketController extends Controller {
$query = new Query (); $query = new Query ();
$query->distinct ( true ); $query->distinct ( true );
$query->select ( [ $query->select ( [
'customer.id_customer as customer_id_customer',
'customer.newsletter_token as customer_newsletter_token',
'customer.email as customer_email', 'customer.email as customer_email',
'customer.name as customer_name', 'customer.name as customer_name',
'ticket_type.name as ticket_type_name', 'ticket_type.name as ticket_type_name',
@ -61,16 +64,20 @@ class TicketController extends Controller {
'ticket.status' => Ticket::STATUS_ACTIVE , 'ticket.status' => Ticket::STATUS_ACTIVE ,
'customer.warn_mail_ticket_expire_enabled' => Customer::$ENABLED 'customer.warn_mail_ticket_expire_enabled' => Customer::$ENABLED
] ); ] );
$query->andWhere ( [ $query->andWhere ( [
'ticket.end' => new Expression ( 'DATE_ADD(CURDATE(),INTERVAL ' . $dayCount . ' DAY)' ) 'ticket.end' => new Expression ( 'DATE_ADD(CURDATE(),INTERVAL ' . $dayCount . ' DAY)' )
] ); ] );
$query->andWhere([ $query->andWhere([
['<','ticket.usage_count' ,'ticket.max_usage_count'] '<','ticket.usage_count' , new Expression('ticket.max_usage_count')
]); ]);
$recepients = $query->all (); $recepients = $query->all ();
\Yii::info ( "Bérlet lejár figyelmeztetés küldése: " . $dayCount . " nap múlva " \Yii::info ( "Bérlet lejár figyelmeztetés küldése: " . $dayCount . " nap múlva "
. count ( $recepients ) . " vendég bérlete jár le." . count ( $recepients ) . " vendég bérlete jár le."
); );
@ -80,25 +87,30 @@ class TicketController extends Controller {
$recepientEmail = $recepient['customer_email']; $recepientEmail = $recepient['customer_email'];
$model = new WarnMailModel( if ( !empty($recepientEmail)){
[
'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 = new WarnMailModel(
'model' => $model, [
] ); 'day' => $dayCount,
'company' => Helper::getCompanyName(),
'ticketTypeName' => $recepient['ticket_type_name'],
'ticketTypePriceBrutto' => $recepient['ticket_type_price_brutto'],
'customerName' => $recepient['customer_name'],
'idCustomer' => $recepient['customer_id_customer'],
'newsletterToken' => $recepient['customer_newsletter_token'],
]
);
$message $message = \Yii::$app->mailer->compose ( 'warn_expire', [
->setFrom ( [ "noreply@fitnessadmin.hu" => Helper::getCompanyName() ] ) 'model' => $model,
->setTo ( $recepientEmail ) ] );
->setSubject ( "Értesítés - " . Helper::getCompanyName()." - Bérleted ".$dayCount." nap múlva lejár" )
->send (); $message
->setFrom ( [ "noreply@fitnessadmin.hu" => Helper::getCompanyName() ] )
->setTo ( $recepientEmail )
->setSubject ( "Értesítés - " . Helper::getCompanyName()." - Bérleted ".$dayCount." nap múlva lejár" )
->send ();
}
} }
} }
} }
@ -129,7 +141,10 @@ class TicketController extends Controller {
$q2 = new Query(); $q2 = new Query();
$q2->distinct(); $q2->distinct();
$q2->select(['customer.email as customer_email','customer.name as customer_name']); $q2->select(['customer.email as customer_email','customer.name as customer_name'
,'customer.id_customer as customer_id_customer'
,'customer.newsletter_token as customer_newsletter_token'
]);
$q2->from("customer"); $q2->from("customer");
$q2->innerJoin("ticket","ticket.id_card = customer.id_customer_card"); $q2->innerJoin("ticket","ticket.id_card = customer.id_customer_card");
// $q2->andWhere(['status' => Customer::STATUS_ACTIVE ]); // $q2->andWhere(['status' => Customer::STATUS_ACTIVE ]);
@ -160,6 +175,11 @@ class TicketController extends Controller {
$mailBody = $newsletter->body; $mailBody = $newsletter->body;
$mailBody = strtr($mailBody, $replacePairs ); $mailBody = strtr($mailBody, $replacePairs );
$mailBody .="<hr>";
$mailBody .="Leiratkozás hírlevélről:";
$mailBody .= Html::a("Leiratkozom",Helper::getWebUrl() ."/frontend/web/index.php?r=site/newsletter-unsubscribe&id=".$customer['customer_id_customer']."&token=".$customer['customer_newsletter_token']);
$mailSubject = $newsletter->subject; $mailSubject = $newsletter->subject;
$mailSubject = strtr($mailSubject, $replacePairs ); $mailSubject = strtr($mailSubject, $replacePairs );

View File

@ -114,7 +114,7 @@ class CustomerController extends Controller
$model->country = "Magyarország"; $model->country = "Magyarország";
$model->id_user = Yii::$app->user->id; $model->id_user = Yii::$app->user->id;
$model->warn_mail_ticket_expire_enabled = 1; $model->warn_mail_ticket_expire_enabled = 1;
$model->newsletter = 1; $model->newsletter = 0;
$receptionForm = new ReceptionForm(); $receptionForm = new ReceptionForm();
$receptionForm->number = $number; $receptionForm->number = $number;

View File

@ -17,6 +17,7 @@ use common\components\Helper;
use common\models\Log; use common\models\Log;
use common\models\Customer; use common\models\Customer;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use frontend\models\SubscribeForm;
/** /**
* Site controller * Site controller
@ -182,6 +183,8 @@ class SiteController extends Controller
public function actionNewsletterUnsubscribe($id,$token) public function actionNewsletterUnsubscribe($id,$token)
{ {
$this->layout = "main-nologin";
$customer = Customer::find() $customer = Customer::find()
->andWhere(['id_customer' => $id ]) ->andWhere(['id_customer' => $id ])
->andWhere(['newsletter_token' => $token]) ->andWhere(['newsletter_token' => $token])
@ -196,9 +199,60 @@ class SiteController extends Controller
$customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time(); $customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time();
$customer->save(); $customer->save();
Log::logC([
'id_customer' => $customer->id_customer,
'type' => Log::$TYPE_NEWSLETTER_UNSUBSCRIBE,
"message" => "Hírlevél feliratkozás: ". $customer->name
]);
return $this->render("unsubscribe"); return $this->render("unsubscribe");
} }
public function actionNewsletterSubscribe($id,$token)
{
$this->layout = "main-nologin";
$customer = Customer::find()
->andWhere(['id_customer' => $id ])
->andWhere(['newsletter_token' => $token])
->one();
if ( !isset($customer)){
throw new NotFoundHttpException("Az oldal nem található");
}
$model = new SubscribeForm([
'customer' => $customer
]);
if ($model->load(Yii::$app->request->post()) && $model->validate() ) {
$customer->newsletter = 1;
$customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time();
$customer->save();
Log::logC([
'id_customer' => $customer->id_customer,
'type' => Log::$TYPE_NEWSLETTER_SUBSCRIBE,
"message" => "Hírlevél feliratkozás: ". $customer->name ." - " . $customer->email
]);
return $this->redirect(["newsletter-subscribe-success"]);
}
return $this->render("subscribeform",['model' => $model]);
}
public function actionNewsletterSubscribeSuccess( )
{
$this->layout = "main-nologin";
return $this->render("subscribe");
}
/** /**
* Signs user up. * Signs user up.
* *

View File

@ -110,7 +110,7 @@ class CustomerCreate extends \common\models\Customer
[['photo_data'] ,'safe'], [['photo_data'] ,'safe'],
[['birth_place'] ,'safe'], [['birth_place'] ,'safe'],
[['mother_name'] ,'safe'], [['mother_name'] ,'safe'],
[['warn_mail_ticket_expire_enabled','newsletter'],'integer'] [['warn_mail_ticket_expire_enabled' ],'integer']
// [['email','phone'], 'validateEmailOrPhoneRequired' ], // [['email','phone'], 'validateEmailOrPhoneRequired' ],
]; ];
} }

View File

@ -118,7 +118,7 @@ class CustomerUpdate extends \common\models\Customer
[['photo_data'] ,'safe'], [['photo_data'] ,'safe'],
[['birth_place'] ,'safe'], [['birth_place'] ,'safe'],
[['mother_name'] ,'safe'], [['mother_name'] ,'safe'],
[['warn_mail_ticket_expire_enabled','newsletter'],'integer'] [['warn_mail_ticket_expire_enabled' ],'integer']
]; ];
} }

View File

@ -0,0 +1,53 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
/**
* ContactForm is the model behind the contact form.
*/
class SubscribeForm extends Model
{
public $idCustomer;
public $token;
public $subscribe;
public $customer;//input constructor param
/**
* @inheritdoc
*/
public function rules()
{
return [
// name, email, subject and body are required
[['subscribe', 'token', 'idCustomer' ], 'safe'],
[['subscribe' ], 'required' ],
[['subscribe' ], 'validateSubscribe' ,'skipOnEmpty' => false, 'skipOnError' => false ],
];
}
public function validateSubscribe($attr,$param){
if ( $this->subscribe != '1'){
echo "subscribe failed";
$this->addError( "subscribe", "Feliratkozáshoz be kell jelölnie ezt a mezőt!");
}
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'subscribe' => 'Szeretnék hírlevelet kapni',
];
}
}

View File

@ -148,11 +148,7 @@ use kartik\widgets\DatePicker;
<?= $form->field($model, 'warn_mail_ticket_expire_enabled')->checkbox([ 'label'=> "Kér értesítést bérlet lejáratáról"]) ?> <?= $form->field($model, 'warn_mail_ticket_expire_enabled')->checkbox([ 'label'=> "Kér értesítést bérlet lejáratáról"]) ?>
</div> </div>
</div> </div>
<div class='row'>
<div class='col-md-6'>
<?= $form->field($model, 'newsletter')->checkbox([ 'label'=> "Kér hírlevelet"]) ?>
</div>
</div>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/customer', 'Create') : Yii::t('common/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> <?= Html::submitButton($model->isNewRecord ? Yii::t('common/customer', 'Create') : Yii::t('common/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

View File

@ -144,11 +144,7 @@ use yii\base\Widget;
</div> </div>
</div> </div>
<div class='row'>
<div class='col-md-6'>
<?= $form->field($model, 'newsletter')->checkbox([ 'label'=> "Kér hírlevelet"]) ?>
</div>
</div>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/customer', 'Create') : Yii::t('common/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> <?= Html::submitButton($model->isNewRecord ? Yii::t('common/customer', 'Create') : Yii::t('common/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

View File

@ -0,0 +1,83 @@
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use frontend\assets\AppAsset;
use common\widgets\Alert;
use common\components\FrotnendMenuStructure;
use frontend\components\FrontendMenuStructure;
use kartik\widgets\AlertBlock;
use yii\helpers\Url;
use common\components\Helper;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<script>
var reception_card_url = '<?php echo Url::toRoute('customer/reception');?>';
</script>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => Helper::getCompanyName(),
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
NavBar::end();
?>
<div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
<footer class="footer" style="min-height: 60px; height: auto;">
<div class="container">
<div class="row">
<div class="col-md-12">
<p class="pull-left">&copy; <?= Yii::$app->name ?> <?= Yii::$app->params['version'] ?> Fitness - WebAdmin <?= date('Y') ?></p>
</div>
</div>
<div class="row">
<div class="col-md-12">
Ingyenesen használható alkalmazás.
Az oldalon szereplő adatok csak tájékoztató jellegűek.<br>
Az adatok helyességéért és igazságtartalmáért felelősséget nem vállalunk.<br>
Az oldal nem használható hivatalos adatforrásként.<br>
</div>
</div>
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>

View File

@ -0,0 +1,12 @@
<?php
use common\components\Helper;
?>
<p>
Ön sikeresen feliratkozott a hírlevelünkre!
</p>
<p>
Köszönettel:
</p>
<p>
<b> <?php echo Helper::getCompanyName() ?></b>
</p>

View File

@ -0,0 +1,40 @@
<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use common\components\Helper;
?>
<div class="key-form">
<p>
Kedves <?php echo $model->customer->name ?>!
</p>
<?php if ( empty($model->customer->email)) {?>
<p>
Ön nem adott meg e-mail címet. Ha szeretne feliratkozni a hírlevelünkre,
kérjük keressen bennünket személyesen valamilyik termünkben.
</p>
<p>
Köszönettel: <?php echo Helper::getCompanyName()?>
</p>
<?php }else{?>
<p>
Ha Ön is szeretné megkapni a <?php echo Helper::getCompanyName() ?> hírleveleit,
kérjük jelölje be az alább látható jelölőnégyzetett, és kattintson a feliratkozás gombra.
</p>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'subscribe')->checkbox([])?>
<div class="form-group">
<?= Html::submitButton( Yii::t('frontend/key', 'Feliratkozás'), ['class' => 'btn btn-primary'])?>
</div>
<?php ActiveForm::end(); ?>
<?php }?>
</div>

View File

@ -1 +1,10 @@
<?php
use common\components\Helper;
?>
Ön sikeresen leiratkozott a hírlevelünkről! Ön sikeresen leiratkozott a hírlevelünkről!
<p>
Köszönettel:
</p>
<p>
<b> <?php echo Helper::getCompanyName() ?></b>
</p>