京东打印
This commit is contained in:
parent
968e5137a8
commit
e850b3d336
@ -189,12 +189,9 @@ class BusinessOrderController extends Controller
|
|||||||
$waybill = new WayBillService();
|
$waybill = new WayBillService();
|
||||||
$waybill->setOrders($businessOrders);
|
$waybill->setOrders($businessOrders);
|
||||||
$contents = $waybill->getWayBillContents();
|
$contents = $waybill->getWayBillContents();
|
||||||
// 待打印数据
|
|
||||||
[$documents, $orderIds] = $waybill->getDocumentsAndOrderIds($contents);
|
|
||||||
|
|
||||||
return response([
|
return response([
|
||||||
'documents' => $this->combinationPrintDocuments($documents),
|
'data' => $contents
|
||||||
'order_ids' => implode(',', $orderIds),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Ship\JingDong;
|
namespace App\Services\WayBill\JingDong;
|
||||||
|
|
||||||
use App\Enum\Pickup\ConsignType;
|
use App\Enum\Pickup\ConsignType;
|
||||||
use App\Models\BusinessOrder;
|
use App\Models\BusinessOrder;
|
||||||
@ -85,7 +85,7 @@ class JingDongService
|
|||||||
$response = $client->execute($request, $options);
|
$response = $client->execute($request, $options);
|
||||||
$response = json_decode($response->getBody(), true);
|
$response = json_decode($response->getBody(), true);
|
||||||
Log::info("京东返回请求response", [$response]);
|
Log::info("京东返回请求response", [$response]);
|
||||||
if (!isset($response['code']) || ($response['code'] != 0 && $response['code'] != 1000)) {
|
if (!isset($response['code']) || ($response['code'] != 0 && $response['code'] != 1 && $response['code'] != 1000)) {
|
||||||
throw new \Exception($response['msg'] ?? "code异常");
|
throw new \Exception($response['msg'] ?? "code异常");
|
||||||
}
|
}
|
||||||
return $response;
|
return $response;
|
||||||
@ -95,13 +95,11 @@ class JingDongService
|
|||||||
private function buildCargoes($extend)
|
private function buildCargoes($extend)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[
|
"quantity" => $extend["quantity"] ?? 1,
|
||||||
"quantity" => $extend["quantity"] ?? 1,
|
"goodsName" => "鲜花",
|
||||||
"goodsName" => "鲜花",
|
"volume" => ($extend['volume'] ?? 0) > 0 ? $extend['volume'] : 100,
|
||||||
"volume" => ($extend['volume'] ?? 0) > 0 ? $extend['volume'] : 100,
|
"weight" => $extend['weight'] ?? 1,
|
||||||
"weight" => $extend['weight'] ?? 1,
|
"packageQty" => 1
|
||||||
"packageQty" => 1
|
|
||||||
]
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +117,7 @@ class JingDongService
|
|||||||
$path = "/freshmedicinedelivery/delivery/create/order/v1";
|
$path = "/freshmedicinedelivery/delivery/create/order/v1";
|
||||||
$pickupData = $pickup->toArray();
|
$pickupData = $pickup->toArray();
|
||||||
$body = [
|
$body = [
|
||||||
"orderId" => $pickupData['object_id'],
|
"orderId" => $pickupData['order_sn'],
|
||||||
"senderContactRequest" => [
|
"senderContactRequest" => [
|
||||||
'senderName' => $pickupData['sender_name'] ?? '',
|
'senderName' => $pickupData['sender_name'] ?? '',
|
||||||
'senderPhone' => $pickupData['sender_mobile'] ?? '',
|
'senderPhone' => $pickupData['sender_mobile'] ?? '',
|
||||||
@ -128,7 +126,7 @@ class JingDongService
|
|||||||
],
|
],
|
||||||
"customerCode" => $this->customerCode,
|
"customerCode" => $this->customerCode,
|
||||||
"remark" => $pickup['note'] ?? '',
|
"remark" => $pickup['note'] ?? '',
|
||||||
"salePlatform" => '0010001',//京东
|
"salePlatform" => '0030001',//其他平台
|
||||||
"cargoesRequest" => $this->buildCargoes($pickup),
|
"cargoesRequest" => $this->buildCargoes($pickup),
|
||||||
"receiverContactRequest" => [
|
"receiverContactRequest" => [
|
||||||
'receiverName' => $pickupData['recipient_name'] ?? '',
|
'receiverName' => $pickupData['recipient_name'] ?? '',
|
||||||
@ -141,7 +139,7 @@ class JingDongService
|
|||||||
//"pickUpStartTime" => Carbon::today()->startOfDay()->addHours(19)->toDateTimeString(),
|
//"pickUpStartTime" => Carbon::today()->startOfDay()->addHours(19)->toDateTimeString(),
|
||||||
//"pickUpEndTime" => Carbon::today()->startOfDay()->addHours(21)->toDateTimeString(),
|
//"pickUpEndTime" => Carbon::today()->startOfDay()->addHours(21)->toDateTimeString(),
|
||||||
];
|
];
|
||||||
dd($body);
|
|
||||||
$response = $this->request($body, $path);
|
$response = $this->request($body, $path);
|
||||||
return $response['data'];
|
return $response['data'];
|
||||||
|
|
||||||
@ -162,6 +160,27 @@ class JingDongService
|
|||||||
return $response['data'];
|
return $response['data'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function pullData(Waybill $pickup)
|
||||||
|
{
|
||||||
|
//云打印
|
||||||
|
$this->domain = "jdcloudprint";
|
||||||
|
$path = "/PullDataService/pullData";
|
||||||
|
$pickupData = $pickup->toArray();
|
||||||
|
$body = [
|
||||||
|
"cpCode" => "JD",
|
||||||
|
"wayBillInfos" => [[
|
||||||
|
'orderNo' => $pickupData['order_sn'],
|
||||||
|
'jdWayBillCode' => $pickupData['waybill_code'],
|
||||||
|
]],
|
||||||
|
"parameters" => ["ewCustomerCode" => $this->customerCode],
|
||||||
|
"objectId" => $pickupData['object_id'],
|
||||||
|
];
|
||||||
|
$response = $this->request($body, $path);
|
||||||
|
|
||||||
|
return $response['prePrintDatas'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function queryOrder(Waybill $pickup)
|
public function queryOrder(Waybill $pickup)
|
||||||
{
|
{
|
||||||
$path = "/ecap/v1/orders/details/query";
|
$path = "/ecap/v1/orders/details/query";
|
||||||
|
|||||||
@ -8,22 +8,14 @@ use App\Models\ShopSender;
|
|||||||
use App\Models\ShopShip;
|
use App\Models\ShopShip;
|
||||||
use App\Models\Waybill;
|
use App\Models\Waybill;
|
||||||
use App\Services\Business\KuaiTuanTuan\FaceSheet;
|
use App\Services\Business\KuaiTuanTuan\FaceSheet;
|
||||||
use App\Services\Ship\JingDong\JingDongService;
|
|
||||||
|
|
||||||
class WayBillService
|
class WayBillService
|
||||||
{
|
{
|
||||||
public $orders;
|
public $orders;
|
||||||
public $objectId;
|
public $objectId;
|
||||||
public $adminUser;
|
public $adminUser;
|
||||||
// 快递便携式一联单
|
|
||||||
public $sfOne = 'https://file-link.pinduoduo.com/sf_one';
|
|
||||||
public $sfOneTemplate = 'sf_one1688973997895.xml';
|
|
||||||
// 快递三联面单
|
|
||||||
public $sfThree = 'https://file-link.pinduoduo.com/sf_three';
|
|
||||||
public $sfThreeTemplate = 'sf_three1677381064344.xml';
|
|
||||||
// 标准模板
|
// 标准模板
|
||||||
public $sfStd = 'https://file-link.pinduoduo.com/sf_std';
|
public $templateUrl = 'https://template-content.jd.com/template-oss?tempCode=jdkd76x130';
|
||||||
public $sfStdTemplate = 'sf_std1677380804913.xml';
|
|
||||||
// 时效类型
|
// 时效类型
|
||||||
public $timedDeliveryCode;
|
public $timedDeliveryCode;
|
||||||
|
|
||||||
@ -36,61 +28,35 @@ class WayBillService
|
|||||||
// 已下单过的订单不再下单
|
// 已下单过的订单不再下单
|
||||||
$contents = [];
|
$contents = [];
|
||||||
$this->adminUser = auth('api')->user();
|
$this->adminUser = auth('api')->user();
|
||||||
|
$jingDongService = new JingDongService();
|
||||||
foreach ($this->orders as $shopId => $order) {
|
foreach ($this->orders as $shopId => $order) {
|
||||||
// 订单取消的情况暂不处理
|
// 订单取消的情况暂不处理
|
||||||
$shopSend = $this->getShopSend($shopId);
|
$shopSend = $this->getShopSend($shopId);
|
||||||
foreach ($order as $item) {
|
foreach ($order as $item) {
|
||||||
[$sender, $orderInfo, $senderConfig] = $this->prepareRequest($item, $shopSend);
|
[$sender, $orderInfo, $senderConfig] = $this->prepareRequest($item, $shopSend);
|
||||||
$waybill = $this->saveWayBill($item, $shopSend, $senderConfig);
|
$waybill = $this->saveWayBill($item, $shopSend, $senderConfig);
|
||||||
if (empty($waybill->id)) {
|
if (empty($waybill->waybill_code)) {
|
||||||
$jingDongService = new JingDongService();
|
|
||||||
$resp = $jingDongService->createOrder($waybill);
|
$resp = $jingDongService->createOrder($waybill);
|
||||||
|
if (isset($resp['waybillNo'])) {
|
||||||
if (isset($resp['pdd_waybill_get_response'])) {
|
$waybill->waybill_code = $resp['waybillNo'];
|
||||||
$data = $resp['pdd_waybill_get_response']['modules'][0];
|
|
||||||
$printData = json_decode($data['print_data'], true);
|
|
||||||
$waybill->request_id = $resp['pdd_waybill_get_response']['request_id'];
|
|
||||||
$waybill->encryptedData = $printData['encryptedData'];
|
|
||||||
$waybill->signature = $printData['signature'];
|
|
||||||
$waybill->templateUrl = $printData['templateUrl'];
|
|
||||||
$waybill->ver = $printData['ver'];
|
|
||||||
$waybill->waybill_code = $data['waybill_code'];
|
|
||||||
$waybill->save();
|
$waybill->save();
|
||||||
// 返回待打印内容
|
//物流发货
|
||||||
$contents[$waybill->id] = [
|
event(new CreateLogisticEvent($order->shop_id, $waybill->order_sn, $waybill->waybill_code));
|
||||||
'addData' => [
|
|
||||||
'sender' => $sender,
|
|
||||||
],
|
|
||||||
'encryptedData' => $printData['encryptedData'],
|
|
||||||
'signature' => $printData['signature'],
|
|
||||||
'templateUrl' => env('APP_URL') . '/ktt/' . $this->sfOneTemplate, // 电子面单模板
|
|
||||||
'ver' => $printData['ver'],
|
|
||||||
'userid' => $waybill->user_id,
|
|
||||||
'items' => $item['items'],
|
|
||||||
'documentID' => $waybill->id,
|
|
||||||
'order_id' => $item['id'],
|
|
||||||
'participate_no' => $waybill->participate_no,
|
|
||||||
'note' => $waybill->note,
|
|
||||||
];
|
|
||||||
event(new CreateLogisticEvent($shopShip->shop_id, $waybill->order_sn, $data['waybill_code']));
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$contents[$waybill->id] = [
|
|
||||||
'addData' => [
|
|
||||||
'sender' => $sender,
|
|
||||||
],
|
|
||||||
'encryptedData' => $waybill->encryptedData,
|
|
||||||
'signature' => $waybill->signature,
|
|
||||||
'templateUrl' => env('APP_URL') . '/ktt/' . $this->sfOneTemplate, // 电子面单模板
|
|
||||||
'ver' => $waybill->ver,
|
|
||||||
'userid' => $waybill->user_id,
|
|
||||||
'items' => json_decode($waybill->items, true),
|
|
||||||
'documentID' => $waybill->id,
|
|
||||||
'order_id' => $item['id'],
|
|
||||||
'participate_no' => $waybill->participate_no,
|
|
||||||
'note' => $waybill->note,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
//返回面单待打印数据
|
||||||
|
if (empty($waybill->encryptedData)) {
|
||||||
|
// 延时0.5秒 防止订单查询不到
|
||||||
|
usleep(0.5 * 1000000);
|
||||||
|
$resp = $jingDongService->pullData($waybill);
|
||||||
|
if (!empty($resp[0]['perPrintData'])) {
|
||||||
|
$waybill->templateUrl = $this->templateUrl;
|
||||||
|
$waybill->encryptedData = $resp[0]['perPrintData'];
|
||||||
|
$waybill->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$contents[$item['id']] = $waybill;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +95,7 @@ class WayBillService
|
|||||||
['order_sn' => $order['order_sn']]
|
['order_sn' => $order['order_sn']]
|
||||||
);
|
);
|
||||||
|
|
||||||
$waybill->shop_id = $order->shop_id;
|
$waybill->shop_id = $order['shop_id'];
|
||||||
$waybill->object_id = $this->objectId;
|
$waybill->object_id = $this->objectId;
|
||||||
|
|
||||||
$waybill->sender_country = $senderConfig['country'];
|
$waybill->sender_country = $senderConfig['country'];
|
||||||
@ -138,7 +104,7 @@ class WayBillService
|
|||||||
$waybill->sender_district = $senderConfig['district'];
|
$waybill->sender_district = $senderConfig['district'];
|
||||||
$waybill->sender_detail = $senderConfig['detail'];
|
$waybill->sender_detail = $senderConfig['detail'];
|
||||||
$waybill->sender_name = $senderConfig['name'];
|
$waybill->sender_name = $senderConfig['name'];
|
||||||
$waybill->sender_mobile = $senderConfig['mobile'];
|
$waybill->sender_mobile = (int)$senderConfig['mobile'];
|
||||||
|
|
||||||
$waybill->recipient_province = $order['recipient_province'];
|
$waybill->recipient_province = $order['recipient_province'];
|
||||||
$waybill->recipient_city = $order['recipient_city'];
|
$waybill->recipient_city = $order['recipient_city'];
|
||||||
@ -154,7 +120,7 @@ class WayBillService
|
|||||||
$waybill->participate_no = $order['participate_no'];
|
$waybill->participate_no = $order['participate_no'];
|
||||||
$waybill->note = $order['note'];
|
$waybill->note = $order['note'];
|
||||||
$waybill->items = json_encode($order['items'], 256);
|
$waybill->items = json_encode($order['items'], 256);
|
||||||
|
$waybill->save();
|
||||||
return $waybill;
|
return $waybill;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +197,7 @@ class WayBillService
|
|||||||
'name' => $order['recipient_name'],
|
'name' => $order['recipient_name'],
|
||||||
'mobile' => $order['recipient_mobile'],
|
'mobile' => $order['recipient_mobile'],
|
||||||
],
|
],
|
||||||
'template_url' => $this->sfOne,
|
'template_url' => $this->templateUrl,
|
||||||
];
|
];
|
||||||
|
|
||||||
return [$sender, $orderInfo, $senderConfig];
|
return [$sender, $orderInfo, $senderConfig];
|
||||||
@ -251,6 +217,7 @@ class WayBillService
|
|||||||
foreach ($orders as $order) {
|
foreach ($orders as $order) {
|
||||||
$info = [
|
$info = [
|
||||||
'id' => $order['id'],
|
'id' => $order['id'],
|
||||||
|
'shop_id' => $order['shop_id'],
|
||||||
'order_sn' => $order['order_sn'],
|
'order_sn' => $order['order_sn'],
|
||||||
'recipient_province' => $order['receiver_address_province'],
|
'recipient_province' => $order['receiver_address_province'],
|
||||||
'recipient_city' => $order['receiver_address_city'],
|
'recipient_city' => $order['receiver_address_city'],
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class DefaultExecutor implements Executor
|
|||||||
$uri = $this->baseUri . $request->getPath();
|
$uri = $this->baseUri . $request->getPath();
|
||||||
$httpRequest = new Request($request->getMethod(), $uri, $request->getHeaders(), $request->getBody());
|
$httpRequest = new Request($request->getMethod(), $uri, $request->getHeaders(), $request->getBody());
|
||||||
|
|
||||||
$client = new Client();
|
$client = new Client(['verify' => false]);
|
||||||
try {
|
try {
|
||||||
$httpResponse = $client->send($httpRequest, [
|
$httpResponse = $client->send($httpRequest, [
|
||||||
"query" => $request->getQueries(),
|
"query" => $request->getQueries(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user