Exemplo n.º 1
0
 /**
  * Поиск всех позиций определенного заказа
  * @return string
  * @return string
  */
 public function actionOrder()
 {
     if (Yii::$app->request->isAjax) {
         $model = new OrdersSearch();
         $orders = $model->search('order_id = :order_id AND related_detail IS NULL', [':order_id' => Yii::$app->request->post('id')]);
         return $this->renderAjax('_order', ['orders' => $orders, 'searchModel' => $model]);
     }
 }
Exemplo n.º 2
0
 public function actionInOrder()
 {
     if (!empty($post = Yii::$app->request->post()) && Yii::$app->request->isAjax) {
         $order = new OrdersSearch();
         $order->manufacture = strpos($post['manufacture'], '|r') || $post['manufacture'] == '|r' ? explode('|', $post['manufacture'])[0] : $post['manufacture'];
         $order->part_name = strpos($post['name'], '|r') ? explode('|', $post['name'])[0] : $post['name'];
         $order->part_price = (int) $post['price'];
         $order->quantity = (int) $post['quantity'];
         $order->status = \app\modules\user\models\Orders::ORDER_ADOPTED;
         $order->datetime = date('Y-m-d H:m:s');
         $order->product_article = strpos($post['code'], '|r') ? explode('|', $post['code'])[0] : $post['code'];
         $order->order_id = $post['order_id'];
         $order->provider_id = (int) $post['pid'];
         $order->delivery_days = (int) $post['srokmax'];
         $order->related_detail = $post['detail_id'] == 0 ? null : $post['detail_id'];
         if ($order->save()) {
             if (!$post['detail_id']) {
                 $order->isNewRecord = true;
                 $order->related_detail = $order->id;
                 $order->id = null;
                 $order->save();
             }
             $order->provider_id = $order->provider->name;
             return Json::encode($order->getAttributes());
         }
     }
     return false;
 }