Beispiel #1
0
 /**
  * Updates an existing Order model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     //if(!Yii::$app->user->can('updateYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $query = OrderProduct::find()->where(['order_id' => $id]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'dataProvider' => $dataProvider]);
     }
 }
Beispiel #2
0
 public function actionCodes()
 {
     //        $packages = OrderProduct::find()->codes(\Yii::$app->user->id);
     $packages = OrderProduct::find()->codes(\Yii::$app->user->id);
     $codes = ["" => 'Please select code'];
     foreach ($packages as $package) {
         $codes[$package] = $package;
     }
     $topups = OrderProduct::find()->select(['id', 'name'])->availableProduct('Topup', Yii::$app->user->id)->asArray()->all();
     $result = \Yii::$app->controller->renderPartial('@frontend/views/site/_topup_list', ['codes' => $codes, 'topups' => $topups], true);
     return $result;
 }
Beispiel #3
0
 /**
  * Lists all Comment models.
  * @return mixed
  */
 public function actionIndex()
 {
     $commentedOrders = Comment::find()->where(['user_id' => Yii::$app->user->id])->all();
     $orderIds = ArrayHelper::map($commentedOrders, 'order_id', 'order_id');
     $productIds = ArrayHelper::map($commentedOrders, 'order_id', 'product_id');
     if (count($orderIds) && count($productIds)) {
         $ids = [];
         foreach ($productIds as $orderId => $productId) {
             $orderProduct = OrderProduct::find()->where(['and', 'user_id = ' . Yii::$app->user->id, 'order_id = ' . $orderId, 'product_id = ' . $productId])->one();
             $ids[] = $orderProduct->id;
         }
         $query = OrderProduct::find()->where(['and', 'user_id = ' . Yii::$app->user->id, ['not in', 'id', $ids]]);
     } else {
         $query = OrderProduct::find()->where(['user_id' => Yii::$app->user->id]);
     }
     $query->orderBy(['created_at' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeOrder']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     return $this->render('index', ['models' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination]);
 }
Beispiel #4
0
 public function actionAjaxStatus($id, $status)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $model = $this->findModel($id);
     if ($model) {
         $oldStatus = $model->status;
         $model->status = $status;
         $model->save();
         // 记录订单日志
         $orderLog = new OrderLog(['order_id' => $model->id, 'status' => $model->status]);
         $orderLog->save();
         // 如果订单为取消,则恢复对应的库存
         if ($oldStatus > 0 && $status == Order::STATUS_CANCEL) {
             $orderProducts = OrderProduct::find()->where(['order_id' => $model->id])->all();
             foreach ($orderProducts as $product) {
                 Product::updateAllCounters(['stock' => $product->number], ['id' => $product->product_id]);
             }
         }
         return ['status' => 1];
     }
     return ['status' => -1];
 }
Beispiel #5
0
 public static function TrialExist()
 {
     return OrderProduct::find()->where(['modelClass' => 'Package', 'mask' => 1, 'created_by' => Yii::$app->user->id])->exists();
 }