|
|
|
@ -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,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|