Exemplo n.º 1
0
 /**
  * Get the Complete Name for the user.
  *
  * @return string
  */
 public function setPathAttribute($path)
 {
     if (!empty($path)) {
         $title = Carbon::now()->second . $path->getClientOriginalName();
         $this->attributes['path'] = $title;
         \Storage::disk('local')->put($title, \File::get($path));
     }
 }
 /**
  * Возвращает ассоциативный массив:
  * ID Продукта -> [ ID Ценовой Колонки -> Цена ]
  * @return array
  * @throws \Exception
  */
 public function getProductsInOrdersPricesArr()
 {
     // Получаем все Ценовые Колонки для данной Закупки
     $pricing_grid_columns_models_arr = $this->getPricingGridColumns()->get();
     if (!count($pricing_grid_columns_models_arr)) {
         \App\Helpers\Assistant::exception("Pricing Grid Columns array is empty. PurchaseId = {$this->id}");
     }
     $pricing_grid_columns_ids_arr = [];
     // Собираем список ID всех Ценовых Колонок данной Закупки
     foreach ($pricing_grid_columns_models_arr as $pricing_grid_column_model) {
         $pricing_grid_columns_ids_arr[] = $pricing_grid_column_model->id;
     }
     // Получаем массив ID продуктов во всех заказах данной Закупки
     $all_orders_products_ids_arr = $this->getAllOrdersProductsIdsArr();
     if (empty($all_orders_products_ids_arr)) {
         return [];
     }
     \Storage::disk('local')->put('tests/all_orders_products_ids_arr.json', implode(',', $all_orders_products_ids_arr));
     \Storage::disk('local')->put('tests/pricing_grid_columns_ids_arr.json', implode(',', $pricing_grid_columns_ids_arr));
     $products_prices_mixes_arr = \DB::table('prices')->whereIn('product_id', $all_orders_products_ids_arr)->whereIn('column_id', $pricing_grid_columns_ids_arr)->select()->get();
     if (empty($products_prices_mixes_arr)) {
         \App\Helpers\Assistant::exception("Found the product without prices. PurchaseId = {$this->id}");
     }
     $products_prices_arr = [];
     foreach ($products_prices_mixes_arr as $product_price_mix) {
         $product_id = $product_price_mix->product_id;
         $column_id = $product_price_mix->column_id;
         $price = $product_price_mix->price;
         if (!array_key_exists($product_id, $products_prices_arr)) {
             $products_prices_arr[$product_id] = [];
         }
         if (!array_key_exists($column_id, $products_prices_arr[$product_id])) {
             $products_prices_arr[$product_id][$column_id] = [];
         }
         $products_prices_arr[$product_id][intval($column_id)] = doubleval($price);
     }
     return $products_prices_arr;
 }