This commit is contained in:
Roland Schneider 2016-06-01 18:28:45 +02:00
commit dc993021c7
15 changed files with 285 additions and 77 deletions

View File

@ -60,7 +60,7 @@ $this->params['breadcrumbs'][] = $this->title;
<div style='border: 1px solid #000; padding: 6px; background-color: #fff;'>
<?php echo $model->body ?>
</div>
<?php /*?>
<h3>
Teszt üzenet küldése
</h3>
@ -68,10 +68,10 @@ Teszt üzenet küldése
A küldés gombra kattintva úgy küldünk ki egy darab e-mailt,
<ul>
<li>
mintha a megadott vendég lenne a fogadó
mintha a megadott előfizető lenne a fogadó
</li>
<li>
viszont a vendég e-mail címe helyett a megadott e-mail címre küldjük
viszont az előfizető e-mail címe helyett a megadott e-mail címre küldjük
</li>
</ul>
</p>
@ -92,4 +92,5 @@ Teszt üzenet küldése
<?php ActiveForm::end(); ?>
</div>
</div>
<?php */ ?>

View File

@ -1,3 +1,5 @@
-0.0.75
- add unpaid tickets display
-0.0.74
- add newsletter changes
-0.0.73

View File

@ -397,12 +397,16 @@ class Helper {
}
public static function getWebUrl(){
if ( self::isCompanyMovar()){
return "https://fitnessadmin.hu/fitness-web";
}else if ( self::isCompanyGyor()){
return "https://fitnessadmin.hu/cutler";
if ( \Yii::$app->params['development'] == true ){
return "http://localhost/fitness-web";
}else{
return "https://localhost/fitness-web";
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

@ -1,10 +1,11 @@
<?php
return [
'development' => false,
'adminEmail' => 'rocho02@gmail.com',
'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600,
'version' => 'v0.0.74',
'version' => 'v0.0.75',
'company' => 'movar',//gyor
'company_name' => "Freimann Kft.",
'product_visiblity' => 'account',// on reception which products to display. account or global
@ -47,6 +48,7 @@ return [
'day' => 5,
]
],
'newsletter_from' => 'noreply@fitnessadmin.hu'
'newsletter_from' => 'noreply@fitnessadmin.hu',
'newsletter_enabled' => false
];

View File

@ -45,6 +45,10 @@ class Log extends BaseFitnessActiveRecord
public static $TYPE_WASTE = 100;
public static $TYPE_NEWSLETTER_SUBSCRIBE = 110;
public static $TYPE_NEWSLETTER_UNSUBSCRIBE = 120;
public static $TYPE_NEWSLETTER_SENT = 130;
public static $TYPE_TICKET_EXPIRE_SENT = 140;
public static $TYPE_NEWSLETTER_SEND_START = 150;
public static $TYPE_NEWSLETTER_SEND_END = 160;
/**
* @inheritdoc

View File

@ -0,0 +1,85 @@
<?php
namespace common\models;
use Yii;
use yii\helpers\ArrayHelper;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "subscriber".
*
* @property integer $id_subscriber
* @property string $name
* @property string $email
* @property integer $status
* @property string $token
* @property string $created_at
* @property string $updated_at
*/
class Subscriber extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'subscriber';
}
public function behaviors()
{
return ArrayHelper::merge( [
[
'class' => TimestampBehavior::className(),
'value' => function(){ return date('Y-m-d H:i:s' ); }
],
], parent::behaviors());
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['email'], 'email'],
[['status','email','name'], 'required'],
[['status'], 'integer'],
[['name'], 'string', 'max' => 255],
['status' ,'validateSubscribe' ,'skipOnEmpty' => false, 'skipOnError' => false ,'on' => 'subscribe']
];
}
public function validateSubscribe($attr,$param){
if ( $this->status != '1'){
$this->addError( "status", "Feliratkozáshoz be kell jelölnie ezt a mezőt!");
}
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_subscriber' => Yii::t('common/subscriber', 'Id Subscriber'),
'name' => Yii::t('common/subscriber', 'Név'),
'email' => Yii::t('common/subscriber', 'Email'),
'status' => Yii::t('common/subscriber', 'Szeretnék hírlevelet kapni'),
'token' => Yii::t('common/subscriber', 'Token'),
'created_at' => Yii::t('common/subscriber', 'Created At'),
'updated_at' => Yii::t('common/subscriber', 'Updated At'),
];
}
public function beforeSave($insert){
if ( parent::beforeSave($insert)){
$this->token = Yii::$app->security->generateRandomString() . '_' . time();
}
return true;
}
}

