From c342859b3717373d77aee6522b15cf9b9f4a127d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com> Date: Fri, 18 Aug 2023 16:54:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20#100000=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Waybill.php | 3 ++ app/Services/Ship/WayBillService.php | 39 +++++++++++++++++++ ...023_07_27_184020_create_waybills_table.php | 1 + 3 files changed, 43 insertions(+) diff --git a/app/Models/Waybill.php b/app/Models/Waybill.php index a7d3e7e..e32a169 100644 --- a/app/Models/Waybill.php +++ b/app/Models/Waybill.php @@ -7,4 +7,7 @@ use Illuminate\Database\Eloquent\Model; class Waybill extends Model { protected $guarded = []; + + public static $BUSINESS_EXPRESS_CODE = 247; + public static $AIR_FREIGHT_CODE = 266; } diff --git a/app/Services/Ship/WayBillService.php b/app/Services/Ship/WayBillService.php index b96517a..8f17a3e 100644 --- a/app/Services/Ship/WayBillService.php +++ b/app/Services/Ship/WayBillService.php @@ -20,6 +20,8 @@ class WayBillService // 标准模板 public $sfStd = 'https://file-link.pinduoduo.com/sf_std'; public $sfStdTemplate = 'sf_std1677380804913.xml'; + // 时效类型 + public $timedDeliveryCode; public function getContents() { @@ -148,8 +150,35 @@ class WayBillService return $waybill; } + private function timedDelivery($order) + { + $this->timedDeliveryCode = Waybill::$BUSINESS_EXPRESS_CODE; + $address = [ + '辽宁省' => [], + '吉林省' => [], + '黑龙江省' => [], + '甘肃省' => [], + '海南省' => [], + '宁夏回族自治区' => [ + '银川市', '石嘴山市', '吴忠市', '固原市' + ], + '青海省' => [ + '西宁市', '海东市', '海北藏族自治州', '黄南藏族自治州', '海南藏族自治州', '玉树藏族自治州' + ], + ]; + if (isset($address[$order['recipient_province']])) { + if (empty($address[$order['recipient_province']])) { + $this->timedDeliveryCode = Waybill::$AIR_FREIGHT_CODE; + } + if ($address[$order['recipient_province']] && in_array($order['recipient_city'], $address[$order['recipient_province']], true)) { + $this->timedDeliveryCode = Waybill::$AIR_FREIGHT_CODE; + } + } + } + private function prepareRequest($order, $shop) { + $this->timedDelivery($order); $senderConfig = $shop->senders[0]; $sender = [ 'address' => [ @@ -168,6 +197,11 @@ class WayBillService $items = []; foreach ($order['items'] as $item) { if ($item['should_print']) { + // 使用规格编码后删除,此处暂时使用空运名字判断兼容 + if (false !== strpos($item['name'], '空运')) { + $this->timedDeliveryCode = Waybill::$AIR_FREIGHT_CODE; + } + $items[] = [ 'name' => $item['name'], 'count' => $item['count'], @@ -176,6 +210,11 @@ class WayBillService } $orderInfo = [ + 'logistics_services' => [ + 'TIMED-DELIVERY' => [ + 'value' => $this->timedDeliveryCode + ], + ], 'object_id' => $this->objectId, 'order_info' => [ 'order_channels_type' => 'PDD', diff --git a/database/migrations/2023_07_27_184020_create_waybills_table.php b/database/migrations/2023_07_27_184020_create_waybills_table.php index cc132ac..0c551dd 100644 --- a/database/migrations/2023_07_27_184020_create_waybills_table.php +++ b/database/migrations/2023_07_27_184020_create_waybills_table.php @@ -51,6 +51,7 @@ class CreateWaybillsTable extends Migration $table->string('order_sn'); $table->integer('order_id'); $table->integer('participate_no')->default(0); + $table->integer('timed_delivery')->default(247); $table->string('note')->nullable(); $table->text('items'); $table->tinyInteger('cancel')->default(0);