diff --git a/app/Events/BusinessOrderCancelEvent.php b/app/Events/BusinessOrderCancelEvent.php new file mode 100644 index 0000000..f3a00ca --- /dev/null +++ b/app/Events/BusinessOrderCancelEvent.php @@ -0,0 +1,40 @@ +shopId = $shopId; + $this->orderSn = $orderSn; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} diff --git a/app/Events/CreateLogisticEvent.php b/app/Events/CreateLogisticEvent.php new file mode 100644 index 0000000..f5ba041 --- /dev/null +++ b/app/Events/CreateLogisticEvent.php @@ -0,0 +1,42 @@ +shopId = $shopId; + $this->orderSn = $orderSn; + $this->waybillNo = $waybillNo; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} diff --git a/app/Listeners/CancelLogisticListener.php b/app/Listeners/CancelLogisticListener.php new file mode 100644 index 0000000..d894b00 --- /dev/null +++ b/app/Listeners/CancelLogisticListener.php @@ -0,0 +1,47 @@ +where('shop_id', $event->shopId) + ->where('order_sn', $event->orderSn) + ->value('waybill_code'); + if (empty($waybillNo)) { + return; + } + $shop = Shop::query()->findOrFail($event->shopId); + $client = BusinessFactory::init()->make($shop['plat_id'])->setShop($shop); + $client->cancelLogistic($event->orderSn, $event->waybillNo); + } +} diff --git a/app/Listeners/CreateLogisticListener.php b/app/Listeners/CreateLogisticListener.php new file mode 100644 index 0000000..bb83023 --- /dev/null +++ b/app/Listeners/CreateLogisticListener.php @@ -0,0 +1,39 @@ +findOrFail($event->shopId); + $client = BusinessFactory::init()->make($shop['plat_id'])->setShop($shop); + $client->createLogistic($event->orderSn, $event->waybillNo); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index fdd269f..4a0b710 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -5,12 +5,16 @@ namespace App\Providers; use App\Events\BusinessOrdersUpdate; use App\Events\GroupSetEvent; use App\Events\StockUpdateEvent; +use App\Listeners\CreateLogisticListener; use App\Listeners\GroupQueryListener; use App\Listeners\StockUpdateListener; use App\Listeners\StockWarning; use App\Listeners\CombinationGoodsStockUpdateListener; use App\Listeners\UpdateBusinessGoodsStock; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; +use App\Events\BusinessOrderCancelEvent; +use App\Listeners\CancelLogisticListener; +use App\Events\CreateLogisticEvent; class EventServiceProvider extends ServiceProvider { @@ -33,6 +37,12 @@ class EventServiceProvider extends ServiceProvider GroupSetEvent::class => [ GroupQueryListener::class, ], + BusinessOrderCancelEvent::class => [ + CancelLogisticListener::class + ], + CreateLogisticEvent::class => [ + CreateLogisticListener::class + ], ]; /** diff --git a/app/Services/Business/BusinessClient.php b/app/Services/Business/BusinessClient.php index 69ccee8..8514845 100644 --- a/app/Services/Business/BusinessClient.php +++ b/app/Services/Business/BusinessClient.php @@ -2,6 +2,7 @@ namespace App\Services\Business; +use App\Events\BusinessOrderCancelEvent; use App\Events\BusinessOrdersUpdate; use App\Models\BusinessGoodsSku; use App\Models\BusinessOrder; @@ -29,6 +30,10 @@ abstract class BusinessClient abstract public function bindGoods($goods); + abstract public function createLogistic($orderSn, $waybillNo); + + abstract public function cancelLogistic($orderSn, $waybillNo); + abstract public function incrQuantity($businessGoodsSku, $num, $incremental); abstract public function downloadOrdersAndSave($beginTime, $endTime, $downloadType = 'default', $page = 1); @@ -45,6 +50,9 @@ abstract class BusinessClient } else { $orderRecord->update($order); } + if ($order['cancel_status']) { + event(new BusinessOrderCancelEvent($shopId, $order['order_sn'])); + } $goodsSkuNum = 0; foreach ($order['sub_order_list'] as $item) { $item['shop_id'] = $shopId; diff --git a/app/Services/Business/BusinessFactory.php b/app/Services/Business/BusinessFactory.php index c160d3a..1f9d920 100644 --- a/app/Services/Business/BusinessFactory.php +++ b/app/Services/Business/BusinessFactory.php @@ -15,6 +15,10 @@ class BusinessFactory $this->platList['妙选'] = MiaoXuan::class; } + /** + * @param $platName + * @return BusinessClient + */ public function make($platName) { return new $this->platList[$platName]; diff --git a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php index 6cf39b9..9eee939 100644 --- a/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php +++ b/app/Services/Business/KuaiTuanTuan/KuaiTuanTuan.php @@ -262,4 +262,14 @@ class KuaiTuanTuan extends BusinessClient return $this->doRequest($type, $appendParams); } + + public function createLogistic($orderSn, $waybillNo) + { + return Order::createOrderLogistic($orderSn, $waybillNo); + } + + public function cancelLogistic($orderSn, $waybillNo) + { + return Order::deleteOrderLogistic($orderSn, $waybillNo); + } } diff --git a/app/Services/Business/KuaiTuanTuan/Order.php b/app/Services/Business/KuaiTuanTuan/Order.php index 125e8ec..71977c5 100644 --- a/app/Services/Business/KuaiTuanTuan/Order.php +++ b/app/Services/Business/KuaiTuanTuan/Order.php @@ -57,5 +57,40 @@ class Order return [$type, $appendParams]; } + + public function getLogisticsCompanies() + { + $type = 'pdd.logistics.companies.get'; + + return [$type, []]; + } + + + public static function createOrderLogistic($orderSn, $waybillNo, $logisticsId = '', $logisticsName = '') + { + // 不支持拆单发货 + $type = 'pdd.ktt.order.logistic.create'; + $appendParams = [ + 'logisticsId' => $logisticsId, + 'logisticsName' => $logisticsName, + 'orderSn' => $orderSn, +// 'subOrderSnList' => [], 发货子单号列表,无子单号视为整单发货 + 'waybillNo' => $waybillNo, + ]; + + return [$type, $appendParams]; + } + + public static function deleteOrderLogistic($orderSn, $waybillNo) + { + $type = 'pdd.ktt.order.logistic.delete'; + $appendParams = [ + 'orderSn' => $orderSn, +// 'subOrderSnList' => [], 发货子单号列表,无子单号视为整单发货 + 'waybillNo' => $waybillNo, + ]; + + return [$type, $appendParams]; + } } diff --git a/app/Services/Business/MiaoXuan/MiaoXuan.php b/app/Services/Business/MiaoXuan/MiaoXuan.php index 8e18ae9..4ddeee1 100644 --- a/app/Services/Business/MiaoXuan/MiaoXuan.php +++ b/app/Services/Business/MiaoXuan/MiaoXuan.php @@ -47,4 +47,14 @@ class MiaoXuan extends BusinessClient { // TODO: Implement downloadGoods() method. } + + public function createLogistic($orderSn, $waybillNo) + { + // TODO: Implement createLogistic() method. + } + + public function cancelLogistic($orderSn, $waybillNo) + { + // TODO: Implement cancelLogistic() method. + } } diff --git a/app/Services/Ship/WayBillService.php b/app/Services/Ship/WayBillService.php index 3da1565..0f8d1d1 100644 --- a/app/Services/Ship/WayBillService.php +++ b/app/Services/Ship/WayBillService.php @@ -2,6 +2,7 @@ namespace App\Services\Ship; +use App\Events\CreateLogisticEvent; use App\Models\GoodsSku; use App\Models\ShopShip; use App\Models\Waybill; @@ -64,6 +65,7 @@ class WayBillService 'participate_no' => $waybill->participate_no, 'note' => $waybill->note, ]; + event(new CreateLogisticEvent($shopId, $waybill->order_sn, $data['waybill_code'])); } } else { $contents[$waybill->id] = [ diff --git a/config/app.php b/config/app.php index e98770e..f2c2453 100644 --- a/config/app.php +++ b/config/app.php @@ -13,7 +13,7 @@ return [ | */ - 'name' => env('APP_NAME', 'CFen Erp'), + 'name' => env('APP_NAME', 'chunfen_erp'), /* |-------------------------------------------------------------------------- diff --git a/config/database.php b/config/database.php index b186558..37c396d 100644 --- a/config/database.php +++ b/config/database.php @@ -131,7 +131,7 @@ return [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', '6379'), - 'database' => env('REDIS_DB', '0'), + 'database' => env('REDIS_DB', '10'), ], 'cache' => [ @@ -139,7 +139,7 @@ return [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', '6379'), - 'database' => env('REDIS_CACHE_DB', '1'), + 'database' => env('REDIS_CACHE_DB', '11'), ], ],