add coronavirus activate/inactivate
This commit is contained in:
65
backend/models/CustomerActivateForm.php
Normal file
65
backend/models/CustomerActivateForm.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
|
||||
use common\models\Card;
|
||||
use common\models\Ticket;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
|
||||
class CustomerActivateForm extends Model{
|
||||
|
||||
public $inactiveCardCount;
|
||||
public $message ;
|
||||
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function loadActiveCardCount(){
|
||||
$this->inactiveCardCount = Card::find()->andWhere(
|
||||
['status' => Card::STATUS_INACTIVE]
|
||||
)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function activate(){
|
||||
if ( !$this->validate()){
|
||||
return false;
|
||||
}
|
||||
|
||||
$tx = \Yii::$app->db->beginTransaction();
|
||||
assert(isset($tx));
|
||||
try{
|
||||
Yii::$app->db->createCommand(Ticket::$SQL_UPDATE_TICKETS_END_DATE_ON_CARD_ACTIVATION )->execute();
|
||||
Card::updateAll(
|
||||
[
|
||||
'status' => Card::STATUS_ACTIVE,
|
||||
'end' => 'date_add( end, INTERVAL datediff(current_date, c.inactivated_at) DAY )'
|
||||
],
|
||||
[
|
||||
'status' => Card::STATUS_INACTIVE
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
Card::updateFlagStatus();
|
||||
$tx->commit();
|
||||
}catch (\Exception $exception){
|
||||
$tx->rollBack();
|
||||
throw $exception;
|
||||
}
|
||||
$this->message = $this->inactiveCardCount ." kártya aktiválva" ;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
56
backend/models/CustomerInactivateForm.php
Normal file
56
backend/models/CustomerInactivateForm.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
|
||||
use common\models\Card;
|
||||
use yii\base\Model;
|
||||
|
||||
class CustomerInactivateForm extends Model{
|
||||
|
||||
public $inactivateDate;
|
||||
|
||||
public $timestampInactivate;
|
||||
|
||||
public $activeCardCount;
|
||||
|
||||
public $message ;
|
||||
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[[ 'inactivateDate' ], 'required'],
|
||||
[[ 'inactivateDate', ], 'date' , 'timestampAttribute' => 'timestampInactivate' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function loadActiveCardCount(){
|
||||
$this->activeCardCount = Card::find()->andWhere(
|
||||
['status' => Card::STATUS_ACTIVE]
|
||||
)->count();
|
||||
}
|
||||
|
||||
public function inactivate(){
|
||||
if ( !$this->validate()){
|
||||
return false;
|
||||
}
|
||||
Card::updateAll(
|
||||
[
|
||||
'status' => Card::STATUS_INACTIVE,
|
||||
'inactivated_at' => $this->timestampInactivate
|
||||
],
|
||||
[
|
||||
'status' => Card::STATUS_ACTIVE
|
||||
]
|
||||
);
|
||||
Card::updateFlagStatus();
|
||||
\Yii::$app->session->setFlash ( 'success', 'Kártyák inaktiválva' );
|
||||
$this->message = $this->activeCardCount ." kártya inkatválva a köveztekző dátummal: " . $this->inactivateDate ;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user