Integrate `SystemSetting` into core services to enable dynamic configuration of business logic and update the WordPress order form redirection to align with the new order approval workflow. - Update `PaymentController`, `ShipmentObserver`, and `TrackingService` to utilize `SystemSetting` for runtime configuration. - Modify `ifnex-order-form.js` to redirect users to the orders list instead of order details upon successful submission.
51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Shipment;
|
|
use App\Models\ShipmentTrackingEvent;
|
|
use App\Models\SystemSetting;
|
|
|
|
class TrackingService
|
|
{
|
|
public function getTrackingTimeline(string $awb_no)
|
|
{
|
|
$shipment = Shipment::where('awb_no', $awb_no)->firstOrFail();
|
|
|
|
return $shipment->trackingEvents()
|
|
->orderByDesc('event_date')
|
|
->orderByDesc('event_time')
|
|
->get();
|
|
}
|
|
|
|
public function addTrackingEvent(int $shipment_id, array $data): ShipmentTrackingEvent
|
|
{
|
|
$event = ShipmentTrackingEvent::create(array_merge($data, [
|
|
'shipment_id' => $shipment_id,
|
|
'source' => 'manual',
|
|
]));
|
|
|
|
if (SystemSetting::get('kavenegar_api_key') && (bool) SystemSetting::get('kavenegar_send_tracking_update', false)) {
|
|
$shipment = Shipment::with('user')->find($shipment_id);
|
|
if ($shipment && $shipment->user && $shipment->user->phone) {
|
|
$shipment->user->notify(new \App\Notifications\TrackingUpdatedSms(
|
|
$shipment->awb_no,
|
|
$event->event_description ?? 'بهروزرسانی',
|
|
$event->location ?? ''
|
|
));
|
|
}
|
|
}
|
|
|
|
return $event;
|
|
}
|
|
|
|
public function getShipmentWithTracking(string $awb_no)
|
|
{
|
|
$shipment = Shipment::where('awb_no', $awb_no)
|
|
->with(['carrierMappings', 'trackingEvents'])
|
|
->firstOrFail();
|
|
|
|
return $shipment;
|
|
}
|
|
}
|