Example #1
0
 public function actionPay($id)
 {
     if (Yii::$app->user->isGuest) {
         Yii::$app->session->setFlash('error', "Нужно авторизоваться");
         return $this->redirect(['/site/login']);
     }
     $product = Product::find()->where(['id' => $id])->one();
     $user = User::find()->where(['id' => Yii::$app->user->id])->one();
     if ($product->number_of_coupons <= 0) {
         return 0;
     }
     if ($product->type_coupon == 0 and $user->coupon_gold < 1 or $product->type_coupon == 1 and $user->coupon_silver < 1 or $product->type_coupon == 2 and $user->coupon_bronze < 1) {
         return 1;
     }
     if (Order::payProduct($user, $product)) {
         if ($product->number_of_coupons == 0) {
             $product->status = 2;
             $product->save();
         }
         return 2;
     }
     return false;
 }