Ejemplo n.º 1
0
 public function resetActiveItems()
 {
     $time = time();
     $RActiveItems = RActiveItems::find()->where(['<=', 'date', $time])->all();
     if ($RActiveItems) {
         foreach ($RActiveItems as $item) {
             $item->delete();
         }
     }
 }
Ejemplo n.º 2
0
 public function getCountActiveRecord()
 {
     return $this->hasMany(RItems::className(), ['id_user' => 'id'])->rightJoin(RActiveItems::tableName(), "r_items.id = r_active_items.id_item")->count();
 }
Ejemplo n.º 3
0
 public function enabled()
 {
     if ($this->validRecord()) {
         $user = $user = Yii::$app->user->identity;
         $user->scenario = "money";
         $session = Yii::$app->session;
         if (isset($this->category->priceCategory->price)) {
             $price = $this->category->priceCategory->price;
         } else {
             $price = 0;
         }
         if ($user->money >= $price) {
             $activeItem = new RActiveItems();
             $activeItem->id_item = $this->id;
             if (isset($this->category->priceCategory->time)) {
                 $dt_time = $this->category->priceCategory->time;
             } else {
                 $dt_time = 0;
             }
             $activeItem->date = time() + $dt_time;
             $activeItem->start_date = time();
             $activeItem->save();
             $user->minusMoney($price);
         } else {
             $session->setFlash('error', "Недостаточно средств на счете!");
         }
     }
 }