View File

@ -124,6 +124,11 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
public function getCard(){
return $this->hasOne( Card::className(), ["id_card" =>"id_card" ] );
}
public function getContract(){
return $this->hasOne( Contract::className(), ["id_contract" =>"id_contract" ] );
}
public function getCardNumber(){
$result = "";
$card = $this->card;
@ -217,6 +222,31 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
return $result;
}
/**
* @param common\models\Card $card the card to which we are looking for
* */
public static function readUnpaid($card){
if ( $card == null )
return [];
$query = Ticket::find();
$query->innerJoin("transfer", "transfer.id_object = ticket.id_ticket ");
$today = date('Y-m-d');
$query->andWhere(['ticket.id_card' => $card->id_card]);
$query->andWhere( 'ticket.start <= :today' ,[ 'today' => $today] );
$query->andWhere( 'ticket.end >= :today' ,[ 'today' => $today] );
$query->andWhere( ['in' ,'ticket.status' ,[ Ticket::STATUS_INACTIVE, Ticket::STATUS_ACTIVE] ]);
$query->andWhere( ["transfer.type" => Transfer::TYPE_TICKET] );
$query->andWhere( [ "transfer.status" => Transfer::STATUS_NOT_PAID ]);
$query->orderBy([ "ticket.created_at" =>SORT_DESC] );
$result = $query->all();
return $result;
}
public static function mkStatisticQuery($start,$end,$id_card = null){

View File

@ -13,6 +13,7 @@ use common\components\Helper;
use common\models\Newsletter;
use common\models\Log;
use yii\helpers\Html;
use common\models\Subscriber;
class TicketController extends Controller {
public function actionIndex() {
@ -110,6 +111,12 @@ class TicketController extends Controller {
->setTo ( $recepientEmail )
->setSubject ( "Értesítés - " . Helper::getCompanyName()." - Bérleted ".$dayCount." nap múlva lejár" )
->send ();
Log::logC([
'type' => Log::$TYPE_TICKET_EXPIRE_SENT,
'message' => "Bérlet lejár üzenet: " . $recepient['customer_name']." [id_customer=". $recepient['customer_id_customer'] ."]",
'id_customer' => $recepient['customer_id_customer']
]);
}
}
}
@ -129,6 +136,12 @@ class TicketController extends Controller {
public function actionNewsletter(){
set_time_limit(0);
if ( \Yii::$app->params['newsletter_enabled'] != true ){
return;
}
$q1 = Newsletter::find();
$q1->andWhere(['sent' => Newsletter::$SENT_NOT]);
$q1->andWhere(['status' => Newsletter::$STATUS_ACTIVE]);
@ -139,38 +152,32 @@ class TicketController extends Controller {
\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'
,'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 ]);
$q2->andWhere(['newsletter' => Customer::$ENABLED ]);
$q2->andWhere(['>=' ,'ticket.end',new Expression('DATE( DATE_ADD(NOW(),INTERVAL -3 MONTH) )')]);
$subscribers = Subscriber::find()->andWhere(['status' => 1])->all();
$customers = $q2->all();
\Yii::info("Hírlevél küldése " .count($customers) . " vendégnek!" );
\Yii::info("Hírlevél küldése " .count($subscribers) . " előfizetőnek!" );
$i = 0;
foreach ($newsletters as $newsletter ){
$i = 0;
foreach ($customers as $customer ){
Log::logC([
'type' => Log::$TYPE_NEWSLETTER_SEND_START,
'message' => "Hírlevél küldés indítása[id_newsletter=" . $newsletter->id_newsletter ."]"
]);
foreach ($subscribers as $subscriber ){
try{
$log = "Sending Newsletter";
$log .="[id_newsletter=".$newsletter->id_newsletter ."]";
$log .="[customer_email=" . $customer['customer_email'] . "]";
$log .="[subscriber_email=" . $subscriber->email . "]";
$log .="[subscriber_id=" . $subscriber->id_subscriber . "]";
\Yii::info($log);
$message = \Yii::$app->mailer->compose ( );
$replacePairs = [
'{vendeg_neve}' => $customer['customer_name']
'{vendeg_neve}' => $subscriber->name
];
$mailBody = $newsletter->body;
@ -178,7 +185,7 @@ class TicketController extends Controller {
$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']);
$mailBody .= Html::a("Leiratkozom",Helper::getWebUrl() ."/frontend/web/index.php?r=site/newsletter-unsubscribe&id=".$subscriber->id_subscriber."&token=". $subscriber->token );
$mailSubject = $newsletter->subject;
$mailSubject = strtr($mailSubject, $replacePairs );
@ -186,14 +193,19 @@ class TicketController extends Controller {
$message
->setFrom ( [ \Yii::$app->params['newsletter_from'] => Helper::getCompanyName() ])
->setTo ( [
$customer['customer_email']
$subscriber->email => $subscriber->name
])
->setHtmlBody( $mailBody )
->setSubject ( $mailSubject )
->send ();
Log::logC([
'type' => Log::$TYPE_NEWSLETTER_SENT,
'message' => "Hírlevél küldés[id_newsletter=" . $newsletter->id_newsletter ."][id_subscriber=" . $subscriber->id_subscriber ."]"
]);
}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'] ) ;
\Yii::error("Nem sikerült hírlevelet kikülden: Hírlevél azonosító=" .$newsletter->id_newsletter. ";Előfizető azonosító ". $subscriber->id_subscriber ) ;
}
$i++;
@ -202,6 +214,11 @@ class TicketController extends Controller {
$newsletter->sent_at = Helper::getDateTimeString();
$newsletter->save(false);
Log::logC([
'type' => Log::$TYPE_NEWSLETTER_SEND_END,
'message' => "Hírlevél küldés befejezése[id_newsletter=" . $newsletter->id_newsletter ."]"
]);
// Log::log([
// 'type' =>Log::$TYPE_LOGIN,
// 'message' => $message

View File

@ -0,0 +1,43 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160527_054414_add_table__subscriber 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('{{%subscriber}}', [
'id_subscriber' => $this->primaryKey(),
'name' => $this->string(),
'email' => $this->text(),
'status' => $this->integer(11),
'token' => $this->string(),
'created_at' => $this->dateTime()->notNull(),
'updated_at' => $this->dateTime()->notNull(),
], $tableOptions);
}
public function down()
{
return true;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -18,6 +18,7 @@ use common\models\Log;
use common\models\Customer;
use yii\web\NotFoundHttpException;
use frontend\models\SubscribeForm;
use common\models\Subscriber;
/**
* Site controller
@ -100,7 +101,9 @@ class SiteController extends Controller
$message = "";
$user = User::findOne(\Yii::$app->user->id);
if ( isset($geoip)){
$message = "Bejelentkezés: " .$user->username. " Ip cím:". $geoip->ip . " Város: " . $geoip->city;
$ip = isset( $geoip->ip ) ? $geoip->ip : "";
$city = isset( $geoip->city ) ? $geoip->city : "";
$message = "Bejelentkezés: " .$user->username. " Ip cím:". $ip . " Város: " . $city;
}
Log::log([
@ -185,9 +188,9 @@ class SiteController extends Controller
$this->layout = "main-nologin";
$customer = Customer::find()
->andWhere(['id_customer' => $id ])
->andWhere(['newsletter_token' => $token])
$customer = Subscriber::find()
->andWhere(['id_subscriber' => $id ])
->andWhere(['token' => $token])
->one();
@ -195,51 +198,32 @@ class SiteController extends Controller
throw new NotFoundHttpException("Az oldal nem található");
}
$customer->newsletter = 0;
$customer->newsletter_token = Yii::$app->security->generateRandomString() . '_' . time();
$customer->status = 0;
$customer->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
"message" => "Hírlevél leiratkozás: ". $customer->name
]);
return $this->render("unsubscribe");
return $this->render("unsubscribe",['subscriber' => $customer]);
}
public function actionNewsletterSubscribe($id,$token)
public function actionNewsletterSubscribe()
{
$this->layout = "main-nologin";
$model = new Subscriber(['scenario' => 'subscribe']);
$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() ) {
if ($model->load(Yii::$app->request->post()) && $model->save() ) {
$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
"message" => "Hírlevél feliratkozás: ". $model->name ." - " . $model->email
]);
return $this->redirect(["newsletter-subscribe-success"]);

View File

@ -26,6 +26,7 @@ class ReceptionForm extends Model
public $card;
public $customer;
public $tickets;
public $unpaidTickets;
public $defaultAccount;
public $cardSearchModel;
public $lastCassaState;
@ -77,6 +78,7 @@ class ReceptionForm extends Model
if ( $this->card != null ){
$this->customer = $this->card->customer;
$this->readValidTickets();
$this->readUnpaidTicket();
$this->readAssignedKeys();
$this->readContract();
}
@ -183,6 +185,10 @@ class ReceptionForm extends Model
$this->tickets = Ticket::readActive($this->card);
}
public function readUnpaidTicket(){
$this->unpaidTickets = Ticket::readUnpaid($this->card);
}
/**
* @return true , if card found without customer
* */

View File

@ -105,4 +105,35 @@ if ( isset($model->contract)){
}
}
if ( isset( $model->unpaidTickets ) ) {
if ( count($model->unpaidTickets) > 0){
echo Html::beginTag("div",['class'=>"alert alert-warning", "role"=>"alert"]);
echo Html::beginTag("strong",[ ]);
echo "Fizetetlen bérletek";
echo Html::endTag("strong");
echo "<ul>";
$formatter = \Yii::$app->formatter;
foreach ($model->unpaidTickets as $t ){
echo Html::beginTag("li",[ ]);
$c = $t->contract;
if (isset($c)){
echo "<b>Szerződéses</b>";
}
echo $t->getTicketTypeName();
echo ": ";
echo $formatter->asDate($t->start);
echo " - " ;
echo $formatter->asDate($t->end);
echo " (";
echo $t->price_brutto;
echo " Ft)";
echo Html::endTag("li");
}
echo "</ul>";
echo Html::endTag("div");
}
}
?>

View File

@ -4,18 +4,6 @@ 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,
@ -26,7 +14,9 @@ Kedves <?php echo $model->customer->name ?>!
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'subscribe')->checkbox([])?>
<?= $form->field($model, 'email')->textInput([])?>
<?= $form->field($model, 'name')->textInput([])?>
<?= $form->field($model, 'status')->checkbox([ 'label' => false ])->label("Szeretnék hírlevelet kapni")?>
@ -35,6 +25,5 @@ Kedves <?php echo $model->customer->name ?>!
</div>
<?php ActiveForm::end(); ?>
<?php }?>
</div>

View File

@ -1,7 +1,13 @@
<?php
use common\components\Helper;
?>
<p>
Kedves <?php echo $subscriber->name ?>!
</p>
<p>
Ön sikeresen leiratkozott a hírlevelünkről!
A leiratkozott e-mail cím : <?php echo $subscriber->email?>
</p>
<p>
Köszönettel:
</p>

4
update_botond.sh Normal file
View File

@ -0,0 +1,4 @@
git pull origin master
composer install
php yii migrate
yii migrate --interactive=0