Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // Setup HTTP request for the records
     $url = SiteConfig::whereParameter('recordsUrl')->first()->data;
     $client = new Client(['base_uri' => $url]);
     $data = $client->get("api/getPricing");
     $priceData = json_decode($data->getBody());
     $priceMethod = SiteConfig::firstOrCreate(['parameter' => 'priceMethod']);
     $priceMethod->data = $priceData->priceMethod;
     $priceMethod->save();
     DB::statement('TRUNCATE element_costs');
     foreach ($priceData->prices as $price) {
         if ($priceData->priceMethod == 'fixedRatio') {
             $frPrice = SiteConfig::firstOrCreate(['parameter' => $price->parameter]);
             $frPrice->data = $price->data;
             $frPrice->save();
         } else {
             if ($priceData->priceMethod == 'elementPrice') {
                 ElementCost::create(['element' => $price->element, 'quantity' => $price->quantity, 'quantity_type' => $price->quantity_type, 'price' => $price->price]);
             }
         }
     }
 }