Exemplo n.º 1
0
 /**
  * Актвирует услугу
  *
  * @return array
  * [
  *   'stock'      => \app\models\Stock
  *   'dateFinish' => string - дата до которого оплачена услуга в формате 'yyyy-mm-dd'
  * ]
  */
 public function activate()
 {
     $stock_id = $this->getField('stock_id');
     $stock = Stock::find($stock_id);
     $monthCounter = $this->getField('month');
     $dateFinish = \app\models\UserStock::add(\Yii::$app->user->getId(), $stock_id, $monthCounter, $this->getField('datetime'));
     $dateFinishStr = Yii::$app->formatter->asDate($dateFinish);
     WalletHistory::insert("Услуга включена, акция: {$stock->getName()}, месяцев: {$monthCounter}, до: {$dateFinishStr}");
     self::delete();
     return ['stock' => $stock, 'dateFinish' => $dateFinish];
 }
Exemplo n.º 2
0
 public function actionStock_list()
 {
     $items = Stock::query()->orderBy(['name' => SORT_ASC])->all();
     $dateFinishList = UserStock::query(['user_id' => \Yii::$app->user->getId()])->select(['stock_id', 'date_finish'])->all();
     for ($i = 0; $i < count($items); $i++) {
         $item =& $items[$i];
         foreach ($dateFinishList as $row) {
             if ($row['stock_id'] == $item['id']) {
                 $item['date_finish'] = $row['date_finish'];
             }
         }
         if (!isset($item['date_finish'])) {
             $item['date_finish'] = null;
         }
     }
     return $this->render(['items' => $items]);
 }
Exemplo n.º 3
0
 /**
  * Оплачена акция?
  *
  * @param integer $stock_id идентификатор акции cap_stock.id
  *
  * @return bool
  * true -  оплачена
  * false - не оплачена
  */
 public function isPaid($stock_id)
 {
     return UserStock::isPaidStatic($this->getId(), $stock_id);
 }
Exemplo n.º 4
0
 /**
  * Оплачена ли котировка?
  *
  * @return bool
  */
 public function isPaid()
 {
     return UserStock::query(['stock_id' => $this->getId(), 'user_id' => \Yii::$app->user->id])->andWhere(['>', 'date_finish', date('Y-m-d')])->exists();
 }
Exemplo n.º 5
0
        <div class="list-group">
            <a href="<?php 
    echo Url::to(['cabinet/stock_list']);
    ?>
" class="list-group-item">
                Курсы
            </a>
        </div>


        <div class="list-group">

            <?php 
    $items = \app\models\Stock::query()->orderBy(['name' => SORT_ASC])->all();
    $dateFinishList = \app\models\UserStock::query(['user_id' => \Yii::$app->user->getId()])->select(['stock_id', 'date_finish'])->all();
    for ($i = 0; $i < count($items); $i++) {
        $item =& $items[$i];
        foreach ($dateFinishList as $row) {
            if ($row['stock_id'] == $item['id']) {
                $item['is_paid'] = \Yii::$app->user->identity->isPaid($item['id']);
            }
        }
        if (!isset($item['is_paid'])) {
            $item['is_paid'] = false;
        }
    }
    for ($i = 0; $i < count($items); $i++) {
        $item =& $items[$i];
        $url = Url::to(['cabinet/stock_item3', 'id' => $item['id']]);
        ?>