add backend ticket stat basics
This commit is contained in:
@@ -6,12 +6,26 @@ use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Ticket;
|
||||
use common\components\Helper;
|
||||
use yii\db\ActiveRecord;
|
||||
|
||||
/**
|
||||
* TicketSearch represents the model behind the search form about `common\models\Ticket`.
|
||||
*/
|
||||
class TicketSearch extends Ticket
|
||||
{
|
||||
|
||||
public $timestampStart;
|
||||
public $timestampEnd;
|
||||
|
||||
public $users;
|
||||
public $accounts;
|
||||
public $ticketTypes;
|
||||
|
||||
public $valid_in_interval;
|
||||
public $created_in_interval;
|
||||
public $expire_in_interval;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -19,7 +33,10 @@ class TicketSearch extends Ticket
|
||||
{
|
||||
return [
|
||||
[['id_ticket', 'id_user', 'id_ticket_type', 'id_account', 'id_discount', 'max_usage_count', 'usage_count', 'status', 'price_brutto'], 'integer'],
|
||||
[['start', 'end', 'comment', 'created_at', 'updated_at'], 'safe'],
|
||||
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
|
||||
[['valid_in_interval','created_in_interval','expire_in_interval'],'boolean']
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@@ -43,35 +60,60 @@ class TicketSearch extends Ticket
|
||||
{
|
||||
$query = Ticket::find();
|
||||
|
||||
Helper::queryAccountConstraint($query, 'ticket.id_account');
|
||||
|
||||
$query->with('ticketType' );
|
||||
$query->with('user');
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
|
||||
$this->load($params);
|
||||
|
||||
|
||||
if (!$this->validate()) {
|
||||
// uncomment the following line if you do not want to return any records when validation fails
|
||||
// $query->where('0=1');
|
||||
return $dataProvider;
|
||||
$query->where('0=1');
|
||||
// return $dataProvider;
|
||||
}
|
||||
|
||||
$query->andFilterWhere([
|
||||
'id_ticket' => $this->id_ticket,
|
||||
'id_user' => $this->id_user,
|
||||
'id_ticket_type' => $this->id_ticket_type,
|
||||
'id_account' => $this->id_account,
|
||||
'id_discount' => $this->id_discount,
|
||||
'start' => $this->start,
|
||||
'end' => $this->end,
|
||||
'max_usage_count' => $this->max_usage_count,
|
||||
'usage_count' => $this->usage_count,
|
||||
'status' => $this->status,
|
||||
'price_brutto' => $this->price_brutto,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'comment', $this->comment]);
|
||||
|
||||
$all = (!($this->valid_in_interval) && !($this->expire_in_interval) && !($this->created_in_interval) )
|
||||
||
|
||||
($this->valid_in_interval == true && $this->expire_in_interval == true && $this->created_in_interval);
|
||||
|
||||
$dateConditions = [];
|
||||
$start = $this->timestampStart;
|
||||
$end = $this->timestampEnd;
|
||||
Yii::info('valid all: ' .$all);
|
||||
|
||||
if( $all || $this->created_in_interval ){
|
||||
$dateConditions[] = Helper::queryInIntervalRule('ticket.created_at', $start, $end);
|
||||
}
|
||||
|
||||
if ( $all || $this->valid_in_interval ){
|
||||
$dateConditions[] = Helper::queryValidRule('ticket.start', 'ticket.end', $start, $end);
|
||||
}
|
||||
|
||||
if ( $all || $this->expire_in_interval ){
|
||||
$dateConditions[] = Helper::queryExpireRule('ticket.start', 'ticket.end', $start, $end);
|
||||
}
|
||||
|
||||
if ( count($dateConditions) == 1 ){
|
||||
$query->andWhere($dateConditions[0]);
|
||||
}else if ( count($dateConditions) > 1 ){
|
||||
$cond = ['or'];
|
||||
foreach ($dateConditions as $c){
|
||||
$cond[] = $c;
|
||||
}
|
||||
$query->andWhere($cond);
|
||||
}
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user