예제 #1
0
 public function checkDiscount(Discount $discount, Product $product = null, Order $order = null)
 {
     $result = false;
     if (intval(self::find()->where(['discount_id' => $discount->id])->count()) === 0) {
         $result = true;
     } else {
         $discountsCode = self::find()->where(['discount_id' => $discount->id])->all();
         $result = OrderCode::find()->where(['order_id' => $order->id, 'discount_code_id' => ArrayHelper::map($discountsCode, 'id', 'id'), 'status' => 1])->count() == 1;
     }
     return $result;
 }
예제 #2
0
 public function actionIndex()
 {
     $model = $this->loadOrder(false, false);
     $orderCode = null;
     if (!is_null($model)) {
         $orderCode = OrderCode::find()->where(['order_id' => $model->id, 'status' => 1])->one();
         if ($orderCode === null) {
             $orderCode = new OrderCode();
             if (Yii::$app->request->isPost) {
                 $orderCode->load(Yii::$app->request->post());
                 $orderCode->order_id = $model->id;
                 if ($orderCode->save()) {
                     $this->refresh();
                 }
             }
         }
         $model->calculate();
     }
     return $this->render('index', ['model' => $model, 'orderCode' => $orderCode]);
 }