コード例 #1
0
 public function search($params)
 {
     $query = Message::find()->innerJoinWith(['region' => function ($q) {
         /* @var \yii\db\ActiveQuery $q */
         $q->onCondition([Region::tableName() . '.id' => \Yii::$app->user->identity->currentRegion]);
     }], false)->innerJoinWith(['payments', 'client', 'category'])->orderBy([Message::tableName() . '.create_dt' => SORT_DESC])->distinct();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50, 'pageSizeParam' => 'inpage']]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     switch ($this->timeMark) {
         case self::TIME_ALL:
             $query->active();
             break;
         case self::TIME_CURRENT:
             $query->active()->andWhere([Payment::tableName() . '.num' => Payment::currentNumber()]);
             break;
         case self::TIME_FUTURE:
             $query->active()->andWhere(['>', Payment::tableName() . '.num', Payment::currentNumber()]);
             break;
         case self::TIME_PREVIOUS:
             $query->active()->andWhere(['<', Payment::tableName() . '.num', Payment::currentNumber()]);
             break;
         case self::TIME_REMOVED:
             $query->deleted();
             break;
     }
     if (!empty($this->subject)) {
         switch ($this->type) {
             case self::TYPE_PHONE:
                 $query->andWhere(['LIKE', Phone::tableName() . '.number', $this->subject])->orWhere(['LIKE', Message::tableName() . '.phone', $this->subject]);
                 break;
             case self::TYPE_CLIENT:
                 $query->andWhere(['LIKE', Client::tableName() . '.name', $this->subject]);
                 break;
             case self::TYPE_NUM:
                 $query->andWhere([Payment::tableName() . '.num' => $this->subject]);
                 break;
         }
     }
     return $dataProvider;
 }
コード例 #2
0
 public function actionEmptyads()
 {
     $msgs = Message::findBySql('
       select tm.*
       from ' . Message::tableName() . ' tm
       where (
         select count(id) as cnt
         from ' . Payment::tableName() . ' tp
         where tp.message_id = tm.id
       ) < 1
     ')->with('category')->all();
     return $this->render('emptyads', ['messages' => $msgs]);
 }
コード例 #3
0
 public function getData($validate = true)
 {
     if ($validate && !$this->validate()) {
         return false;
     }
     $statistic = new StatisticSet(['categorySets' => $this->endCategories]);
     $msgs = $this->getTargetMessages(false);
     $old = ArrayHelper::getColumn(Payment::find()->where(['num' => $this->number - 1, 'message_id' => ArrayHelper::getColumn($msgs, 'id')])->select(['id', 'message_id'])->asArray()->all(), 'message_id');
     $set = null;
     $isNew = false;
     $pm = null;
     foreach ($msgs as $data) {
         $set = $statistic->getCategorySet($data->category_id);
         if (!$set) {
             continue;
         }
         $paid = null;
         $isNew = !in_array($data->id, $old);
         $pm = $data->payments[0];
         $paid = $pm->amount != 0;
         //$set->incrementStat('paymentsCount');
         $set->incrementStat('Принято');
         switch ($pm->status) {
             case Payment::STATUS_PENDING:
                 if ($paid) {
                     $set->incrementStat('paymentsPaidWait');
                 }
                 break;
             case Payment::STATUS_FAIL:
                 if ($paid) {
                     $set->incrementStat('paymentsPaidFail');
                 }
                 break;
             case Payment::STATUS_SUCCESS:
                 //$set->incrementStat($paid ? 'paymentsPaidAccept' : 'paymentsFreeAccept');
                 $set->incrementStat('Оплачено');
                 break;
         }
         switch ($pm->price_type) {
             case Price::TYPE_FRAME:
                 //$set->incrementStat('priceInFrame');
                 $set->incrementStat('в рамке');
                 break;
             case Price::TYPE_BOLD:
                 //$set->incrementStat('priceHighlighted');
                 $set->incrementStat('жирный шрифт');
                 break;
             case Price::TYPE_BOLDED_FRAME:
                 //$set->incrementStat('priceHighlightedInFrame');
                 $set->incrementStat('выделенное в рамке');
                 break;
             case Price::TYPE_COLORED_BACKGROUND:
                 //$set->incrementStat('priceColoredBackground');
                 $set->incrementStat('на цветном фоне');
                 break;
             case Price::TYPE_DIAMOND:
                 //$set->incrementStat('priceMarkedDiamond');
                 $set->incrementStat('выделенное маркером');
                 break;
             case Price::TYPE_SHAPED_FRAME:
                 //$set->incrementStat('priceShapedFrame');
                 $set->incrementStat('фигурная рамка');
                 break;
             case Price::TYPE_STANDART:
                 //$set->incrementStat('priceStandart');
                 $set->incrementStat('обычное');
                 break;
         }
         if ($pm->site == 1) {
             $set->incrementStat('размещение на сайт');
         }
         $set->incrementStat('Топ ' . $pm->position);
         $set->incrementStat($paid ? 'paymentsPaidCount' : 'paymentsFreeCount');
         $set->incrementStat($isNew ? 'messageNew' : 'messageProlong');
     }
     return $statistic;
 }