From e35114f84279ca6309cc5b14c23dc5bbd584307f 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, 28 Jul 2023 15:35:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20#10000=20=E8=AE=A2=E5=8D=95=E4=B8=8B?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/Test.php | 1 + .../Business/BusinessOrderController.php | 21 +++++++++++++++++++ .../Business/KuaiTuanTuan/FaceSheet.php | 11 ++++++++++ .../Ship/{WayBill.php => WayBillService.php} | 21 +++++++++++-------- ...023_07_27_184020_create_waybills_table.php | 5 +++-- 5 files changed, 48 insertions(+), 11 deletions(-) rename app/Services/Ship/{WayBill.php => WayBillService.php} (93%) diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 5f4eaec..5816240 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -15,6 +15,7 @@ use App\Models\ShopShip; use App\Models\TodayPrice; use App\Services\Business\BusinessFactory; use App\Services\Business\KuaiTuanTuan\FaceSheet; +use App\Services\Ship\WayBillService; use App\Utils\DateTimeUtils; use Carbon\Carbon; use Illuminate\Console\Command; diff --git a/app/Http/Controllers/Business/BusinessOrderController.php b/app/Http/Controllers/Business/BusinessOrderController.php index 5979ccc..2cc1057 100644 --- a/app/Http/Controllers/Business/BusinessOrderController.php +++ b/app/Http/Controllers/Business/BusinessOrderController.php @@ -8,6 +8,7 @@ use App\Models\BusinessOrder; use App\Models\BusinessOrderItem; use App\Models\GoodsSku; use App\Models\Shop; +use App\Services\Ship\WayBillService; use App\Utils\DateTimeUtils; use Carbon\Carbon; use Illuminate\Http\Request; @@ -186,4 +187,24 @@ class BusinessOrderController extends Controller ->get(['activity_title', 'activity_no']) ->toArray(); } + + public function print(Request $request) + { + $shopIds = Shop::query() + ->where('plat_id', Shop::$PLAT_KTT) + ->pluck('id'); + $builder = BusinessOrder::query() + ->with('items') + ->whereIn('shop_id', $shopIds) + ->filter(); + $externalSkuIds = $request->get('external_sku_ids'); + if ($externalSkuIds) { + $ids = BusinessOrderItem::query()->whereIn('external_sku_id', $externalSkuIds)->pluck('business_order_id'); + $builder->whereIn('id', $ids); + } + $businessOrders = $builder->get(); + $waybill = new WayBillService(); + $waybill->setOrders($businessOrders); + $waybill->get(); + } } diff --git a/app/Services/Business/KuaiTuanTuan/FaceSheet.php b/app/Services/Business/KuaiTuanTuan/FaceSheet.php index de71054..4f77b61 100644 --- a/app/Services/Business/KuaiTuanTuan/FaceSheet.php +++ b/app/Services/Business/KuaiTuanTuan/FaceSheet.php @@ -85,5 +85,16 @@ class FaceSheet extends KuaiTuanTuan return $this->doRequest($type, $appendParams); } + + public function cancel($waybillCode, $wpCode) + { + $type = 'pdd.cloudprint.customares.get'; + $appendParams = [ + 'waybill_code' => $waybillCode, + 'wp_code' => $wpCode, + ]; + + return $this->doRequest($type, $appendParams); + } } diff --git a/app/Services/Ship/WayBill.php b/app/Services/Ship/WayBillService.php similarity index 93% rename from app/Services/Ship/WayBill.php rename to app/Services/Ship/WayBillService.php index f895435..302619e 100644 --- a/app/Services/Ship/WayBill.php +++ b/app/Services/Ship/WayBillService.php @@ -4,9 +4,10 @@ namespace App\Services\Ship; use App\Models\GoodsSku; use App\Models\ShopShip; +use App\Models\Waybill; use App\Services\Business\KuaiTuanTuan\FaceSheet; -class WayBill +class WayBillService { public $orders; public $objectId; @@ -15,6 +16,7 @@ class WayBill public function get() { foreach ($this->orders as $shopId => $order) { + // 订单取消的情况暂不处理 $shop = $this->getShop($shopId); $faceSheet = new FaceSheet(); $faceSheet->setShop($shop); @@ -24,12 +26,12 @@ class WayBill $resp = $faceSheet->getWayBill($sender, $orderInfo, $wpCode); if (isset($resp['pdd_waybill_get_response'])) { $data = $resp['pdd_waybill_get_response']['modules'][0]; - $data = json_decode($data['print_data'], true); + $printData = json_decode($data['print_data'], true); $waybill->request_id = $resp['pdd_waybill_get_response']['request_id']; - $waybill->encryptedData = $data['encryptedData']; - $waybill->signature = $data['signature']; - $waybill->templateUrl = $data['templateUrl']; - $waybill->ver = $data['ver']; + $waybill->encryptedData = $printData['encryptedData']; + $waybill->signature = $printData['signature']; + $waybill->templateUrl = $printData['templateUrl']; + $waybill->ver = $printData['ver']; $waybill->waybill_code = $data['waybill_code']; $waybill->save(); } @@ -41,7 +43,7 @@ class WayBill { $senderConfig = $shop->senders[0]; $waybill = new Waybill(); - $waybill->shop_id = $shop->id; + $waybill->shop_id = $shop->shop_id; $waybill->object_id = $this->objectId; $waybill->sender_country = $senderConfig['country']; @@ -149,7 +151,8 @@ class WayBill 'combinationGoods.goodsSkuItem:id,external_sku_id', ]) ->whereIn('external_sku_id', $combinationExternalIds) - ->get(); + ->get() + ->toArray(); foreach ($goodsSkus as $goodsSku) { foreach ($goodsSku['combination_goods'] as $item) { $combinations[$goodsSku['external_sku_id']][] = [ @@ -215,6 +218,6 @@ class WayBill $query->orderBy('sort')->first(); } ]) - ->get(); + ->first(); } } 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 b0e2051..fa0ef58 100644 --- a/database/migrations/2023_07_27_184020_create_waybills_table.php +++ b/database/migrations/2023_07_27_184020_create_waybills_table.php @@ -42,14 +42,15 @@ class CreateWaybillsTable extends Migration $table->string('recipient_district'); $table->string('recipient_detail'); $table->string('recipient_name'); - $table->integer('recipient_mobile'); + $table->string('recipient_mobile', 16); - $table->bigInteger('user_id'); + $table->string('user_id'); $table->string('wp_code'); $table->string('order_channels_type')->default('PDD'); $table->string('order_sn'); $table->text('items'); + $table->tinyInteger('cancel')->default(0); $table->timestamps();