81 lines
1.8 KiB
PHP
81 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
use App\Models\Shop\PriceList;
|
|
|
|
class PriceLists
|
|
{
|
|
public static function getByTariff($id)
|
|
{
|
|
return PriceList::byTariff($id)->get();
|
|
}
|
|
|
|
public static function getOptions()
|
|
{
|
|
return PriceList::pluck('name','id')->toArray();
|
|
}
|
|
|
|
public static function getAll()
|
|
{
|
|
return PriceList::orderBy('name', 'asc')->get();
|
|
}
|
|
|
|
public static function edit($id)
|
|
{
|
|
$price_list = self::getFull($id)->toArray();
|
|
$n = count($price_list['price_list_values']);
|
|
if ($n <= 3) {
|
|
$price_list['price_list_values'] += array_fill($n, 3 - $n, '');
|
|
}
|
|
return $price_list;
|
|
}
|
|
|
|
public static function get($id)
|
|
{
|
|
return PriceList::find($id);
|
|
}
|
|
|
|
public static function getPrices($id)
|
|
{
|
|
return PriceList::with('price_list_values')->find($id);
|
|
}
|
|
|
|
public static function getFull($id)
|
|
{
|
|
return PriceList::with(['price_list_values'])->find($id);
|
|
}
|
|
|
|
public static function store($data)
|
|
{
|
|
$id = $data['id'] ?? false;
|
|
$price_list_values = $data['price_list_values'] ?? false;
|
|
unset($data['price_list_values']);
|
|
$price_list = $id ? self::update($data) : self::create($data);
|
|
PriceListValues::storePrices($price_list->id, $price_list_values);
|
|
return $price_list;
|
|
}
|
|
|
|
public static function create($data)
|
|
{
|
|
return PriceList::create($data);
|
|
}
|
|
|
|
public static function update($data, $id = false)
|
|
{
|
|
$id = $id ? $id : $data['id'];
|
|
$item = self::get($id);
|
|
$item->update($data);
|
|
return $item;
|
|
}
|
|
|
|
public static function destroy($id)
|
|
{
|
|
return PriceList::destroy($id);
|
|
}
|
|
}
|