20240120-ljl-routeConfig
ljl 10 months ago
parent 7d0417ddc9
commit f8b84a7183

@ -2,18 +2,21 @@
use Service\Order\OrderMergeService;
use Service\Order\OrderPrintService;
use Service\Order\OrderSendService;
use Service\Order\OrderService;
class OrderPrintController extends AbstractApiController {
private $orderPrintService;
private $orderService;
private $orderMergeService;
private $orderSendService;
public function __construct($route) {
parent::__construct($route);
$this->orderService = OrderService::instance();
$this->orderPrintService = OrderPrintService::instance();
$this->orderMergeService = OrderMergeService::instance();
$this->orderSendService = OrderSendService::instance();
}
/**
@ -159,6 +162,33 @@ class OrderPrintController extends AbstractApiController {
return $this->renderSuccess($data);
}
/**
* @api POST 保存打单记录
* @param int expressId 模板id
* @param int logisticsId 模板物流ID
* @param int isPreview 是否预览
* @param int isOutStorage 是否发货
* @param int isRepeatPrintCallback 是否疑似重复打印
* @param string printFrom 打印来源,示例order,purchase,expressLog
* @param trade[] tradeList 订单列表格式同订单列表接口trade需额外传waybillDatasenderAddresspackageIdAndCloudPrintDataMapwlbItemsbatchNumserialNumserialCountprintPackageCountprintPackageId
* @param object printRet 打印结果
* @param string printRet.result 打印状态fail/success
* @param string printRet.reason 打印失败原因
* @param object printRet.tradeKeyAndFailListMap 订单号和失败信息map
* @param object printRet.failList 获取面单失败信息列表
*/
public function updateOrderExpressStatus() {
$updateRet = $this->orderPrintService->updateOrderExpressStatus($_POST, CommonTool::getOperatorInfo());
try {
$outStorageRet = $this->orderSendService->orderOutstorageAfterPrint($_POST, CommonTool::getOperatorInfo());
$outStorageRet = CommonTool::successResult($outStorageRet);
} catch (Exception $e) {
$outStorageRet = CommonTool::failResult($e->getMessage());
}
return $this->renderSuccess(['updateRet' => $updateRet, 'outStorageRet' => $outStorageRet]);
}
/**
* @api POST 快速定位订单
* @param array authMallIds * 授权店铺ID逗号分割示例:16700961 16412356

@ -31,6 +31,7 @@ use PddApi;
use PermissionTool;
use PurchaseOrderConst;
use Repository\Mall\MallOpRepository;
use Repository\OrderPrint\ExpressTplRepository;
use Repository\OrderPrint\OrderPrintRepository;
use Service\AbstractService;
use StatusConst;
@ -58,6 +59,8 @@ class OrderPrintService extends AbstractService {
private $opPrintExpressLogWaybillDao;
private $purchaseOrderFastPositionLogDao;
private $expressTplRepository;
protected function __construct() {
$this->mallOpRepository = MallOpRepository::instance();
$this->orderPrintRepository = OrderPrintRepository::instance();
@ -78,6 +81,8 @@ class OrderPrintService extends AbstractService {
$this->opPrintExpressLogOrderDao = OpPrintExpressLogOrderDao::instance();
$this->opPrintExpressLogWaybillDao = OpPrintExpressLogWaybillDao::instance();
$this->purchaseOrderFastPositionLogDao = PurchaseOrderFastPositionLogDao::instance();
$this->expressTplRepository = ExpressTplRepository::instance();
}
public function searchOrderList($params, $operatorInfo) {
@ -615,17 +620,16 @@ class OrderPrintService extends AbstractService {
public function updateOrderExpressStatus($params, $operatorInfo) {
$mallId = $operatorInfo['mallId'];
$expressData = $params['expressData'];
$expressId = $params['expressId'];
$printRet = $params['printRet'];
$tradeList = $params['tradeList'];
$isPreview = empty($params['isPreview']) ? 0 : 1;
$isOutStorage = CommonTool::isTrue($params['isOutStorage']) ? 1 : 0;
$printFrom = empty($params['printFrom']) ? null : $params['printFrom'];
$tradeKeyAndFailListMap = $printRet['tradeKeyAndFailListMap'] ?: [];
$failList = ZcArrayHelper::changeKeyRow($printRet['failList'], 'tradeKey');
$printFailKeys = array_keys($failList);
$expressTpl = $this->expressTplRepository->getUserExpressTplById($mallId, $expressId);
$printStatus = CommonTool::isFailRet($printRet) ? StatusConst::fail : StatusConst::success;
$printReason = isset($printRet['reason']) ? $printRet['reason'] : null;
$tradeData = [];
@ -634,7 +638,7 @@ class OrderPrintService extends AbstractService {
$wlbCodes = [];
$curPrintStatus = in_array($tradeKey, $printFailKeys) ? StatusConst::fail : $printStatus;
foreach ($trade['wlbItems'] as $wlb) {
if ($wlb['logisticsId'] == $expressData['logistics_id']) {
if ($wlb['logisticsId'] == $expressTpl['logisticsId']) {
$wlbCodes[] = $wlb['wlbCode'];
}
}
@ -660,11 +664,11 @@ class OrderPrintService extends AbstractService {
$tradeData[$tradeKey] = [
'orderIds' => $trade['orderIds'],
'waybillCodes' => $wlbCodes,
'logisticsId' => $expressData['logistics_id'],
'templateId' => $expressData['template_id'],
'expressId' => $expressData['op_user_express_tpl_id'],
'expressType' => $expressData['express_type'],
'waybillType' => $expressData['waybill_type'],
'logisticsId' => $expressTpl['logisticsId'],
'templateId' => $expressTpl['templateId'],
'expressId' => $expressTpl['opUserExpressTplId'],
'expressType' => $expressTpl['expressType'],
'waybillType' => $expressTpl['waybillType'],
'status' => $curPrintStatus,
'reason' => $printReason ?: $trade['waybillFailReason'],
'printPackageCount' => $trade['printPackageCount'],
@ -690,6 +694,7 @@ class OrderPrintService extends AbstractService {
$this->updateExpressPrintStatusByOrder($mallId, $expressId, $tradeKey, $orderInfos[$tradeKey], $trade, $isPreview, $isOutStorage);
$updateRet[$tradeKey] = CommonTool::successResult(array(
'orderId' => $tradeKey,
'logisticsId' => $expressTpl['logisticsId'],
'gmtPrintExpress' => ZcDateHelper::now(),
'printExpressStatus' => OrderPrintConst::pExpressStatusPrinted
));
@ -698,18 +703,7 @@ class OrderPrintService extends AbstractService {
}
}
if ($isOutStorage && 'order' == $printFrom) {
foreach ($tradeList as $key => $row) {
$tradeList[$key]['printExpressLogId'] = $tradeData[$row['tradeKey']]['printExpressLogId'];
}
$outstorageRet = $this->orderOutstorageAfterExpressLog($tradeList, $expressData, array_keys($tradeKeyAndFailListMap), array_column($failList, 'tradeKey'));
} else {
throw new BizException('未达到记日志后发货条件');
}
return [
'updateRet' => $updateRet,
'outstorageRet' => $outstorageRet,
];
return $updateRet;
}
public function updateExpressPrintStatusByOrder($mallId, $expressId, $tradeKey, $orderInfo, $trade, $isPreview, $isOutStorage = 0) {
@ -730,7 +724,7 @@ class OrderPrintService extends AbstractService {
$this->opPrintStatusDao->insertUpdate($printStatusData);
}
$logs = array(
$logs = [
'mall_id' => $orderInfo['mallId'],
'order_id' => $tradeKey,
'order_sn' => $orderInfo['orderSn'],
@ -744,9 +738,8 @@ class OrderPrintService extends AbstractService {
'status' => $trade['status'],
'reason' => $trade['reason'],
'is_preview' => $isPreview,
'is_out_storage' => $isOutStorage,
'gmt_create' => $now
);
'is_out_storage' => $isOutStorage
];
$this->opPrintExpressLogDao->insert( $logs);
$logId = $this->opPrintExpressLogDao->lastInsertId();
@ -758,7 +751,6 @@ class OrderPrintService extends AbstractService {
'mall_id' => $orderInfo['mallId'],
'order_id' => $orderId,
'is_master' => $orderId == $tradeKey ? 1 : 0,
'gmt_create' => $now
);
$filterInfo = [
@ -784,82 +776,6 @@ class OrderPrintService extends AbstractService {
return $logId;
}
private function orderOutstorageAfterExpressLog($tradeList, $expressData, $printFailTradeKeys, $getWaybillFailTradeKeys) {
$deliveryInfos = $this->buildDeliveryInfos($tradeList, $expressData, $printFailTradeKeys, $getWaybillFailTradeKeys);
if ($deliveryInfos) {
$_POST['deliveryInfos'] = $deliveryInfos;
$_POST['source'] = 'print_after';
$_POST['isSendAgain'] = '0';
$_POST['logisticsId'] = $expressData['logistics_id'];
$_POST['sendMethod'] = 'online';
$_POST['expressId'] = $expressData['op_user_express_tpl_id'];
return $this->orderOutstorage(true);
}
return CommonTool::failResult('没有需要发货的订单');
}
private function buildDeliveryInfos($tradeList, $expressData, $printFailTradeKeys, $getWaybillFailTradeKeys) {
$logger = \Zc::getLog('outstorage');
$deliveryInfos = [];
$orderIds = [];
foreach ($tradeList as $trade) {
$waybillCode = '';
$tradeKey = $trade['tradeKey'];
$orderIds = array_merge($orderIds, $trade['orderIds']);
if (in_array($tradeKey, $printFailTradeKeys)) {
$logger->info("$tradeKey in printFailTradeKeys");
continue;
}
if (in_array($tradeKey, $getWaybillFailTradeKeys)) {
$logger->info("$tradeKey in getWaybillFailTradeKeys");
continue;
}
foreach ($trade['wlbItems'] as $wlb) {
if ($wlb['logisticsId'] == $expressData['logistics_id'] && $wlb['wlbCode']) {
$waybillCode = $wlb['wlbCode'];
$packageCount = $wlb['packageCount'];
break;
}
}
if (empty($waybillCode)) {
$logger->info("$tradeKey waybillCodeEmpty");
continue;
}
$items = [];
foreach ($trade['orders'] as $order) {
foreach ($order['items'] as $item) {
$items[] = $item;
}
}
$orderIdAndItemsMap = ZcArrayHelper::changeKey($items, 'orderId', true);
foreach ($trade['orderIds'] as $orderId) {
$orderItems = $orderIdAndItemsMap[$orderId];
$orderItemIds = ZcArrayHelper::getSub($orderItems, 'itemId');
$deliveryInfo = [
'tradeKey' => $tradeKey,
'orderId' => $orderId,
'logisticsId' => $expressData['logistics_id'],
'expressNo' => $waybillCode,
'itemIds' => $orderItemIds,
'printExpressLogId' => $trade['printExpressLogId'],
];
$deliveryInfos[] = $deliveryInfo;
}
}
if (empty($deliveryInfos)) {
$logger->info("tradeKeyAndWaybillInfoMap empty " . implode(',', $orderIds));
}
return $deliveryInfos;
}
public function getHotGoodsList($mallId, $params) {
$authMallIds = $params['authMallIds'];
if ($authMallIds) {
@ -947,7 +863,6 @@ class OrderPrintService extends AbstractService {
array_push($goodsIdAndGoodsInfoMap[$goodsId]['orderIds'], $opOrderGood['orderId']);
$goodsIdAndGoodsInfoMap[$goodsId]['salesCount'] += 1;
}
}
$returnOpOrderGoods = array_values($goodsIdAndGoodsInfoMap);

@ -544,8 +544,8 @@ class OrderSendService extends AbstractService {
return [
'retList' => $retList,
'fCnt' => $fCnt,
'sCnt' => $sCnt
'fCnt' => $fCnt,
'sCnt' => $sCnt
];
}
@ -941,4 +941,85 @@ class OrderSendService extends AbstractService {
'retList' => $retList
];
}
public function orderOutstorageAfterPrint($params, $operatorInfo) {
$isOutStorage = CommonTool::isTrue($params['isOutStorage']) ? 1 : 0;
$printFrom = empty($params['printFrom']) ? null : $params['printFrom'];
$printRet = $params['printRet'];
$logisticsId = $params['logisticsId'];
$tradeList = $params['tradeList'];
$tradeKeyAndFailListMap = $printRet['tradeKeyAndFailListMap'] ?: [];
$failList = ZcArrayHelper::changeKeyRow($printRet['failList'], 'tradeKey');
if (!$isOutStorage || 'order' != $printFrom) {
throw new BizException('未达到记日志后发货条件');
}
$deliveryInfos = $this->buildDeliveryInfos($tradeList, $logisticsId, array_keys($tradeKeyAndFailListMap), array_column($failList, 'tradeKey'));
if (empty($deliveryInfos)) {
throw new BizException('没有需要发货的订单');
}
return $this->orderOutstorage($deliveryInfos, 'print_after', $operatorInfo, true);
}
private function buildDeliveryInfos($tradeList, $logisticsId, $printFailTradeKeys, $getWaybillFailTradeKeys) {
$logger = \Zc::getLog('outstorage');
$deliveryInfos = [];
$orderIds = [];
foreach ($tradeList as $trade) {
$waybillCode = '';
$tradeKey = $trade['tradeKey'];
$orderIds = array_merge($orderIds, $trade['orderIds']);
if (in_array($tradeKey, $printFailTradeKeys)) {
$logger->info("$tradeKey in printFailTradeKeys");
continue;
}
if (in_array($tradeKey, $getWaybillFailTradeKeys)) {
$logger->info("$tradeKey in getWaybillFailTradeKeys");
continue;
}
foreach ($trade['wlbItems'] as $wlb) {
if ($wlb['logisticsId'] == $logisticsId && $wlb['wlbCode']) {
$waybillCode = $wlb['wlbCode'];
$packageCount = $wlb['packageCount'];
break;
}
}
if (empty($waybillCode)) {
$logger->info("$tradeKey waybillCodeEmpty");
continue;
}
$items = [];
foreach ($trade['orders'] as $order) {
foreach ($order['items'] as $item) {
$items[] = $item;
}
}
$orderIdAndItemsMap = ZcArrayHelper::changeKey($items, 'orderId', true);
foreach ($trade['orderIds'] as $orderId) {
$orderItems = $orderIdAndItemsMap[$orderId];
$orderItemIds = ZcArrayHelper::getSub($orderItems, 'itemId');
$deliveryInfo = [
'tradeKey' => $tradeKey,
'orderId' => $orderId,
'logisticsId' => $logisticsId,
'expressNo' => $waybillCode,
'itemIds' => $orderItemIds,
'printExpressLogId' => $trade['printExpressLogId'],
];
$deliveryInfos[] = $deliveryInfo;
}
}
if (empty($deliveryInfos)) {
$logger->info("tradeKeyAndWaybillInfoMap empty " . implode(',', $orderIds));
}
return $deliveryInfos;
}
}
Loading…
Cancel
Save