Files
izyim/app/Classes/Modules/Orders/Services/ListsOrderHistory.php
T
2019-03-19 17:11:21 +08:00

64 lines
3.0 KiB
PHP
Executable File

<?php
namespace App\Classes\Modules\Orders\Services;
use App\Classes\Constants;
use App\Models\Order;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
class ListsOrderHistory
{
public function execute(string $orderId, Carbon $createdAt, bool $complete, Carbon $lastUpdate){
/** @var Order $order */
$order = Order::findOrFail($orderId);
$orderSteps = $order->orderSteps()->where('complete', true)->orderBy('sequence')->get();
$history = new Collection();
$history->push(['date' => $createdAt->format('d-m-Y H:i'), 'description' => 'Order number has been created']);
foreach ($orderSteps as $step){
switch ($step->reference_id){
case Constants::ORDER_PROCESSING_STEP:
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'warehouse confirmed']);
break;
case Constants::ORDER_NO_WAREHOUSE_PENDING_SUPPLIER:
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Your Order has been loaded into container']);
break;
case Constants::ORDER_WAREHOUSE_RECEIVING_STEP:
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Arrived at China\'s warehouse']);
break;
case Constants::ORDER_WAREHOUSE_PACKING_STEP:
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Your Order has been loaded into container']);
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Invoice has been issued, waiting for shipping payment']);
break;
case Constants::ORDER_SHIPPING_STEP:
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Arrived to Malaysian port']);
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Custom clearance is successful']);
break;
case Constants::ORDER_WAREHOUSE_ARRIVAL_STEP:
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Arrived at Malaysia\'s warehouse']);
break;
case Constants::ORDER_WAREHOUSE_UNPACKING_STEP:
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Your Order has been unloaded and being prepared for delivery']);
break;
case Constants::ORDER_DELIVERY_STEP:
$history->push(['date' => $step->updated_at->format('d-m-Y H:i'), 'description' => 'Out for delivery']);
break;
}
}
if($complete){
$history->push(['date' => $lastUpdate->format('d-m-Y H:i'), 'description' => 'Your Order has successfully been delivered']);
}
return $history->reverse()->toArray();
}
}