优化:订单列表显示预计到达时间
This commit is contained in:
parent
a4bbe1c4d8
commit
a318806058
|
|
@ -16,6 +16,7 @@ use Beike\Notifications\UpdateOrderNotification;
|
|||
use Beike\Services\StateMachineService;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class Order extends Base
|
||||
|
|
@ -64,6 +65,10 @@ class Order extends Base
|
|||
return $this->hasMany(OrderPayment::class);
|
||||
}
|
||||
|
||||
public function logistics(): HasOne{
|
||||
return $this->hasOne(Logistics::class,'id','shipping_method_code');
|
||||
}
|
||||
|
||||
public function subTotal()
|
||||
{
|
||||
$totals = $this->orderTotals;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace Beike\Repositories;
|
|||
|
||||
use Beike\Models\Address;
|
||||
use Beike\Models\Customer;
|
||||
use Beike\Models\Logistics;
|
||||
use Beike\Models\Order;
|
||||
use Beike\Services\StateMachineService;
|
||||
use Carbon\Carbon;
|
||||
|
|
@ -121,7 +122,9 @@ class OrderRepo
|
|||
$builder->where('status', $status);
|
||||
}
|
||||
|
||||
$builder->with(['orderShipments']);
|
||||
$builder->with(['orderShipments','logistics'=>function($query){
|
||||
$query->select(['id','day_min','day_max']);
|
||||
}]);
|
||||
|
||||
|
||||
return $builder;
|
||||
|
|
@ -220,6 +223,12 @@ class OrderRepo
|
|||
$currency = CurrencyRepo::findByCode($currencyCode);
|
||||
$currencyValue = $currency->value ?? 1;
|
||||
|
||||
$shipping_method_name = trans($shippingMethodCode);
|
||||
if(is_int($shippingMethodCode)) {
|
||||
$logisticsName = Logistics::query()->where('id',$shippingMethodCode)->value('name');
|
||||
$shipping_method_name = $logisticsName ?? $shipping_method_name;
|
||||
}
|
||||
|
||||
$order = new Order([
|
||||
'number' => self::generateOrderNumber(),
|
||||
'customer_id' => $customer->id ?? 0,
|
||||
|
|
@ -238,7 +247,7 @@ class OrderRepo
|
|||
'user_agent' => request()->userAgent(),
|
||||
'status' => StateMachineService::CREATED,
|
||||
'shipping_method_code' => $shippingMethodCode,
|
||||
'shipping_method_name' => trans($shippingMethodCode),
|
||||
'shipping_method_name' => $shipping_method_name,
|
||||
'shipping_customer_name' => $shippingAddress->name,
|
||||
'shipping_calling_code' => $shippingAddress->calling_code ?? 0,
|
||||
'shipping_telephone' => $shippingAddress->phone ?? '',
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ class CheckoutService
|
|||
}
|
||||
|
||||
$shippingMethodCode = $current['shipping_method_code'];
|
||||
if (! PluginRepo::shippingEnabled($shippingMethodCode)) {
|
||||
if (! PluginRepo::shippingEnabled($shippingMethodCode) && !is_int($shippingMethodCode)) {
|
||||
throw new \Exception(trans('shop/carts.invalid_shipping_method'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ return [
|
|||
'total' => 'Total',
|
||||
'express_number' => 'Express Number',
|
||||
'express_company' => 'Express Company',
|
||||
'expected_arrival' => 'Expected to arrive between :start_time and :end_time',
|
||||
'order_shipments' => 'shipment information',
|
||||
|
||||
'address_info' => 'Address Information',
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ return [
|
|||
'total' => '订单总额',
|
||||
'express_number' => '快递单号',
|
||||
'express_company' => '快递公司',
|
||||
|
||||
'expected_arrival' => '预计在:start_time 至 :end_time到达',
|
||||
'order_shipments' => '发货信息',
|
||||
|
||||
'address_info' => '地址信息',
|
||||
|
|
|
|||
|
|
@ -38,7 +38,17 @@
|
|||
{{--物流信息--}}
|
||||
@if ($order->orderShipments->count() > 0)
|
||||
<span class="order-created me-4">{{ __('order.express_company') }}:{{ $order->orderShipments[0]->express_company }}</span>
|
||||
<span class="order-number">{{ __('order.express_number') }}:{{ $order->orderShipments[0]->express_number }}</span>
|
||||
<span class="order-number me-4">{{ __('order.express_number') }}:{{ $order->orderShipments[0]->express_number }}</span>
|
||||
@if($order->logistics)
|
||||
@php
|
||||
$created_at = strtotime($order->orderShipments[0]->created_at);
|
||||
$day_min = $order->logistics->day_min;
|
||||
$day_max = $order->logistics->day_max;
|
||||
$startTime = date('Y-m-d',strtotime("+{$day_min} day", $created_at));
|
||||
$endTime = date('Y-m-d',strtotime("+{$day_max} day", $created_at));
|
||||
@endphp
|
||||
<span class="order-number">{{ __('order.expected_arrival',['start_time'=>$startTime,'end_time'=>$endTime]) }}</span>
|
||||
@endif
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
|||
Loading…
Reference in New Issue