20240120-ljl-routeConfig
ljl 10 months ago
parent f8b84a7183
commit 8c35349d68

@ -221,4 +221,30 @@ class OrderPrintController extends AbstractApiController {
$skuList = $this->orderPrintService->getHotSkuListByGoodsId($this->mallId, $_GET);
return $this->renderSuccess(['skuList' => $skuList]);
}
/**
* @api POST 订单报备
* @param string[] orderSns 订单编号
*/
public function retryReportOrder() {
$this->orderPrintService->retryReportOrder($_POST['orderSns'], CommonTool::getOperatorInfo());
return $this->renderSuccess();
}
/**
* @api GET 导出商家备注模板
*/
public function downloadImportSellerMemoTpl() {
$this->orderService->downloadImportSellerMemoTpl();
}
/**
* @api GET 导入商家备注
* @param file file 导入文件
*/
public function importSellerMemo() {
$file = CommonTool::uploadFileSafe('file', CommonTool::getUuidName());
$data = $this->orderService->importSellerMemo($file, CommonTool::getOperatorInfo());
return $this->renderSuccess($data);
}
}

@ -14,6 +14,7 @@ use Dao\Order\OpOrderMapDao;
use Dao\Order\OpOrderRiskDao;
use Dao\Order\PurchaseOrderFastPositionLogDao;
use Dao\Order\SearchConditionLogDao;
use Dao\OrderPrint\OpOrderWaybillTypeReportDao;
use Dao\OrderPrint\OpPageSettingDao;
use Dao\OrderPrint\OpPrintExpressLogDao;
use Dao\OrderPrint\OpPrintExpressLogOrderDao;
@ -31,6 +32,7 @@ use PddApi;
use PermissionTool;
use PurchaseOrderConst;
use Repository\Mall\MallOpRepository;
use Repository\Order\OrderDecryptRepository;
use Repository\OrderPrint\ExpressTplRepository;
use Repository\OrderPrint\OrderPrintRepository;
use Service\AbstractService;
@ -39,9 +41,6 @@ use ZcArrayHelper;
use ZcDateHelper;
class OrderPrintService extends AbstractService {
private $mallOpRepository;
private $orderPrintRepository;
private $areaDao;
private $mallSDao;
private $opOrderDao;
@ -58,12 +57,15 @@ class OrderPrintService extends AbstractService {
private $opPrintExpressLogOrderDao;
private $opPrintExpressLogWaybillDao;
private $purchaseOrderFastPositionLogDao;
private $opOrderWaybillTypeReportDao;
private $mallOpRepository;
private $orderPrintRepository;
private $expressTplRepository;
private $orderDecryptRepository;
protected function __construct() {
$this->mallOpRepository = MallOpRepository::instance();
$this->orderPrintRepository = OrderPrintRepository::instance();
$this->areaDao = AreaDao::instance();
$this->mallSDao = MallSDao::instance();
@ -81,8 +83,12 @@ class OrderPrintService extends AbstractService {
$this->opPrintExpressLogOrderDao = OpPrintExpressLogOrderDao::instance();
$this->opPrintExpressLogWaybillDao = OpPrintExpressLogWaybillDao::instance();
$this->purchaseOrderFastPositionLogDao = PurchaseOrderFastPositionLogDao::instance();
$this->opOrderWaybillTypeReportDao = OpOrderWaybillTypeReportDao::instance();
$this->mallOpRepository = MallOpRepository::instance();
$this->orderPrintRepository = OrderPrintRepository::instance();
$this->expressTplRepository = ExpressTplRepository::instance();
$this->orderDecryptRepository = OrderDecryptRepository::instance();
}
public function searchOrderList($params, $operatorInfo) {
@ -882,4 +888,21 @@ class OrderPrintService extends AbstractService {
$skuList = $this->opOrderDao->getHotSkuListByGoodsId($authMallIds, $goodsId);
return $skuList;
}
public function retryReportOrder($orderSns, $operatorInfo) {
if (empty($orderSns)){
throw new CheckClientException('请选择需要报备的订单');
}
if (!AppConst::isOpAppCategory() && !AppConst::isJxcAppCategory()) {
throw new CheckClientException('该应用无需调用该解决');
}
$waybillType = OrderPrintConst::waybillTypeOther;
$orderSns = CommonTool::convertValToArray($orderSns);
$hasReportOrderSns = $this->opOrderWaybillTypeReportDao->getHasReportByOrderSns($orderSns);
$needReportOrderSns = array_diff($orderSns, $hasReportOrderSns);
if (empty($needReportOrderSns)){
return;
}
$this->orderDecryptRepository->reportOpOrdersWaybillType($needReportOrderSns, $waybillType, $operatorInfo['mallId'], $operatorInfo['accessToken']);
}
}

@ -13,11 +13,15 @@ use Dao\Order\OpOrderInsensitiveInfoDao;
use Dao\Order\OpOrderMallRemarkUpdateLogDao;
use Dao\Order\OpOrderRemarkTagDao;
use DbTool;
use ExcelTool;
use Exception;
use Exception\BizException;
use Exception\CheckClientException;
use OrderPrintConst;
use OrderPrintTool;
use PddApi;
use PermissionTool;
use PHPExcel;
use Service\AbstractService;
use VirtualNumberTool;
use ZcArrayHelper;
@ -351,4 +355,112 @@ class OrderService extends AbstractService {
// TODO analysisDsOrderMerge
}
public function downloadImportSellerMemoTpl() {
$objPHPExcel = new PHPExcel();
$activeSheet = ExcelTool::createNewSheetAndSetTitle($objPHPExcel, 0, '批量导入备注模板');
ExcelTool::setSheetRowValues(
$activeSheet,
1,
['订单号', '商家备注内容', "颜色标记只能填1-5\n(1:红色,2:黄色,3:绿色,4:蓝色,5:紫色)\n不填写默认为空", "是否覆盖原备注\n
(填“是”会覆盖原备注,填“否”或者不填则追加到原备注后面)"]
);
$activeSheet->getColumnDimension('C')->setWidth(60);
$activeSheet->getColumnDimension('D')->setWidth(60);
$activeSheet->getRowDimension('1')->setRowHeight(50);
ExcelTool::downloadExcel($objPHPExcel, '批量导入备注模板');
exit();
}
public function importSellerMemo($file, $operatorInfo) {
$data = $this->parseImportSellerMemoFile($file);
return $this->saveImportSellerMemo($data, $operatorInfo);
}
private function parseImportSellerMemoFile($file) {
ini_set('max_execution_time', 0);
$objPHPExcel = ExcelTool::createPHPExcelFromFile($file);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$data = [];
for ($j = 1; $j <= $highestRow; $j++) {
$data[$j]['orderSn'] = (string)trim($objPHPExcel->getActiveSheet()->getCell("A$j")->getValue());
$data[$j]['remark'] = (string)trim($objPHPExcel->getActiveSheet()->getCell("B$j")->getValue());
$data[$j]['flag'] = (string)trim($objPHPExcel->getActiveSheet()->getCell("C$j")->getValue());
$coverOriginal = (string)trim($objPHPExcel->getActiveSheet()->getCell("D$j")->getValue());
$data[$j]['coverOriginal'] = (!empty($coverOriginal) && $coverOriginal == '是') ? 1 : 0;
}
unlink($file);
unset($data[1]);
return $data;
}
public function saveImportSellerMemo($orderDatas, $operatorInfo) {
$totalOrderSns = array_column($orderDatas, 'orderSn');
if (empty($totalOrderSns)) {
throw new CheckClientException('请先选择一个订单');
}
if(count($totalOrderSns) > 1000) {
throw new CheckClientException('订单数量过多可能造成失败请调整到最多不超过1000个');
}
$orderSnAndOrderRemarkInfoMap = ZcArrayHelper::changeKeyRow($orderDatas, 'orderSn');
$chunkOrderSns = array_chunk($totalOrderSns, 100);
$errors = [];
$successCount = 0;
foreach ($chunkOrderSns as $orderSns) {
$orders = $this->opOrderDao->getListByOrderSns($orderSns);
if (empty($orders)) {
continue;
}
$orderSnAndOrderInfoMap = ZcArrayHelper::changeKeyRow($orders, 'orderSn');
$orderMallIds = array_unique(ZcArrayHelper::getSub($orders, 'mallId'));
$authMalls = PermissionTool::checkMultiShopValid($operatorInfo['mallId'], $orderMallIds);
foreach ($orderDatas as $rowKey => $orderData) {
$orderSn = $orderData['orderSn'];
if (empty($orderSn)) {
$errors[] = $this->buildRowError($rowKey, '订单号为空');
continue;
}
if (empty($orderSnAndOrderInfoMap[$orderSn])) {
$errors[] = $this->buildRowError($rowKey, '订单[' . $orderSn . ']不存在');
continue;
}
$orderRemarkInfo = $orderSnAndOrderRemarkInfoMap[$orderSn];
$orderInfo = $orderSnAndOrderInfoMap[$orderSn];
$flag = (int)$orderRemarkInfo['flag'];
$flag = $flag > 5 ? 5 : ($flag < 0 ? 0 : $flag);
$newRemark = $orderRemarkInfo['coverOriginal'] ? $orderRemarkInfo['remark'] : ($orderInfo['remark'] . $orderRemarkInfo['remark']);
if (mb_strlen($newRemark, 'utf-8') > 200) {
$errors[] = $this->buildRowError($rowKey, '备注信息不能超过200个字');
continue;
}
$orderAccessToken = $authMalls[$orderInfo['mallId']]['accessToken'];
try {
$this->updateOrderRemarkToPdd($orderInfo, $newRemark, $flag, $orderAccessToken, $orderRemarkInfo['coverOriginal'], OrderPrintConst::updateMallRemarkSourceImport, $orderRemarkInfo['remark'], $operatorInfo);
} catch (Exception $e) {
$errors[] = $this->buildRowError($rowKey, $e->getMessage());
continue;
}
$successCount ++;
}
}
return [
'successCount' => $successCount,
'errorCount' => count($errors),
'errors' => $errors
];
}
private function buildRowError($row, $reason) {
return [
'row' => $row,
'reason' => $reason,
];
}
}
Loading…
Cancel
Save