diff --git a/common/components/Helper.php b/common/components/Helper.php index 0e2abe8..6179b56 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -285,6 +285,10 @@ class Helper { return \Yii::$app->params ['company'] == 'movar'; } + public static function isCompanyGyor() { + return \Yii::$app->params ['company'] == 'gyor'; + } + public static function isUserCartOn() { return \Yii::$app->params ['user_cart_on'] == true; } @@ -392,5 +396,14 @@ class Helper { 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"; + } + } } \ No newline at end of file diff --git a/common/components/WarnMailModel.php b/common/components/WarnMailModel.php index 419cb14..2931945 100644 --- a/common/components/WarnMailModel.php +++ b/common/components/WarnMailModel.php @@ -10,6 +10,8 @@ class WarnMailModel extends Model{ public $ticketTypeName; public $ticketTypePriceBrutto; public $customerName; + public $idCustomer; + public $newsletterToken; diff --git a/common/mail/warn_expire.php b/common/mail/warn_expire.php index bd5bced..5a76b11 100644 --- a/common/mail/warn_expire.php +++ b/common/mail/warn_expire.php @@ -1,3 +1,8 @@ +

Kedves customerName?>!

Tájékoztatjuk, hogy az alábbi bérlete day?> nap múlva lejár: @@ -13,6 +18,10 @@

company ?>

+

+ idCustomer."&token=".$model->newsletterToken; ?> + +

Ez egy automatikus e-mail üzenet, amelyre nem tud válaszolni.

diff --git a/common/models/Log.php b/common/models/Log.php index 1037e07..d8847f4 100644 --- a/common/models/Log.php +++ b/common/models/Log.php @@ -43,6 +43,9 @@ class Log extends BaseFitnessActiveRecord public static $TYPE_PROCUREMENT_UPDATE = 80; public static $TYPE_TICKET_COUNT_MOVE_OUT = 90; public static $TYPE_WASTE = 100; + public static $TYPE_NEWSLETTER_SUBSCRIBE = 110; + public static $TYPE_NEWSLETTER_UNSUBSCRIBE = 120; + /** * @inheritdoc */ @@ -110,4 +113,15 @@ class Log extends BaseFitnessActiveRecord $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); + } + } diff --git a/console/controllers/TicketController.php b/console/controllers/TicketController.php index 964a363..5e930b1 100644 --- a/console/controllers/TicketController.php +++ b/console/controllers/TicketController.php @@ -12,6 +12,7 @@ use common\components\WarnMailModel; use common\components\Helper; use common\models\Newsletter; use common\models\Log; +use yii\helpers\Html; class TicketController extends Controller { public function actionIndex() { @@ -48,6 +49,8 @@ class TicketController extends Controller { $query = new Query (); $query->distinct ( true ); $query->select ( [ + 'customer.id_customer as customer_id_customer', + 'customer.newsletter_token as customer_newsletter_token', 'customer.email as customer_email', 'customer.name as customer_name', 'ticket_type.name as ticket_type_name', @@ -61,16 +64,20 @@ class TicketController extends Controller { '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)' ) ] ); $query->andWhere([ - ['<','ticket.usage_count' ,'ticket.max_usage_count'] + '<','ticket.usage_count' , new Expression('ticket.max_usage_count') ]); $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." ); @@ -79,26 +86,31 @@ class TicketController extends Controller { foreach ( $recepients as $recepient ) { $recepientEmail = $recepient['customer_email']; + + if ( !empty($recepientEmail)){ - $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" => Helper::getCompanyName() ] ) - ->setTo ( $recepientEmail ) - ->setSubject ( "Értesítés - " . Helper::getCompanyName()." - Bérleted ".$dayCount." nap múlva lejár" ) - ->send (); + $model = new WarnMailModel( + [ + '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 = \Yii::$app->mailer->compose ( 'warn_expire', [ + 'model' => $model, + ] ); + + $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->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->innerJoin("ticket","ticket.id_card = customer.id_customer_card"); // $q2->andWhere(['status' => Customer::STATUS_ACTIVE ]); @@ -160,6 +175,11 @@ class TicketController extends Controller { $mailBody = $newsletter->body; $mailBody = strtr($mailBody, $replacePairs ); + + $mailBody .="
"; + $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 = strtr($mailSubject, $replacePairs ); diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index 51e1189..15e384e 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -114,7 +114,7 @@ class CustomerController extends Controller $model->country = "Magyarország"; $model->id_user = Yii::$app->user->id; $model->warn_mail_ticket_expire_enabled = 1; - $model->newsletter = 1; + $model->newsletter = 0; $receptionForm = new ReceptionForm(); $receptionForm->number = $number; diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 06f01ba..28291c7 100644 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -17,6 +17,7 @@ use common\components\Helper; use common\models\Log; use common\models\Customer; use yii\web\NotFoundHttpException; +use frontend\models\SubscribeForm; /** * Site controller @@ -181,6 +182,8 @@ class SiteController extends Controller public function actionNewsletterUnsubscribe($id,$token) { + + $this->layout = "main-nologin"; $customer = Customer::find() ->andWhere(['id_customer' => $id ]) @@ -196,8 +199,59 @@ class SiteController extends Controller $customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time(); $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"); } + + 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. diff --git a/frontend/models/CustomerCreate.php b/frontend/models/CustomerCreate.php index c480424..f35e533 100644 --- a/frontend/models/CustomerCreate.php +++ b/frontend/models/CustomerCreate.php @@ -110,7 +110,7 @@ class CustomerCreate extends \common\models\Customer [['photo_data'] ,'safe'], [['birth_place'] ,'safe'], [['mother_name'] ,'safe'], - [['warn_mail_ticket_expire_enabled','newsletter'],'integer'] + [['warn_mail_ticket_expire_enabled' ],'integer'] // [['email','phone'], 'validateEmailOrPhoneRequired' ], ]; } diff --git a/frontend/models/CustomerUpdate.php b/frontend/models/CustomerUpdate.php index 7dbabef..a638f80 100644 --- a/frontend/models/CustomerUpdate.php +++ b/frontend/models/CustomerUpdate.php @@ -118,7 +118,7 @@ class CustomerUpdate extends \common\models\Customer [['photo_data'] ,'safe'], [['birth_place'] ,'safe'], [['mother_name'] ,'safe'], - [['warn_mail_ticket_expire_enabled','newsletter'],'integer'] + [['warn_mail_ticket_expire_enabled' ],'integer'] ]; } diff --git a/frontend/models/SubscribeForm.php b/frontend/models/SubscribeForm.php new file mode 100644 index 0000000..748d6f1 --- /dev/null +++ b/frontend/models/SubscribeForm.php @@ -0,0 +1,53 @@ + 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', + ]; + } + + + + +} diff --git a/frontend/views/customer/_form_create.php b/frontend/views/customer/_form_create.php index ef4c02e..afd82c3 100644 --- a/frontend/views/customer/_form_create.php +++ b/frontend/views/customer/_form_create.php @@ -148,11 +148,7 @@ use kartik\widgets\DatePicker; field($model, 'warn_mail_ticket_expire_enabled')->checkbox([ 'label'=> "Kér értesítést bérlet lejáratáról"]) ?> -
-
- field($model, 'newsletter')->checkbox([ 'label'=> "Kér hírlevelet"]) ?> -
-
+
isNewRecord ? Yii::t('common/customer', 'Create') : Yii::t('common/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> diff --git a/frontend/views/customer/_form_update.php b/frontend/views/customer/_form_update.php index e79e08c..4374959 100644 --- a/frontend/views/customer/_form_update.php +++ b/frontend/views/customer/_form_update.php @@ -144,11 +144,7 @@ use yii\base\Widget;
-
-
- field($model, 'newsletter')->checkbox([ 'label'=> "Kér hírlevelet"]) ?> -
-
+
isNewRecord ? Yii::t('common/customer', 'Create') : Yii::t('common/customer', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> diff --git a/frontend/views/layouts/main-nologin.php b/frontend/views/layouts/main-nologin.php new file mode 100644 index 0000000..a91a714 --- /dev/null +++ b/frontend/views/layouts/main-nologin.php @@ -0,0 +1,83 @@ + +beginPage() ?> + + + + + + + <?= Html::encode($this->title) ?> + + head() ?> + + +beginBody() ?> + +
+ Helper::getCompanyName(), + 'brandUrl' => Yii::$app->homeUrl, + 'options' => [ + 'class' => 'navbar-inverse navbar-fixed-top', + ], + ]); + + NavBar::end(); + ?> + +
+ isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], + ]) ?> + + +
+
+ + + +endBody() ?> + + +endPage() ?> diff --git a/frontend/views/site/subscribe.php b/frontend/views/site/subscribe.php new file mode 100644 index 0000000..4980b98 --- /dev/null +++ b/frontend/views/site/subscribe.php @@ -0,0 +1,12 @@ + +

+Ön sikeresen feliratkozott a hírlevelünkre! +

+

+Köszönettel: +

+

+ +

diff --git a/frontend/views/site/subscribeform.php b/frontend/views/site/subscribeform.php new file mode 100644 index 0000000..99190ee --- /dev/null +++ b/frontend/views/site/subscribeform.php @@ -0,0 +1,40 @@ + +
+

+Kedves customer->name ?>! +

+customer->email)) {?> +

+ Ö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. +

+

+ Köszönettel: +

+ + +

+ Ha Ön is szeretné megkapni a hírleveleit, + kérjük jelölje be az alább látható jelölőnégyzetett, és kattintson a feliratkozás gombra. + +

+ + + + + field($model, 'subscribe')->checkbox([])?> + + + +
+ 'btn btn-primary'])?> +
+ + + +
+ diff --git a/frontend/views/site/unsubscribe.php b/frontend/views/site/unsubscribe.php index ffb15f7..48ff169 100644 --- a/frontend/views/site/unsubscribe.php +++ b/frontend/views/site/unsubscribe.php @@ -1 +1,10 @@ + Ön sikeresen leiratkozott a hírlevelünkről! +

+Köszönettel: +

+

+ +

\ No newline at end of file