京东打印

This commit is contained in:
杨建炊 2024-12-28 15:32:20 +08:00
parent 0cd78ff136
commit 4c69014a12
10 changed files with 91 additions and 12 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class CancelLogisticEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $shopId;
public $orderSn;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($shopId, $orderSn)
{
$this->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');
}
}

View File

@ -179,7 +179,6 @@ class BusinessOrderController extends Controller
public function print(Request $request)
{
$shopIds = Shop::query()
->where('plat_id', Shop::$PLAT_KTT)
->pluck('id');

View File

@ -2,6 +2,8 @@
namespace App\Http\Controllers\Business;
use App\Events\BusinessOrderCancelEvent;
use App\Events\CancelLogisticEvent;
use App\Exports\BusinessOrderExport;
use App\Exports\OrderBlankExport;
use App\Http\Controllers\Controller;
@ -10,6 +12,7 @@ use App\Models\BusinessOrderItem;
use App\Models\GoodsSku;
use App\Models\Shop;
use App\Models\Waybill;
use App\Services\Business\BusinessFactory;
use App\Services\WayBill\JingDong\JingDongService;
use App\Services\WayBill\JingDong\WayBillService;
use App\Utils\DateTimeUtils;
@ -34,5 +37,38 @@ class WaybillController extends Controller
return $jingDongService->queryTrace($waybill);
}
public function cancel(Request $request)
{
$params = $request->validate([
'order_id' => 'required',
], [
'order_id.required' => '订单id',
]);
$waybill = Waybill::query()->where("order_id", $params['order_id'])->firstOrFail();
if (empty($waybill->waybill_code)) {
throw new \Exception("无快递单号可取消");
}
try{
//取消快团团物流
$shop = Shop::query()->findOrFail($waybill->shop_id);
$client = BusinessFactory::init()->make($shop['plat_id'])->setShop($shop);
$client->cancelLogistic($waybill->order_sn, $waybill->waybill_code);
//取消京东物流
$jingDongService = new JingDongService();
$jingDongService->cancelOrder($waybill);
}catch(\Exception $exception) {
Log::error("取消快团团或者京东物流异常", ["error" => $exception->getMessage()]);
}
$waybill->waybill_code = '';
$waybill->encryptedData = '';
$waybill->status = Waybill::$STATUS_INIT;
$waybill->cancel = 1;
$waybill->save();
BusinessOrder::query()->where("id", $params['order_id'])->update(['print_status' => 0]);
return response(['message' => 'success']);
}
}

View File

@ -2,6 +2,7 @@
namespace App\Listeners;
use App\Events\CancelLogisticEvent;
use App\Events\CreateLogisticEvent;
use App\Models\Shop;
use App\Models\Waybill;
@ -11,9 +12,6 @@ use Illuminate\Queue\InteractsWithQueue;
class CancelLogisticListener implements ShouldQueue
{
public $connection = 'redis';
public $queue = 'listeners';
/**
* Create the event listener.
@ -31,7 +29,7 @@ class CancelLogisticListener implements ShouldQueue
* @param CreateLogisticEvent $event
* @return void
*/
public function handle(CreateLogisticEvent $event)
public function handle(CancelLogisticEvent $event)
{
$waybillNo = Waybill::query()
->where('shop_id', $event->shopId)

View File

@ -11,10 +11,6 @@ use Illuminate\Queue\InteractsWithQueue;
class CreateLogisticListener implements ShouldQueue
{
public $connection = 'redis';
public $queue = 'listeners';
/**
* Create the event listener.
*
@ -35,6 +31,6 @@ class CreateLogisticListener implements ShouldQueue
{
$shop = Shop::query()->findOrFail($event->shopId);;
$client = BusinessFactory::init()->make($shop['plat_id'])->setShop($shop);
//$client->createLogistic($event->orderSn, $event->waybillNo);
$client->createLogistic($event->orderSn, $event->waybillNo);
}
}

View File

@ -11,6 +11,7 @@ class Waybill extends Model
public static $BUSINESS_EXPRESS_CODE = 247;
public static $AIR_FREIGHT_CODE = 266;
public static $STATUS_INIT = 0;
public static $STATUS_CREATE_WAYBILL_CODE = 1;
public static $STATUS_CREATE_WAYBILL_ENCRYPTED_DATA = 2;
public static $STATUS_PRINT_SUCCESS = 3;

View File

@ -3,6 +3,7 @@
namespace App\Providers;
use App\Events\BusinessOrdersUpdate;
use App\Events\CancelLogisticEvent;
use App\Events\StockUpdateEvent;
use App\Events\GroupSetEvent;
use App\Events\BatchStockUpdateEvent;
@ -47,6 +48,9 @@ class EventServiceProvider extends ServiceProvider
CreateLogisticEvent::class => [
CreateLogisticListener::class
],
CancelLogisticEvent::class => [
CancelLogisticListener::class
],
];
/**

View File

@ -4,6 +4,7 @@ namespace App\Services\Business;
use App\Events\BusinessOrderCancelEvent;
use App\Events\BusinessOrdersUpdate;
use App\Events\CancelLogisticEvent;
use App\Models\BusinessGoodsSku;
use App\Models\BusinessOrder;
use App\Models\BusinessOrderItem;
@ -55,7 +56,7 @@ abstract class BusinessClient
$orderRecord->update($order);
}
if (!empty($order['cancel_status'])) {
event(new BusinessOrderCancelEvent($shopId, $order['order_sn']));
event(new CancelLogisticEvent($shopId, $order['order_sn']));
}
$goodsSkuNum = 0;
foreach ($order['sub_order_list'] as $item) {
@ -154,7 +155,7 @@ abstract class BusinessClient
'headers' => ['Content-type' => 'application/x-www-form-urlencoded;charset=UTF-8'],
'form_params' => $params
];
$res = (new Client())->request($method, $url, $headers);
$res = (new Client(['verify'=>false]))->request($method, $url, $headers);
$size = $res->getBody()->getSize();
$res = json_decode($res->getBody()->getContents(), true);
$paramsJson = json_encode($params, 256);

View File

@ -73,6 +73,7 @@ Route::middleware(['auth:api', 'check.permissions'])->group(function () {
Route::get('print/orders', [BusinessOrderController::class, 'print'])->name('order.print');
Route::put('print/success', [BusinessOrderController::class, 'printSuccess'])->name('order.printSuccess');
Route::get('waybill/queryTrace', [\App\Http\Controllers\Business\WaybillController::class, 'queryTrace']);
Route::post('waybill/cancel', [\App\Http\Controllers\Business\WaybillController::class, 'cancel']);
// 发货信息
Route::get('shop/ship/senders', [ShipController::class, 'getSenders'])->name('shop_ship.senders.get');
Route::post('shop/ship/senders', [ShipController::class, 'saveSenders'])->name('shop_ship.senders.save');

View File

@ -1,5 +1,6 @@
<?php
use App\Services\Business\BusinessFactory;
use Illuminate\Foundation\Inspiring;
/*
@ -14,5 +15,7 @@ use Illuminate\Foundation\Inspiring;
*/
Artisan::command('inspire', function () {
$order= \App\Models\BusinessOrder::query()->find(6582);
BusinessFactory::init()->make($order->shop->plat_id)->setShop($order->shop)->queryStatusAndSync($order);
$this->comment(Inspiring::quote());
})->describe('Display an inspiring quote');