75 lines
1.7 KiB
PHP
75 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Models\Shop\Order;
|
|
|
|
class Orders
|
|
{
|
|
|
|
public static function saveOrder($data)
|
|
{
|
|
$data += $data['basket'];
|
|
$basket = $data['basket'];
|
|
unset($data['basket']);
|
|
$order = self::store($data);
|
|
$detail = OrderDetails::saveBasket($order->id, $basket['detail']);
|
|
unset($data['comment']);
|
|
unset($data['agree']);
|
|
unset($data['customer_id']);
|
|
unset($data['delivery_id']);
|
|
unset($data['detail']);
|
|
unset($data['payment_type']);
|
|
unset($data['sale_channel_id']);
|
|
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
|
|
}
|
|
|
|
public static function edit($id)
|
|
{
|
|
return Orders::get($id, ['customer', 'address', 'delivery', 'detail']);
|
|
}
|
|
|
|
public static function get($id, $relations = false)
|
|
{
|
|
return $relations ? Order::with($relations)->findOrFail($id) : Order::findOrFail($id);
|
|
}
|
|
|
|
public static function store($data)
|
|
{
|
|
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
|
|
}
|
|
|
|
public static function create($data)
|
|
{
|
|
OrderStats::increase();
|
|
return Order::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 delete($id)
|
|
{
|
|
return Order::destroy($id);
|
|
}
|
|
|
|
public static function getStatus($id)
|
|
{
|
|
return self::statuses()[$id] ?? false;
|
|
}
|
|
|
|
public static function statuses()
|
|
{
|
|
return [
|
|
'En attente',
|
|
'Expédié',
|
|
'Livré',
|
|
];
|
|
}
|
|
}
|