20240120-ljl-routeConfig
parent
38b699093d
commit
e9fee5eb55
@ -1,302 +0,0 @@
|
||||
<?php
|
||||
|
||||
class FdsOrderPrintController extends AbstractApiController {
|
||||
|
||||
/**
|
||||
* @var MallService
|
||||
*/
|
||||
private $mallService;
|
||||
|
||||
/**
|
||||
* @var OrderPrintService
|
||||
*/
|
||||
private $orderPrintService;
|
||||
|
||||
/**
|
||||
* @var OrderPrintUtil
|
||||
*/
|
||||
private $orderPrintUtil;
|
||||
|
||||
/**
|
||||
* @var OpFdsOrderService
|
||||
*/
|
||||
private $opFdsOrderService;
|
||||
|
||||
public function __construct($route) {
|
||||
parent::__construct($route);
|
||||
|
||||
$this->mallService = Zc::singleton('MallService');
|
||||
$this->orderPrintService = Zc::singleton('OrderPrintService');
|
||||
$this->opFdsOrderService = Zc::singleton('OpFdsOrderService');
|
||||
|
||||
$this->orderPrintUtil = Zc::singleton('OrderPrintUtil');
|
||||
|
||||
if(!$this->mallService->checkIsMallRoleFactory($this->mallId)){
|
||||
$this->redirect('',404);
|
||||
}
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$subAccountId = $_SESSION[SessionConst::mallSubAccountId];
|
||||
$this->orderPrintService->initRtExpressTpl($this->mallId, $this->accessToken);
|
||||
$this->orderPrintService->initRtInvoiceTpl($this->mallId);
|
||||
|
||||
$opSetting = $this->orderPrintService->getUserOpSetting($this->mallId);
|
||||
$opPageSetting = $this->orderPrintService->getUserOpPageSetting($this->mallId, $subAccountId);
|
||||
|
||||
$senderAddress = $this->orderPrintService->getUserDefaultSenderAddress($this->mallId);
|
||||
|
||||
$defaultPageSize = $this->orderPrintService->getDefaultOpPageSize($opSetting, $opPageSetting);
|
||||
$defaultSortType = $this->orderPrintService->getDefaultFdsOrderSortType($opSetting, $opPageSetting);
|
||||
|
||||
$this->opFdsOrderService->tryRsyncOpFdsOrder($this->mallId, $opSetting['rsync_fds_order_days']);
|
||||
|
||||
$this->render(array(
|
||||
'defaultPageSize' => $defaultPageSize,
|
||||
'defaultSortType' => $defaultSortType,
|
||||
'opSetting' => $opSetting,
|
||||
'opPageSetting' => $opPageSetting,
|
||||
'printOrderPageSizeArray' => OrderPrintTool::getPrintOrderPageSizeArray(),
|
||||
'senderAddress' => $senderAddress
|
||||
));
|
||||
}
|
||||
|
||||
public function searchFdsOrderList(){
|
||||
$page = $_POST['page'] > 0 ? (int)$_POST['page'] : 1;
|
||||
$subAccountId = $_SESSION[SessionConst::mallSubAccountId] ?: 0;
|
||||
|
||||
$printOrderPageSizeArray = OrderPrintTool::getPrintOrderPageSizeArray();
|
||||
$pageSize = in_array($_POST['pageSize'], $printOrderPageSizeArray) ? $_POST['pageSize'] : $printOrderPageSizeArray[0];
|
||||
$this->orderPrintService->saveMallPrintOrderPageSize($this->mallId, $subAccountId, $pageSize);
|
||||
|
||||
$printOrderSortTypeArray = array_keys(OrderPrintTool::getFdsOrderSortTypeMap());
|
||||
$sortType = in_array($_POST['sortType'], $printOrderSortTypeArray) ? $_POST['sortType'] : $printOrderSortTypeArray[1];
|
||||
|
||||
$this->orderPrintService->saveMallPrintFdsOrderSortType($this->mallId, $subAccountId, $sortType);
|
||||
|
||||
$searchRet = $this->orderPrintUtil->searchFdsOrderList($this->mallId, $_POST, $page, $pageSize);
|
||||
|
||||
if (CommonTool::isFailRet($searchRet)) {
|
||||
return $this->renderJSON($searchRet);
|
||||
}
|
||||
$orderList = $searchRet['orderList'];
|
||||
$total = $searchRet['total'];
|
||||
$pagin = new ZcPagination($total, $pageSize, $page);
|
||||
|
||||
$orderListHtml = $this->renderWithoutLayout(array(
|
||||
'orderList' => $orderList,
|
||||
'pagin' => $pagin,
|
||||
'total' => $total,
|
||||
'orderPrintTab' => $_POST['orderPrintTab'],
|
||||
'isMultiShop' => $_POST['isMultiShop'],
|
||||
), 'order/fds_order_print/order_list', true);
|
||||
|
||||
return $this->renderJSON(CommonTool::successResult(array(
|
||||
'tradeData' => array_values($orderList),
|
||||
'orderListHtml' => $orderListHtml,
|
||||
'total' => $total
|
||||
)));
|
||||
}
|
||||
|
||||
public function updateFdsOrderExpressStatus(){
|
||||
$expressData = $_POST['expressData'];
|
||||
$expressId = $_POST['expressId'];
|
||||
$printRet = $_POST['printRet'];
|
||||
|
||||
$printStatus = CommonTool::isFailRet($printRet) ? StatusConst::fail : StatusConst::success;
|
||||
$printReason = isset($printRet['reason']) ? $printRet['reason'] : null;
|
||||
$tradeData = array();
|
||||
foreach ($_POST['tradeList'] as $trade) {
|
||||
foreach ($trade['orderIds'] as $orderId) {
|
||||
$wlbCodes = array();
|
||||
foreach ($trade['wlbItems'] as $wlb) {
|
||||
if ($wlb['logisticsId'] == $expressData['logistics_id']) {
|
||||
$wlbCodes[] = $wlb['wlbCode'];
|
||||
}
|
||||
}
|
||||
|
||||
$tradeData[$orderId] = array(
|
||||
'op_fds_order_id' => $orderId,
|
||||
'waybill_codes' => $wlbCodes,
|
||||
'logistics_id' => $expressData['logistics_id'],
|
||||
'template_id' => $expressData['template_id'],
|
||||
'express_id' => $expressData['op_user_express_tpl_id'],
|
||||
'express_type' => $expressData['express_type'],
|
||||
'waybill_type' => $expressData['waybill_type'],
|
||||
'status' => $printStatus,
|
||||
'reason' => $printReason,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$updateRet = $this->opFdsOrderService->updateFdsOrderPrintExpressStatus($this->mallId, $expressId, $tradeData);
|
||||
return $this->renderJSON($updateRet);
|
||||
}
|
||||
|
||||
public function saveFdsOrderExpressNo(){
|
||||
$orderId = $_POST['orderId'];
|
||||
$expressNos = $_POST['expressNos'];
|
||||
$logisticsId = $_POST['logisticsId'];
|
||||
$expressType = $_POST['expressType'];
|
||||
$waybillType = (int)$_POST['waybillType'];
|
||||
$newInsureInfoMap = ZcArrayHelper::changeKeyRow($_POST['newInsureInfoList'], 'exporessNo');
|
||||
$needSaveExpressNo = $_POST['needSaveExpressNo'];
|
||||
|
||||
foreach($newInsureInfoMap as &$insureInfo) {
|
||||
$insureInfo['insure'] = $insureInfo['insure'] ? 1 : 0;
|
||||
$insureInfo['insureMoney'] = max(0, floatval($insureInfo['insureMoney']));
|
||||
}
|
||||
|
||||
$order = $this->opFdsOrderService->getOpFdsOrderByFdsOrderId($this->mallId, $orderId);
|
||||
|
||||
if ($needSaveExpressNo) {
|
||||
$ret = $this->opFdsOrderService->saveExpressNo($order['mall_id'], $orderId, $order['order_mask_sn'], $expressNos, $logisticsId, $expressType, $waybillType, $newInsureInfoMap);
|
||||
} else {
|
||||
$ret = $this->opFdsOrderService->updateExpressInsure($this->mallId, $orderId, $logisticsId, $expressType, $waybillType, $newInsureInfoMap);
|
||||
}
|
||||
return $this->renderJSON($ret);
|
||||
}
|
||||
|
||||
public function updateFdsOrderInvoiceStatus(){
|
||||
$orderIds = $_POST['orderIds'];
|
||||
$printRet = $_POST['printRet'];
|
||||
$printStatus = CommonTool::isFailRet($printRet) ? StatusConst::fail : StatusConst::success;
|
||||
$printReason = isset($printRet['reason']) ? $printRet['reason'] : null;
|
||||
$updateRet = $this->opFdsOrderService->updateFdsOrderPrintInvoiceStatus($this->mallId, $orderIds, $printStatus, $printReason);
|
||||
return $this->renderJSON($updateRet);
|
||||
}
|
||||
|
||||
public function returnFdsWaybill(){
|
||||
$orderId = $_POST['orderId'];
|
||||
$waybillCode = explode(',',$_POST['waybillCode'])[0];
|
||||
$logisticsId = $_POST['logisticsId'];
|
||||
$orderInfo = $this->opFdsOrderService->getOpFdsOrderByFdsOrderId($this->mallId, $orderId);
|
||||
if(empty($orderInfo) || (!in_array($orderInfo['return_status'], [StatusConst::normal, StatusConst::fail]))){
|
||||
return $this->renderJSON(CommonTool::failResult('参数错误'));
|
||||
}
|
||||
$returnRet = $this->opFdsOrderService->returnFdsWaybill($orderInfo, $waybillCode, $logisticsId, $this->accessToken);
|
||||
return $this->renderJSON($returnRet);
|
||||
}
|
||||
|
||||
public function cancelReturnFdsWaybill(){
|
||||
$orderId = $_POST['orderId'];
|
||||
$waybillCode = explode(',',$_POST['waybillCode'])[0];
|
||||
$logisticsId = $_POST['logisticsId'];
|
||||
$orderInfo = $this->opFdsOrderService->getOpFdsOrderByFdsOrderId($this->mallId, $orderId);
|
||||
if(empty($orderInfo) || (!in_array($orderInfo['return_status'], [StatusConst::success, StatusConst::cancelFail]))){
|
||||
return $this->renderJSON(CommonTool::failResult('参数错误'));
|
||||
}
|
||||
$cancelReturnRet = $this->opFdsOrderService->cancelReturnFdsWaybill($orderInfo, $waybillCode, $logisticsId, $this->accessToken);
|
||||
return $this->renderJSON($cancelReturnRet);
|
||||
}
|
||||
|
||||
public function expressLog(){
|
||||
$pageNo = $_GET['page'] > 0 ? (int)$_GET['page'] : 1;
|
||||
$pageSize = 20;
|
||||
|
||||
list($logList, $total) = $this->opFdsOrderService->searchFdsExpressPrintLogs($this->mallId, $pageNo, $pageSize);
|
||||
$pagin = new ZcPagination($total, $pageSize, $pageNo);
|
||||
$this->render(array(
|
||||
'logisticsMap' => $this->orderPrintService->getLogisticsMap(),
|
||||
'logList' => $logList,
|
||||
'total' => $total,
|
||||
'pagin' => $pagin
|
||||
));
|
||||
}
|
||||
|
||||
public function invoiceLog(){
|
||||
$pageNo = $_GET['page'] > 0 ? (int)$_GET['page'] : 1;
|
||||
$pageSize = 20;
|
||||
|
||||
list($logList, $total) = $this->opFdsOrderService->searchFdsInvoicePrintLogs($this->mallId, $pageNo, $pageSize);
|
||||
$pagin = new ZcPagination($total, $pageSize, $pageNo);
|
||||
$this->render(array(
|
||||
'logList' => $logList,
|
||||
'total' => $total,
|
||||
'pagin' => $pagin
|
||||
));
|
||||
}
|
||||
|
||||
public function returnLog(){
|
||||
$pageNo = $_GET['page'] > 0 ? (int)$_GET['page'] : 1;
|
||||
$pageSize = 20;
|
||||
|
||||
list($logList, $total) = $this->opFdsOrderService->searchFdsReturnLogs($this->mallId, $pageNo, $pageSize);
|
||||
$pagin = new ZcPagination($total, $pageSize, $pageNo);
|
||||
$this->render(array(
|
||||
'logisticsMap' => $this->orderPrintService->getLogisticsMap(),
|
||||
'logList' => $logList,
|
||||
'total' => $total,
|
||||
'pagin' => $pagin
|
||||
));
|
||||
}
|
||||
|
||||
public function batchReturnFdsWaybill(){
|
||||
$orderWaybillInfos = $_POST['orderWaybillInfos'];
|
||||
if(empty($orderWaybillInfos)){
|
||||
return $this->renderJSON(CommonTool::failResult('请选择订单'));
|
||||
}
|
||||
$orderIds = array_column($orderWaybillInfos, 'orderId');
|
||||
$orderList = $this->opFdsOrderService->getOpFdsOrdersByFdsOrderIds($this->mallId, $orderIds);
|
||||
$failCount = $successCount = 0;
|
||||
$tip = '';
|
||||
foreach ($orderWaybillInfos as $orderWaybillInfo){
|
||||
$orderInfo = $orderList[$orderWaybillInfo['orderId']];
|
||||
if(empty($orderInfo) || (!in_array($orderInfo['return_status'], [StatusConst::normal, StatusConst::fail]))){
|
||||
$tip .= $orderInfo['order_mask_sn'] . '参数错误<br>';
|
||||
$failCount += 1;
|
||||
continue;
|
||||
}
|
||||
$returnRet = $this->opFdsOrderService->returnFdsWaybill($orderInfo, explode(',',$orderWaybillInfo['waybillCode'])[0], $orderWaybillInfo['logisticsId'], $this->accessToken);
|
||||
if(CommonTool::isFailRet($returnRet)){
|
||||
$tip .= $orderInfo['order_mask_sn'] . $returnRet['reason'] .'<br>';
|
||||
$failCount += 1;
|
||||
continue;
|
||||
}
|
||||
$successCount += 1;
|
||||
}
|
||||
if($successCount == 0){
|
||||
return $this->renderJSON(CommonTool::failResult('成功0个,失败'.$failCount.'个'));
|
||||
}
|
||||
$tip = '成功' . $successCount . '个,失败' . $failCount . '个' . $tip;
|
||||
return $this->renderJSON(CommonTool::successResult(['tip' => $tip, 'successCount' => $successCount, 'failCount' => $failCount]));
|
||||
}
|
||||
|
||||
public function batchCancelReturnFdsWaybill(){
|
||||
$orderWaybillInfos = $_POST['orderWaybillInfos'];
|
||||
if(empty($orderWaybillInfos)){
|
||||
return $this->renderJSON(CommonTool::failResult('请选择订单'));
|
||||
}
|
||||
$orderIds = array_column($orderWaybillInfos, 'orderId');
|
||||
$orderList = $this->opFdsOrderService->getOpFdsOrdersByFdsOrderIds($this->mallId, $orderIds);
|
||||
$failCount = $successCount = 0;
|
||||
$tip = '';
|
||||
foreach ($orderWaybillInfos as $orderWaybillInfo){
|
||||
$orderInfo = $orderList[$orderWaybillInfo['orderId']];
|
||||
if(empty($orderInfo) || (!in_array($orderInfo['return_status'], [StatusConst::success, StatusConst::cancelFail]))){
|
||||
$tip .= $orderInfo['order_mask_sn'] . '参数错误<br>';
|
||||
$failCount += 1;
|
||||
continue;
|
||||
}
|
||||
$returnRet = $this->opFdsOrderService->cancelReturnFdsWaybill($orderInfo, explode(',',$orderWaybillInfo['waybillCode'])[0], $orderWaybillInfo['logisticsId'], $this->accessToken);
|
||||
if(CommonTool::isFailRet($returnRet)){
|
||||
$tip .= $orderInfo['order_mask_sn'] . $returnRet['reason'] .'<br>';
|
||||
$failCount += 1;
|
||||
continue;
|
||||
}
|
||||
$successCount += 1;
|
||||
}
|
||||
if($successCount == 0){
|
||||
return $this->renderJSON(CommonTool::failResult('成功0个,失败'.$failCount.'个'));
|
||||
}
|
||||
$tip = '成功' . $successCount . '个,失败' . $failCount . '个' . $tip;
|
||||
return $this->renderJSON(CommonTool::successResult(['tip' => $tip, 'successCount' => $successCount, 'failCount' => $failCount]));
|
||||
}
|
||||
|
||||
public function getMallMaskMap() {
|
||||
$startTime = ZcDateHelper::formatDate($_POST['startTime'] ?: '2000-01-01');
|
||||
$endTime = !$_POST['endTime'] ? date('Y-m-d H:i:s') : ZcDateHelper::formatDate($_POST['endTime'] . ' 23:59:59');
|
||||
$mallMaskMap = $this->opFdsOrderService->getFdsMallMaskMap($this->mallId, $startTime, $endTime);
|
||||
$this->renderJSON(CommonTool::successResult(['mallMaskMap' => $mallMaskMap]));
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\Admin;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class TimerTokenApplyLogDao extends AbstractDao {
|
||||
public function getClientIpByTimerToken($timerToken) {
|
||||
return $this->queryFirstField('SELECT client_ip FROM %b WHERE timer_token = %s AND gmt_expire >= NOW() LIMIT 1', $this->getTable(), $timerToken);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\OrderPrint;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class OpAssemblyTaskDao extends AbstractDao {
|
||||
public function searchPage($mallId, $page, $pageSize) {
|
||||
return $this->queryPage('select * from %b where mall_id = %i order by op_assembly_task_id desc', $this->getTable(), $mallId, $page, $pageSize);
|
||||
}
|
||||
|
||||
public function getProcessingTaskCount($mallId) {
|
||||
return $this->queryFirstField('select count(*) from %b where mall_id = %i and status = %s', $this->getTable(), $mallId, \StatusConst::process);
|
||||
}
|
||||
|
||||
public function checkTaskEnd($mallId, $taskId) {
|
||||
$row = $this->query('select * from %b where op_assembly_task_id = %i and mall_id = %i and status = %s', $this->getTable(), $taskId, $mallId, \StatusConst::finish);
|
||||
return $row ? true : false;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\OrderPrint;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
use Dao\Goods\OpGoodsShortDao;
|
||||
|
||||
class OpAssemblyTaskItemDao extends AbstractDao {
|
||||
public function searchByCursor($maxItemId, $taskId, $mallId, $limit) {
|
||||
$goodsShortTbl = OpGoodsShortDao::tableName();
|
||||
return $this->query('select oati.*, ogs.warehouse, ogs.shelves from %b as oati left join %b ogs on oati.goods_id = ogs.goods_id where oati.op_assembly_task_item_id > %i and oati.op_assembly_task_id = %i and oati.mall_id = %i order by oati.op_assembly_task_id asc limit %i' , $this->getTable(), $goodsShortTbl, $maxItemId, $taskId, $mallId, $limit);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\OrderPrint;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class OpAssemblyTaskStageDao extends AbstractDao {
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\OrderPrint;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class OpWaybillBillLogDao extends AbstractDao {
|
||||
public function searchPage($mallId, $taskId, $page, $pageSize) {
|
||||
return $this->queryPage('select * from %b owbl where owbl.mall_id = %i and owbl.op_waybill_bill_task_id = %i', $this->getTable(), $mallId, $taskId, $page, $pageSize);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\OrderPrint;
|
||||
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class OpWaybillBillQueueDao extends AbstractDao {
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Dao\OrderPrint;
|
||||
|
||||
use CommonTool;
|
||||
use Dao\AbstractDao;
|
||||
|
||||
class OpWaybillBillTaskDao extends AbstractDao {
|
||||
public function searchPage($mallId, $page, $pageSize) {
|
||||
return $this->queryPage('select * from %b where mall_id = %i and is_delete = 0 order by gmt_create desc', $this->getTable(), $mallId, $page, $pageSize);
|
||||
}
|
||||
|
||||
public function getTask($mallId, $taskId) {
|
||||
return $this->queryFirstRow('select owbt.* from %b owbt where owbt.op_waybill_bill_task_id = %i and mall_id = %i', $this->getTable(), $taskId, $mallId);
|
||||
}
|
||||
|
||||
public function getListOfMallByTaskIds($mallId, $taskIds) {
|
||||
$taskIds = is_array($taskIds) ? $taskIds : [$taskIds];
|
||||
return $this->query('select * from %b where mall_id = %i and op_waybill_bill_task_id in %li', $this->getTable(), $mallId, $taskIds);
|
||||
}
|
||||
|
||||
public function deleteMallTask($mallId, $taskId) {
|
||||
if (CommonTool::anyEmpty($mallId, $taskId)) {
|
||||
return false;
|
||||
}
|
||||
$updateData = [
|
||||
'is_delete' => 1,
|
||||
];
|
||||
$result = $this->update($updateData, 'mall_id = %i and op_waybill_bill_task_id = %i', $mallId, $taskId);
|
||||
return $result ? true : false;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Service\AfterSale;
|
||||
|
||||
use Service\AbstractService;
|
||||
|
||||
class AfterSaleService extends AbstractService {
|
||||
|
||||
protected function __construct() {
|
||||
}
|
||||
}
|
@ -0,0 +1,502 @@
|
||||
<?php
|
||||
|
||||
namespace Service\OrderPrint;
|
||||
|
||||
use Dao\Mall\MallSDao;
|
||||
use Dao\Order\OpOrderDao;
|
||||
use Dao\Order\OpOrderGoodsDao;
|
||||
use Dao\Order\SearchConditionLogDao;
|
||||
use Dao\OrderPrint\OpAssemblyTaskDao;
|
||||
use Dao\OrderPrint\OpAssemblyTaskItemDao;
|
||||
use Dao\OrderPrint\OpAssemblyTaskStageDao;
|
||||
use DbTool;
|
||||
use ExcelTool;
|
||||
use Exception\BizException;
|
||||
use OrderConst;
|
||||
use OrderPrintConst;
|
||||
use OrderPrintTool;
|
||||
use PermissionTool;
|
||||
use PHPExcel_Style_Alignment;
|
||||
use PHPExcel_Worksheet_MemoryDrawing;
|
||||
use Service\AbstractService;
|
||||
use StatusConst;
|
||||
use ZcArrayHelper;
|
||||
use ZcDateHelper;
|
||||
|
||||
class AssemblyService extends AbstractService {
|
||||
|
||||
private $mallSDao;
|
||||
private $opOrderDao;
|
||||
private $opOrderGoodsDao;
|
||||
private $opAssemblyTaskDao;
|
||||
private $searchConditionLogDao;
|
||||
private $opAssemblyTaskItemDao;
|
||||
private $opAssemblyTaskStageDao;
|
||||
|
||||
protected function __construct() {
|
||||
$this->mallSDao = MallSDao::instance();
|
||||
$this->opOrderDao = OpOrderDao::instance();
|
||||
$this->opOrderGoodsDao = OpOrderGoodsDao::instance();
|
||||
$this->searchConditionLogDao = SearchConditionLogDao::instance();
|
||||
$this->opAssemblyTaskDao = OpAssemblyTaskDao::instance();
|
||||
$this->opAssemblyTaskItemDao = OpAssemblyTaskItemDao::instance();
|
||||
$this->opAssemblyTaskStageDao = OpAssemblyTaskStageDao::instance();
|
||||
}
|
||||
|
||||
public function searchTradeList($mallId, $params) {
|
||||
set_time_limit('180');
|
||||
$filterCondition = $this->filterOrderConditon($mallId, $params);
|
||||
|
||||
$this->searchConditionLogDao->add($mallId, OrderPrintConst::searchConditionBizCodeAssembly, $params);
|
||||
return $this->searchAssemblyTradeList($filterCondition);
|
||||
}
|
||||
|
||||
private function filterOrderConditon($mallId, $data){
|
||||
$conditon = [];
|
||||
|
||||
$mallIds = [$mallId];
|
||||
if ($data['isMultiShop']) {
|
||||
$mallIds = empty($data['authMallIds']) ? $mallIds : $data['authMallIds'];
|
||||
PermissionTool::checkMultiShopValid($mallId, $data['authMallIds']);
|
||||
}
|
||||
$conditon['authMallIds'] = $mallIds;
|
||||
|
||||
$data['orderStatus'] = array_key_exists($data['orderStatus'], OrderConst::getOrderStatusMap()) ? $data['orderStatus'] : OrderConst::orderStatusWaitSellerSendGoods;
|
||||
|
||||
if (!empty($data['orderSn'])) {
|
||||
$conditon['orderSn'] = $data['orderSn'];
|
||||
}
|
||||
if (!empty($data['waybillCode'])) {
|
||||
$conditon['waybillCode'] = trim($data['waybillCode']);
|
||||
}
|
||||
if (!empty($data['logisticsId'])) {
|
||||
$conditon['logisticsId'] = trim($data['logisticsId']);
|
||||
}
|
||||
if (!empty($data['receiverName'])) {
|
||||
$conditon['receiverName'] = trim($data['receiverName']);
|
||||
}
|
||||
if (!empty($data['receiverPhone']) && ctype_digit($data['receiverPhone'])) {
|
||||
$conditon['receiverPhone'] = trim($data['receiverPhone']);
|
||||
}
|
||||
|
||||
if (!empty($data['orderStartTime'])) {
|
||||
$conditon['orderStartTime'] = ZcDateHelper::formatDate($data['orderStartTime']);
|
||||
}
|
||||
if (!empty($data['orderEndTime']) && ($data['orderEndTime'] >= $data['orderStartTime'])) {
|
||||
$conditon['orderEndTime'] = ZcDateHelper::formatDate($data['orderEndTime']);
|
||||
}
|
||||
|
||||
if ($data['orderStatus'] == OrderConst::orderStatusWaitSellerSendGoods) {
|
||||
$conditon['orderStatus'] = OrderConst::orderStatusWaitSellerSendGoods;
|
||||
} else {
|
||||
$conditon['orderStatus'] = OrderConst::orderStatusWaitBuyerConfirmGoods;
|
||||
}
|
||||
|
||||
$conditon['refundStatus'] = OrderConst::refundStatusNoRefund;
|
||||
|
||||
if (!empty($data['goodsId'])) {
|
||||
$conditon['goodsId'] = $data['goodsId'];
|
||||
}
|
||||
|
||||
if (!empty($data['goodsName'])) {
|
||||
$conditon['goodsName'] = $data['goodsName'];
|
||||
}
|
||||
|
||||
if (!empty($data['sellerMemo'])) {
|
||||
$conditon['sellerMemo'] = trim($data['sellerMemo']);
|
||||
}
|
||||
|
||||
if (!empty($data['buyerMemo'])) {
|
||||
$conditon['buyerMemo'] = trim($data['buyerMemo']);
|
||||
}
|
||||
|
||||
if (array_key_exists($data['pExpressStatus'], OrderPrintConst::getAllKuaidiStatusMap(false))) {
|
||||
$conditon['pExpressStatus'] = trim($data['pExpressStatus']);
|
||||
}
|
||||
|
||||
if (array_key_exists($data['pInvoiceStatus'], OrderPrintConst::getAllFahuoStatusMap(false))) {
|
||||
$conditon['pInvoiceStatus'] = trim($data['pInvoiceStatus']);
|
||||
}
|
||||
|
||||
if(!empty($data['warehouse'])) {
|
||||
$conditon['warehouse'] = trim($data['warehouse']);
|
||||
}
|
||||
|
||||
if(!empty($data['shelves'])) {
|
||||
$conditon['shelves'] = trim($data['shelves']);
|
||||
}
|
||||
|
||||
if (array_key_exists($data['warehouseShelvesSort'], OrderPrintConst::getWareWarehouseShelvesSortTypeMap())) {
|
||||
$conditon['warehouseShelvesSort'] = trim($data['warehouseShelvesSort']);
|
||||
}
|
||||
|
||||
return $conditon;
|
||||
}
|
||||
|
||||
public function searchAssemblyTradeList($filterCondition) {
|
||||
$mallIds = $filterCondition['authMallIds'];
|
||||
list($conditions, $joinTables) = $this->opOrderDao->getSearchOrderCondition($filterCondition, $mallIds);
|
||||
$whereStr = !empty($conditions) ? implode(' ', $conditions) : '';
|
||||
$joinStr = !empty($joinTables) ? implode(' ', $joinTables) : '';
|
||||
|
||||
$items = [];
|
||||
$itemsTotal = 0;
|
||||
$pageSize = 200;
|
||||
$maxOrderId = 0;
|
||||
while (true) {
|
||||
$orderIds = $this->opOrderDao->searchOrderIdsCursor($mallIds, $maxOrderId, $joinStr, $whereStr, $pageSize);
|
||||
if (empty($orderIds)) {
|
||||
break;
|
||||
}
|
||||
$maxOrderId = end($orderIds);
|
||||
$rows = $this->opOrderGoodsDao->searchWithGoodsShort($orderIds, $filterCondition);
|
||||
if (empty($rows)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if (isset($items[$row['goodsId']])) {
|
||||
$item = $items[$row['goodsId']];
|
||||
} else {
|
||||
$item = [
|
||||
'goodsName' => $row['goodsName'],
|
||||
'outerGoodsId' => $row['outerGoodsId'],
|
||||
'outerId' => $row['outerId'],
|
||||
'goodsImg' => $row['goodsImg'],
|
||||
'goodsCount' => 0,
|
||||
'warehouse' => $row['warehouse'],
|
||||
'shelves' => $row['shelves'],
|
||||
'warehouseShelvesKey' => OrderPrintTool::buildWarehouseShelvesKey($row['warehouse'], $row['shelves']),
|
||||
'skus' => []
|
||||
];
|
||||
}
|
||||
$item['goodsCount'] += $row['goodsCount'];
|
||||
$itemsTotal += $row['goodsCount'];
|
||||
$skuId = $row['skuId'];
|
||||
if (isset($item['skus'][$skuId])) {
|
||||
$item['skus'][$skuId]['skuCount'] += $row['goodsCount'];
|
||||
} else {
|
||||
$item['skus'][$skuId] = array(
|
||||
'skuId' => $row['skuId'],
|
||||
'skuName' => $row['goodsName'] . ' ' . $row['goodsSpec'],
|
||||
'goodsSpec' => $row['goodsSpec'],
|
||||
'outerId' => $row['outerId'],
|
||||
'skuCount' => (int)$row['goodsCount']
|
||||
);
|
||||
}
|
||||
$items[$row['goodsId']] = $item;
|
||||
}
|
||||
}
|
||||
foreach ($items as &$goods) {
|
||||
$goods['skus'] = array_values($goods['skus']);
|
||||
}
|
||||
|
||||
$warehouseShelvesAndItemsMap = [];
|
||||
$warehouseShelvesAndItemTotalMap = [];
|
||||
foreach ($items as &$item) {
|
||||
$key = $item['warehouseShelvesKey'];
|
||||
if (!isset($warehouseShelvesAndItemsMap[$key])) {
|
||||
$warehouseShelvesAndItemsMap[$key] = [];
|
||||
}
|
||||
$warehouseShelvesAndItemsMap[$key][] = $item;
|
||||
|
||||
if (!isset($warehouseShelvesAndItemTotalMap[$key])) {
|
||||
$warehouseShelvesAndItemTotalMap[$key] = 0;
|
||||
}
|
||||
$warehouseShelvesAndItemTotalMap[$key] += $item['goodsCount'];
|
||||
}
|
||||
|
||||
switch ($filterCondition['warehouseShelvesSort']) {
|
||||
case OrderPrintConst::wareSortTypeWarehouseShelvesTotalDesc:
|
||||
array_multisort($warehouseShelvesAndItemTotalMap, SORT_DESC , $warehouseShelvesAndItemsMap);
|
||||
break;
|
||||
case OrderPrintConst::wareSortTypeWarehouseShelvesTotalAsc:
|
||||
array_multisort($warehouseShelvesAndItemTotalMap, SORT_ASC, $warehouseShelvesAndItemsMap);
|
||||
break;
|
||||
case OrderPrintConst::wareSortTypeWarehouseShelvesAsc:
|
||||
ksort($warehouseShelvesAndItemsMap);
|
||||
break;
|
||||
}
|
||||
|
||||
return [
|
||||
'warehouseShelvesAndItemsMap' => $warehouseShelvesAndItemsMap,
|
||||
'warehouseShelvesAndItemTotalMap' => $warehouseShelvesAndItemTotalMap,
|
||||
'itemsTotal' => $itemsTotal,
|
||||
'itemsCount' => count($items),
|
||||
];
|
||||
}
|
||||
|
||||
public function searchTaskList($mallId, $params) {
|
||||
$page = intval($params['page'] ?: 1);
|
||||
$pageSize = intval($params['pageSize'] ?: 20);
|
||||
list($list, $total) = $this->opAssemblyTaskDao->searchPage($mallId, $page, $pageSize);
|
||||
$mallIds = [];
|
||||
foreach ($list as &$row) {
|
||||
$row['condition'] = unserialize($row['condition']);
|
||||
$mallIds = array_merge($mallIds, $row['condition']['mallIds']);
|
||||
}
|
||||
$mallIdAndMallNameMap = $this->mallSDao->getMallIdAndMallNameMap($mallIds);
|
||||
foreach ($list as &$row) {
|
||||
$shopNames = array();
|
||||
foreach ($row['condition']['mallIds'] as $mallId) {
|
||||
$shopNames[] = $mallIdAndMallNameMap[$mallId];
|
||||
}
|
||||
$row['shopNames'] = $shopNames;
|
||||
}
|
||||
return [
|
||||
'taskList' => $list,
|
||||
'total' => $total
|
||||
];
|
||||
}
|
||||
|
||||
public function checkAllowAddTask($mallId) {
|
||||
$processTaskCount = $this->opAssemblyTaskDao->getProcessingTaskCount($mallId);
|
||||
if ($processTaskCount) {
|
||||
throw new BizException('还有任务未处理完成');
|
||||
}
|
||||
}
|
||||
|
||||
public function getTask($mallId, $taskId) {
|
||||
$task = $this->opAssemblyTaskDao->getById($taskId);
|
||||
if (empty($task)|| $task['mallId'] != $mallId) {
|
||||
throw new BizException('任务不存在');
|
||||
}
|
||||
if (!empty($task['condition'])) {
|
||||
$task['condition'] = unserialize($task['condition']);
|
||||
}
|
||||
return $task;
|
||||
}
|
||||
|
||||
public function getTaskItemsList($mallId, $taskId) {
|
||||
$items = [];
|
||||
$itemsTotal = 0;
|
||||
|
||||
$pageSize = 500;
|
||||
$maxItemId = 0;
|
||||
do {
|
||||
$rows = $this->opAssemblyTaskItemDao->searchByCursor($maxItemId, $taskId, $mallId, $pageSize);
|
||||
if (empty($rows)) {
|
||||
break;
|
||||
}
|
||||
$maxItemId = ZcArrayHelper::getValue(end($rows), 'opAssemblyTaskItemId');
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if (isset($items[$row['goodsId']])) {
|
||||
$item = $items[$row['goodsId']];
|
||||
} else {
|
||||
$item = array(
|
||||
'goodsName' => $row['goodsName'],
|
||||
'outerGoodsId' => $row['outerGoodsId'],
|
||||
'outerId' => $row['outerId'],
|
||||
'goodsImg' => $row['goodsImg'],
|
||||
'goodsCount' => 0,
|
||||
'warehouse' => $row['warehouse'],
|
||||
'shelves' => $row['shelves'],
|
||||
'warehouseShelvesKey' => OrderPrintTool::buildWarehouseShelvesKey($row['warehouse'], $row['shelves']),
|
||||
'skus' => []
|
||||
);
|
||||
}
|
||||
$item['goodsCount'] += $row['skuCount'];
|
||||
$itemsTotal += $row['skuCount'];
|
||||
$skuId = $row['skuId'];
|
||||
if (isset($item['skus'][$skuId])) {
|
||||
$item['skus'][$skuId]['skuCount'] += $row['skuCount'];
|
||||
} else {
|
||||
$item['skus'][$skuId] = array(
|
||||
'skuName' => $row['skuName'],
|
||||
'goodsSpec' => $row['goodsSpec'],
|
||||
'outerId' => $row['outerId'],
|
||||
'skuCount' => (int)$row['skuCount']
|
||||
);
|
||||
}
|
||||
$items[$row['goodsId']] = $item;
|
||||
}
|
||||
} while(true);
|
||||
|
||||
foreach ($items as &$item) {
|
||||
$item['skus'] = array_values($item['skus']);
|
||||
}
|
||||
|
||||
$warehouseShelvesAndItemsMap = array();
|
||||
$warehouseShelvesAndItemTotalMap = array();
|
||||
foreach ($items as &$item) {
|
||||
$key = $item['warehouseShelvesKey'];
|
||||
if (!isset($warehouseShelvesAndItemsMap[$key])) {
|
||||
$warehouseShelvesAndItemsMap[$key] = array();
|
||||
}
|
||||
$warehouseShelvesAndItemsMap[$key][] = $item;
|
||||
|
||||
if (!isset($warehouseShelvesAndItemTotalMap[$key])) {
|
||||
$warehouseShelvesAndItemTotalMap[$key] = 0;
|
||||
}
|
||||
$warehouseShelvesAndItemTotalMap[$key] += $item['goodsCount'];
|
||||
}
|
||||
|
||||
return [
|
||||
'warehouseShelvesAndItemsMap' => $warehouseShelvesAndItemsMap,
|
||||
'warehouseShelvesAndItemTotalMap' => $warehouseShelvesAndItemTotalMap,
|
||||
'itemsTotal' => $itemsTotal,
|
||||
'itemsCount' => count($items)
|
||||
];
|
||||
}
|
||||
|
||||
public function saveAssemblyTask($mallId, $params) {
|
||||
$condition = $this->filterOrderConditon($mallId, $params);
|
||||
$condition['mallIds'] = $params['authMallIds'];
|
||||
$isRsyncOrder = $params['isRsyncOrder'] ? 1 : 0;
|
||||
|
||||
$this->checkAllowAddTask($mallId);
|
||||
$this->addOpAssemblyTask($mallId, $condition, $isRsyncOrder);
|
||||
}
|
||||
|
||||
public function addOpAssemblyTask($mallId, $condition, $isRsyncOrder) {
|
||||
$trans = DbTool::beginTrans(OpAssemblyTaskDao::class);
|
||||
$task = array(
|
||||
'mall_id' => $mallId,
|
||||
'condition' => serialize($condition),
|
||||
'is_rsync_order' => $isRsyncOrder,
|
||||
'status' => StatusConst::process,
|
||||
);
|
||||
$this->opAssemblyTaskDao->insert($task);
|
||||
$opAssemblyTaskId = $this->opAssemblyTaskDao->lastInsertId();
|
||||
if ($isRsyncOrder) {
|
||||
$stageName = OrderPrintConst::assemblyTaskStageRsyncOrder;
|
||||
} else {
|
||||
$stageName = OrderPrintConst::assemblyTaskStageMergeShops;
|
||||
}
|
||||
$stage = array(
|
||||
'op_assembly_task_id' => $opAssemblyTaskId,
|
||||
'mall_id' => $mallId,
|
||||
'stage_name' => $stageName,
|
||||
'status' => StatusConst::wait,
|
||||
'locked' => 0,
|
||||
);
|
||||
$this->opAssemblyTaskStageDao->insert($stage);
|
||||
DbTool::commitTrans($trans);
|
||||
return $opAssemblyTaskId;
|
||||
}
|
||||
|
||||
public function checkAssemblyTaskEnd($mallId, $taskId) {
|
||||
return $this->opAssemblyTaskDao->checkTaskEnd($mallId, $taskId);
|
||||
}
|
||||
|
||||
public function exportAssembly($mallId, $params) {
|
||||
set_time_limit('180');
|
||||
$hideLogo = $params['hideLogo'];
|
||||
$changedItemTotals = $params['changedItemTotals'];
|
||||
$filterCondition = $this->filterOrderConditon($mallId, $params);
|
||||
$tradeList = $this->searchAssemblyTradeList($filterCondition);
|
||||
$warehouseShelvesAndItemsMap = $tradeList['warehouseShelvesAndItemsMap'];
|
||||
$this->doExportAssemblyItems($warehouseShelvesAndItemsMap, $changedItemTotals, $hideLogo);
|
||||
}
|
||||
|
||||
public function exportAssemblyTaskItems($mallId, $taskId, $hideLogo = false) {
|
||||
$list = $this->getTaskItemsList($mallId, $taskId);
|
||||
$warehouseShelvesAndItemsMap = $list['warehouseShelvesAndItemsMap'];
|
||||
$this->doExportAssemblyItems($warehouseShelvesAndItemsMap, false, $hideLogo);
|
||||
}
|
||||
|
||||
private function doExportAssemblyItems($warehouseShelvesAndItemsMap, $changedItemTotals, $hideLogo) {
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', '序号')
|
||||
->setCellValue('B1', '图片')
|
||||
->setCellValue('C1', '商品标题')
|
||||
->setCellValue('D1', '外部商品编码')
|
||||
->setCellValue('E1', '规格')
|
||||
->setCellValue('F1', '数量')
|
||||
->setCellValue('G1', '总数量')
|
||||
->setCellValue('H1','仓库/市场')
|
||||
->setCellValue('I1', '货架/档口');
|
||||
|
||||
$objActSheet = $objPHPExcel->getActiveSheet();
|
||||
$row_num = 2;
|
||||
$index = 1;
|
||||
$defaultRowHeight = 20;
|
||||
foreach ($warehouseShelvesAndItemsMap as $items) {
|
||||
foreach ($items as $item) {
|
||||
$objActSheet->setCellValue('A' . $row_num, $index)
|
||||
->setCellValue('C' . $row_num, $item['goodsName'])
|
||||
->setCellValue('D' . $row_num, $item['outerGoodsId'])
|
||||
->setCellValue('G' . $row_num, $item['goodsCount'])
|
||||
->setCellValue('H' . $row_num, $item['warehouse'])
|
||||
->setCellValue('I' . $row_num, $item['shelves']);
|
||||
|
||||
$skuSerial = 0;
|
||||
$goodsCount = 0;
|
||||
foreach ($item['skus'] as $k => $sku) {
|
||||
$skuCount = $changedItemTotals[$sku['skuId']] ? $changedItemTotals[$sku['skuId']] : $sku['skuCount'];
|
||||
$objActSheet->setCellValue('E' . ($row_num + $skuSerial), $sku['goodsSpec'])
|
||||
->setCellValue('F' . ($row_num + $skuSerial), $skuCount);
|
||||
$skuSerial++;
|
||||
$goodsCount += $skuCount;
|
||||
}
|
||||
$objActSheet->setCellValue('G' . $row_num, $goodsCount);
|
||||
|
||||
$rowHeight = $defaultRowHeight * $skuSerial;
|
||||
if (!$hideLogo && !empty($item['goodsImg'])) {
|
||||
if ($rowHeight < 30) {
|
||||
$objActSheet->getRowDimension($row_num)->setRowHeight(30);
|
||||
}
|
||||
|
||||
$ext = pathinfo($item['goodsImg'], PATHINFO_EXTENSION);
|
||||
switch ($ext) {
|
||||
case 'png':
|
||||
$img = imagecreatefrompng($item['goodsImg']);
|
||||
break;
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
$img = imagecreatefromjpeg($item['goodsImg']);
|
||||
break;
|
||||
case 'gif':
|
||||
$img = imagecreatefromgif($item['goodsImg']);
|
||||
break;
|
||||
}
|
||||
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
|
||||
$objDrawing->setCoordinates('B' . $row_num);
|
||||
$objDrawing->setImageResource($img);
|
||||
$objDrawing->setOffsetX(5);
|
||||
$objDrawing->setOffsetY(5);
|
||||
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT);//渲染方法
|
||||
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
|
||||
$objDrawing->setHeight(30);
|
||||
$objDrawing->setWorksheet($objActSheet);
|
||||
}
|
||||
if ($skuSerial > 1) {
|
||||
$objActSheet->mergeCells('A' . $row_num . ':' . 'A' . ($row_num + $skuSerial - 1));
|
||||
$objActSheet->mergeCells('B' . $row_num . ':' . 'B' . ($row_num + $skuSerial - 1));
|
||||
$objActSheet->mergeCells('C' . $row_num . ':' . 'C' . ($row_num + $skuSerial - 1));
|
||||
$objActSheet->mergeCells('D' . $row_num . ':' . 'D' . ($row_num + $skuSerial - 1));
|
||||
$objActSheet->mergeCells('G' . $row_num . ':' . 'G' . ($row_num + $skuSerial - 1));
|
||||
$objActSheet->mergeCells('H' . $row_num . ':' . 'H' . ($row_num + $skuSerial - 1));
|
||||
$objActSheet->mergeCells('I' . $row_num . ':' . 'I' . ($row_num + $skuSerial - 1));
|
||||
}
|
||||
$row_num += $skuSerial;
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
$objActSheet->getDefaultRowDimension()->setRowHeight($defaultRowHeight);
|
||||
$objActSheet->getRowDimension(1)->setRowHeight(30);
|
||||
$objActSheet->getColumnDimension('A')->setWidth(10);
|
||||
$objActSheet->getColumnDimension('B')->setWidth(6);
|
||||
$objActSheet->getColumnDimension('C')->setWidth(60);
|
||||
$objActSheet->getColumnDimension('D')->setWidth(30);
|
||||
$objActSheet->getColumnDimension('E')->setWidth(30);
|
||||
$objActSheet->getColumnDimension('F')->setWidth(15);
|
||||
$objActSheet->getColumnDimension('G')->setWidth(15);
|
||||
$objActSheet->getColumnDimension('H')->setWidth(15);
|
||||
$objActSheet->getColumnDimension('I')->setWidth(15);
|
||||
$objActSheet->getStyle('A1:I1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
$objActSheet->getStyle('A1:A' . $row_num)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
|
||||
$objActSheet->getStyle('A1:I' . $row_num)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
|
||||
$objActSheet->getStyle('A2:I' . $row_num)->getAlignment()->setWrapText(true);
|
||||
|
||||
if ($hideLogo) {
|
||||
$objActSheet->removeColumn('B');
|
||||
}
|
||||
|
||||
$filename = iconv("utf-8", "gb2312", '配货单-' . date('Ymd'));
|
||||
$objPHPExcel->getActiveSheet()->setTitle('WorKSheet');
|
||||
ExcelTool::downloadExcel($objPHPExcel, $filename);
|
||||
exit;
|
||||
}
|
||||
}
|
@ -0,0 +1,514 @@
|
||||
<?php
|
||||
|
||||
namespace Service\OrderPrint;
|
||||
|
||||
use CommonTool;
|
||||
use Dao\Mall\MallSDao;
|
||||
use Dao\Order\OpOrderDao;
|
||||
use Dao\OrderPrint\OpWaybillBillLogDao;
|
||||
use Dao\OrderPrint\OpWaybillBillQueueDao;
|
||||
use Dao\OrderPrint\OpWaybillBillTaskDao;
|
||||
use Dao\OrderPrint\OpWaybillInfoDao;
|
||||
use Dao\OrderPrint\OpWaybillInfoTradeDao;
|
||||
use DbTool;
|
||||
use ExcelTool;
|
||||
use Exception\BizException;
|
||||
use Exception\CheckClientException;
|
||||
use OrderDecryptTool;
|
||||
use OrderPrintConst;
|
||||
use OssClient;
|
||||
use Repository\Common\LogisticsRepository;
|
||||
use Repository\Mall\MallRepository;
|
||||
use Service\AbstractService;
|
||||
use StatusConst;
|
||||
use ZcArrayHelper;
|
||||
|
||||
class WaybillBillService extends AbstractService {
|
||||
|
||||
private $mallSDao;
|
||||
private $opOrderDao;
|
||||
private $opWaybillInfoDao;
|
||||
private $opWaybillInfoTradeDao;
|
||||
private $opWaybillBillTaskDao;
|
||||
private $opWaybillBillQueueDao;
|
||||
private $opWaybillBillLogDao;
|
||||
|
||||
private $logisticsRepository;
|
||||
private $mallRepository;
|
||||
|
||||
protected function __construct() {
|
||||
$this->mallSDao = MallSDao::instance();
|
||||
$this->opOrderDao = OpOrderDao::instance();
|
||||
$this->opWaybillInfoDao = OpWaybillInfoDao::instance();
|
||||
$this->opWaybillInfoTradeDao = OpWaybillInfoTradeDao::instance();
|
||||
$this->opWaybillBillTaskDao = OpWaybillBillTaskDao::instance();
|
||||
$this->opWaybillBillQueueDao = OpWaybillBillQueueDao::instance();
|
||||
$this->opWaybillBillLogDao = OpWaybillBillLogDao::instance();
|
||||
|
||||
$this->logisticsRepository = LogisticsRepository::instance();
|
||||
$this->mallRepository = MallRepository::instance();
|
||||
}
|
||||
|
||||
public function searchTaskList($mallId, $params) {
|
||||
$page = intval($params['page'] ?: 1);
|
||||
$pageSize = intval($params['pageSize'] ?: 20);
|
||||
list($taskList, $total) = $this->opWaybillBillTaskDao->searchPage($mallId, $page, $pageSize);
|
||||
return [
|
||||
'taskList' => $taskList,
|
||||
'total' => $total
|
||||
];
|
||||
}
|
||||
|
||||
public function downloadImportWaybillBillTpl() {
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
$objPHPExcel->setActiveSheetIndex(0);
|
||||
$activeSheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
$this->createNewSheetAndSetTitle($objPHPExcel, 0, '快递结算对账模板');
|
||||
$this->setCellValue($activeSheet,1,1, '快递单号');
|
||||
$this->setCellValue($activeSheet,1,2, '543030834000');
|
||||
$this->setCellValue($activeSheet,1,3, '543030833126');
|
||||
$activeSheet->getDefaultRowDimension()->setRowHeight(15);
|
||||
|
||||
$filename = iconv("utf-8", "gb2312", '导入对账表格模板');
|
||||
ExcelTool::downloadExcel($objPHPExcel, $filename, 'downloadImportWaybillBillTpl');
|
||||
exit;
|
||||
}
|
||||
|
||||
private function setCellValue(&$activeSheet, $column, $row, $value) {
|
||||
$columChar = CommonTool::getExcelColumnChar($column);
|
||||
$activeSheet->setCellValueExplicit($columChar . $row, $value, 's');
|
||||
}
|
||||
|
||||
private function setSheetHeader(&$activeSheet, $headers) {
|
||||
$column = 1;
|
||||
foreach ($headers as $field) {
|
||||
$this->setCellValue($activeSheet, $column, 1, $field);
|
||||
$column ++;
|
||||
}
|
||||
}
|
||||
|
||||
private function createNewSheetAndSetTitle(&$objPHPExcel, $sheetIndex, $title = null) {
|
||||
if ($sheetIndex > 0) {
|
||||
$objPHPExcel->createSheet();
|
||||
$objPHPExcel->setActiveSheetIndex($sheetIndex);
|
||||
}
|
||||
$activeSheet = $objPHPExcel->getActiveSheet();
|
||||
if ($title) {
|
||||
$activeSheet->setTitle($title);
|
||||
}
|
||||
return $activeSheet;
|
||||
}
|
||||
|
||||
public function saveWaybillBill($file, $params, $operatorInfo) {
|
||||
$mallId = $operatorInfo['mallId'];
|
||||
$filter = $this->checkAndBuildCondition($mallId, $params);
|
||||
$waybillCodes = $this->getImportWaybillCodes($file);
|
||||
|
||||
$fileName = CommonTool::getUuidName() . '.txt';
|
||||
$ossPath = sprintf('waybill_bill/import_waybill_code_data/%s/%s/%s', $mallId, date('Y-m-d'), $fileName);
|
||||
$ossRet = OssClient::uploadImmutableObjectByContent(\Zc::C('honor-pub.bucket'), $ossPath, serialize($waybillCodes));
|
||||
if (CommonTool::isFailRet($ossRet)) {
|
||||
throw new BizException('上传到OSS出错');
|
||||
}
|
||||
$filter['ossPath'] = $ossPath;
|
||||
$this->saveTaskAndQueue($mallId, $filter, $operatorInfo);
|
||||
}
|
||||
|
||||
private function checkAndBuildCondition($mallId, $params) {
|
||||
$filter = [];
|
||||
if (empty($params['printTimeStart']) || empty($params['printTimeEnd']) || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $params['printTimeStart']) || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $params['printTimeEnd'])) {
|
||||
throw new CheckClientException('请选择打印时间');
|
||||
}
|
||||
if (strtotime($params['printTimeStart']) > strtotime($params['printTimeEnd'])) {
|
||||
throw new CheckClientException('开始时间不能后于结束时间');
|
||||
}
|
||||
if (empty($params['authVenderId']) || !is_numeric($params['authVenderId'])) {
|
||||
throw new CheckClientException('请选择店铺');
|
||||
}
|
||||
if (empty($params['logisticsId']) || !is_numeric($params['logisticsId'])) {
|
||||
throw new CheckClientException('请选择快递公司');
|
||||
}
|
||||
$filter['printTimeStart'] = date('Y-m-d 00:00:00', strtotime($params['printTimeStart']));
|
||||
$filter['printTimeEnd'] = date('Y-m-d 23:59:59', strtotime($params['printTimeEnd']));
|
||||
$filter['authVenderId'] = $params['authVenderId'] != $mallId ? $mallId : $params['authVenderId'];
|
||||
$filter['logisticsId'] = $params['logisticsId'];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
private function getImportWaybillCodes($file) {
|
||||
if (!$file) {
|
||||
throw new CheckClientException('对账表格上传失败');
|
||||
}
|
||||
|
||||
$objPHPExcel = ExcelTool::createPHPExcelFromFile($file);
|
||||
$sheet = $objPHPExcel->getSheet(0); //读取第一张工作表
|
||||
$highestRow = $sheet->getHighestRow(); //读取总行数
|
||||
|
||||
//验证表头
|
||||
if (trim($sheet->getCell('A1')->getValue()) != '快递单号') {
|
||||
unlink($file);
|
||||
throw new CheckClientException('对账模板错误,请下载正确对账模板');
|
||||
}
|
||||
|
||||
$waybillCodes = [];
|
||||
$row = 2;
|
||||
while ($row <= $highestRow) {
|
||||
$waybillCodes[] = trim($sheet->getCell('A' . $row)->getValue());
|
||||
$row ++;
|
||||
if ($row > 10000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
unlink($file);
|
||||
return $waybillCodes;
|
||||
}
|
||||
|
||||
public function saveTaskAndQueue($mallId, $postData, $operatorInfo) {
|
||||
$insertTaskData = [
|
||||
'mall_id' => $mallId,
|
||||
'logistics_id' => $postData['logisticsId'],
|
||||
'gmt_start_print' => $postData['printTimeStart'],
|
||||
'gmt_end_print' => $postData['printTimeEnd'],
|
||||
'import_oss_path' => $postData['ossPath'],
|
||||
'status' => StatusConst::processing,
|
||||
'operate_mall_id' => $operatorInfo['mallId'],
|
||||
'operate_uid' => $operatorInfo['uid'],
|
||||
'operate_ip' => $operatorInfo['ip'],
|
||||
'is_delete' => 0,
|
||||
];
|
||||
$insertQueueData = [
|
||||
'mall_id' => $mallId,
|
||||
'op_waybill_bill_task_id' => '',
|
||||
];
|
||||
$trans = DbTool::beginTrans(OpWaybillBillTaskDao::class);
|
||||
$this->opWaybillBillTaskDao->insert($insertTaskData);
|
||||
$insertQueueData['op_waybill_bill_task_id'] = $this->opWaybillBillTaskDao->lastInsertId();
|
||||
$this->opWaybillBillQueueDao->insert($insertQueueData);
|
||||
DbTool::commitTrans($trans);
|
||||
}
|
||||
|
||||
public function exportWaybillBill($mallId, $taskId) {
|
||||
$taskInfo = $this->opWaybillBillTaskDao->getTask($mallId, $taskId);
|
||||
$logisticsInfo = $this->logisticsRepository->getLogisticsByLogisticsId($taskInfo['logisticsId']);
|
||||
$shopInfo = $this->mallRepository->getMallInfo($mallId);
|
||||
|
||||
$objPHPExcel = new \PHPExcel();
|
||||
$this->initExportWaybillBillSheet($objPHPExcel, $logisticsInfo, $shopInfo);
|
||||
|
||||
$logisticsId = $taskInfo['logisticsId'];
|
||||
unset($shopInfo, $logisticsInfo, $taskInfo);
|
||||
|
||||
list($importMatchResult, $importNoMatchResult, $importAndRecycleResult, $noImportHasPrintResult) = $this->getWaybillBillExportData($mallId, $taskId, $logisticsId);
|
||||
|
||||
$this->packMatchOrHasPrintOrRecycleExportWaybillBillLogData($objPHPExcel, $importMatchResult, 0);
|
||||
unset($importMatchResult);
|
||||
$this->packNoMatchExportWaybillBillLogData($objPHPExcel, $importNoMatchResult);
|
||||
unset($importNoMatchResult);
|
||||
$this->packMatchOrHasPrintOrRecycleExportWaybillBillLogData($objPHPExcel, $importAndRecycleResult, 2);
|
||||
unset($importAndRecycleResult);
|
||||
$this->packMatchOrHasPrintOrRecycleExportWaybillBillLogData($objPHPExcel, $noImportHasPrintResult, 3);
|
||||
unset($noImportHasPrintResult);
|
||||
|
||||
list($duplicationWaybillList, ) = $this->searchDuplicationWaybillBillLogList($mallId, $taskId);
|
||||
$this->packMatchOrHasPrintOrRecycleExportWaybillBillLogData($objPHPExcel, $duplicationWaybillList, 4);
|
||||
unset($duplicationWaybillList);
|
||||
|
||||
ExcelTool::downloadExcel($objPHPExcel, CommonTool::convertEncoding('导出快递结算对账'));
|
||||
exit;
|
||||
}
|
||||
|
||||
private function initExportWaybillBillSheet(&$objPHPExcel, $logisticsInfo, $shopInfo) {
|
||||
$matchHeaders = [ '对账快递', '对账店铺', '运单号', '订单号', '收件人姓名', '收件人手机', '省', '市', '区(县)', '详细地址'];
|
||||
$recycleHeaders = ['对账快递', '对账店铺', '快递公司', '运单号', '订单号', '收件人姓名', '收件人手机', '省', '市', '区(县)', '详细地址'];
|
||||
$hasPrintHeaders = ['对账快递', '对账店铺', '快递公司', '运单号', '订单号', '收件人姓名', '收件人手机', '省', '市', '区(县)', '详细地址', '面单状态'];
|
||||
$duplicationHeaders = ['行号', '快递公司', '运单号', '订单号', '收件人姓名', '收件人手机', '省', '市', '区(县)', '详细地址', '面单状态'];
|
||||
|
||||
$activeSheet = $this->createNewSheetAndSetTitle($objPHPExcel, 0, '导入且匹配的运单号');
|
||||
$this->setSheetHeader($activeSheet, $matchHeaders);
|
||||
$this->setCellValue($activeSheet, 1, 2, $logisticsInfo['logisticsName']);
|
||||
$this->setCellValue($activeSheet, 2, 2, $shopInfo['mallName']);
|
||||
|
||||
$activeSheet = $this->createNewSheetAndSetTitle($objPHPExcel, 1, '导入但未匹配的运单号');
|
||||
$this->setSheetHeader($activeSheet, ['对账快递', '对账店铺', '运单号']);
|
||||
$this->setCellValue($activeSheet, 1, 2, $logisticsInfo['logisticsName']);
|
||||
$this->setCellValue($activeSheet, 2, 2, $shopInfo['mallName']);
|
||||
|
||||
$activeSheet = $this->createNewSheetAndSetTitle($objPHPExcel, 2, '导入但已回收的运单号');
|
||||
$this->setSheetHeader($activeSheet, $recycleHeaders);
|
||||
$this->setCellValue($activeSheet, 1, 2, $logisticsInfo['logisticsName']);
|
||||
$this->setCellValue($activeSheet, 2, 2, $shopInfo['mallName']);
|
||||
|
||||
$activeSheet = $this->createNewSheetAndSetTitle($objPHPExcel, 3, '未导入但本店有打印的运单号');
|
||||
$this->setSheetHeader($activeSheet, $hasPrintHeaders);
|
||||
$this->setCellValue($activeSheet, 1, 2, $logisticsInfo['logisticsName']);
|
||||
$this->setCellValue($activeSheet, 2, 2, $shopInfo['mallName']);
|
||||
|
||||
$activeSheet = $this->createNewSheetAndSetTitle($objPHPExcel, 4, '上传文件中重复的单号');
|
||||
$this->setSheetHeader($activeSheet, $duplicationHeaders);
|
||||
}
|
||||
|
||||
private function packMatchOrHasPrintOrRecycleExportWaybillBillLogData(&$objPHPExcel, $list, $sheetIndex) {
|
||||
$objPHPExcel->setActiveSheetIndex($sheetIndex);
|
||||
$activeSheet = $objPHPExcel->getActiveSheet();
|
||||
$row = 2;
|
||||
foreach ($list as $item) {
|
||||
$column = 3;
|
||||
if ($item['type'] == OrderPrintConst::waybillBillTypeImportAndDuplication) {
|
||||
$column = 1;
|
||||
$this->setCellValue($activeSheet, $column++, $row, $item['index']);
|
||||
}
|
||||
if (in_array($item['type'], [OrderPrintConst::waybillBillTypeNoImportAndHasPrint, OrderPrintConst::waybillBillTypeImportAndRecycle, OrderPrintConst::waybillBillTypeImportAndDuplication])) {
|
||||
$this->setCellValue($activeSheet, $column++, $row, $item['logisticsName']);
|
||||
}
|
||||
$this->setCellValue($activeSheet, $column++, $row, $item['waybillCode']);
|
||||
$this->setCellValue($activeSheet, $column++, $row, implode(',', $item['orderIds'] ?: $item['tradeIds']));
|
||||
$this->setCellValue($activeSheet, $column++, $row, CommonTool::ensconceString($item['receiverName'], 'name'));
|
||||
$this->setCellValue($activeSheet, $column++, $row, CommonTool::ensconceString($item['receiverMobile'], 'mobile'));
|
||||
|
||||
$this->setCellValue($activeSheet, $column++, $row, $item['receiverProvince'] );
|
||||
$this->setCellValue($activeSheet, $column++, $row, $item['receiverCity']);
|
||||
$this->setCellValue($activeSheet, $column++, $row, $item['receiverCounty']);
|
||||
$this->setCellValue($activeSheet, $column++, $row, CommonTool::ensconceString($item['receiverAddress'], 'address'));
|
||||
if (in_array($item['type'], [OrderPrintConst::waybillBillTypeNoImportAndHasPrint, OrderPrintConst::waybillBillTypeImportAndDuplication])) {
|
||||
$this->setCellValue($activeSheet, $column++, $row, ($item['status'] == StatusConst::cancel) ? '已取消' : ($item['status'] ? '有效面单' : ''));
|
||||
}
|
||||
$row ++;
|
||||
}
|
||||
}
|
||||
|
||||
private function packNoMatchExportWaybillBillLogData(&$objPHPExcel, $importNoMatchResult) {
|
||||
$objPHPExcel->setActiveSheetIndex(1);
|
||||
$activeSheet = $objPHPExcel->getActiveSheet();
|
||||
$row = 2;
|
||||
foreach ($importNoMatchResult as $item) {
|
||||
$this->setCellValue($activeSheet, 3, $row, $item['waybillCode']);
|
||||
$row ++;
|
||||
}
|
||||
}
|
||||
|
||||
public function searchDuplicationWaybillBillLogList($mallId, $taskId) {
|
||||
$taskInfo = $this->opWaybillBillTaskDao->getTask($mallId, $taskId);
|
||||
if (empty($taskInfo)) {
|
||||
return [[], 0];
|
||||
}
|
||||
$ossRet = OssClient::getImmutableObjectByContent(\Zc::C('honor-pub.bucket'), $taskInfo['importOssPath']);
|
||||
$importWaybillCodeMap = unserialize($ossRet['body']);
|
||||
|
||||
$duplicationWaybillCodeAndIndexesMap = [];
|
||||
foreach ($importWaybillCodeMap as $index => $waybillCode) {
|
||||
$duplicationWaybillCodeAndIndexesMap[$waybillCode][] = $index;
|
||||
}
|
||||
$billLogList = [];
|
||||
foreach ($duplicationWaybillCodeAndIndexesMap as $waybillCode => $indexList) {
|
||||
if (count($indexList) < 2) {
|
||||
continue;
|
||||
}
|
||||
foreach ($indexList as $index) {
|
||||
$billLogList[] = [
|
||||
'index' => $index + 2,
|
||||
'mallId' => $mallId,
|
||||
'opWaybillBillTaskId' => $taskId,
|
||||
'waybillCode' => $waybillCode,
|
||||
'logisticsId' => $taskInfo['logisticsId'],
|
||||
'type' => OrderPrintConst::waybillBillTypeImportAndDuplication,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$billLogList = $this->rebuildWaybillBillLogList($mallId, $billLogList, OrderPrintConst::waybillBillTypeImportAndDuplication);
|
||||
usort($billLogList, function($v1, $v2) {
|
||||
return $v1['index'] > $v2['index'];
|
||||
});
|
||||
return [$billLogList, count($billLogList)];
|
||||
}
|
||||
|
||||
private function rebuildWaybillBillLogList($mallId, $waybillBillLogList, $type) {
|
||||
if (empty($waybillBillLogList)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($type != OrderPrintConst::waybillBillTypeImportAndNoMatch) {
|
||||
$logisticsId = $waybillBillLogList[0]['logisticsId'];
|
||||
$waybillCodes = array_unique(ZcArrayHelper::getSub($waybillBillLogList, 'waybillCode'));
|
||||
$waybillInfoList = $this->getWaybillInfoByLogisticsIdAndWaybillCodes($mallId, $logisticsId, $waybillCodes);
|
||||
|
||||
$waybillInfoList = ZcArrayHelper::changeKeyRow($waybillInfoList, 'waybillCode');
|
||||
|
||||
if (in_array($type, [OrderPrintConst::waybillBillTypeNoImportAndHasPrint, OrderPrintConst::waybillBillTypeImportAndRecycle, OrderPrintConst::waybillBillTypeImportAndDuplication])) {
|
||||
$logisticsIds = array_unique(ZcArrayHelper::getSub($waybillInfoList, 'logisticsId'));
|
||||
$logisticsList = $this->logisticsRepository->getLogisticsListByLogisticsIds($logisticsIds);
|
||||
}
|
||||
}
|
||||
|
||||
$returnWaybillBillLogList = [];
|
||||
foreach ($waybillBillLogList as $logItem) {
|
||||
$tmp = [
|
||||
'taskId' => $logItem['opWaybillBillTaskId'],
|
||||
'logisticsId' => $logItem['logisticsId'],
|
||||
'waybillCode' => $logItem['waybillCode'],
|
||||
'type' => $logItem['type'],
|
||||
'index' => $logItem['index'],
|
||||
];
|
||||
|
||||
if ($type != OrderPrintConst::waybillBillTypeImportAndNoMatch) {
|
||||
$item = $waybillInfoList[$logItem['waybillCode']];
|
||||
$orderAndAddressTmp = [
|
||||
'tradeIds' => $item['tradeIds'],
|
||||
'receiverProvince' => $item['receiverProvince'],
|
||||
'receiverCity' => $item['receiverCity'],
|
||||
'receiverCounty' => $item['receiverCounty'],
|
||||
'receiverAddress' => $item['receiverAddress'],
|
||||
'receiverMobile' => CommonTool::decrypt($item['receiverMobileS'], null),
|
||||
'receiverName' => CommonTool::decrypt($item['receiverNameS'], null),
|
||||
'waybillCode' => $item['waybillCode'],
|
||||
'status' => $item['status'],
|
||||
'opWaybillInfoId' => $item['opWaybillInfoId']
|
||||
];
|
||||
if (in_array($type, [OrderPrintConst::waybillBillTypeNoImportAndHasPrint, OrderPrintConst::waybillBillTypeImportAndRecycle, OrderPrintConst::waybillBillTypeImportAndDuplication])) {
|
||||
$orderAndAddressTmp['logisticsName'] = $logisticsList[$item['logisticsId']]['logisticsName'];
|
||||
}
|
||||
$returnWaybillBillLogList[] = $tmp + $orderAndAddressTmp;
|
||||
} else {
|
||||
$returnWaybillBillLogList[] = $tmp;
|
||||
}
|
||||
}
|
||||
return $returnWaybillBillLogList;
|
||||
}
|
||||
|
||||
public function getWaybillInfoByLogisticsIdAndWaybillCodes($mallId, $logisticsId, $waybillCodes) {
|
||||
if (CommonTool::anyEmpty($mallId, $logisticsId, $waybillCodes)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$list = $this->opWaybillInfoDao->getListByLogisticsIdAndWaybillCodes($mallId, $logisticsId, $waybillCodes);
|
||||
if (!$list) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$waybillInfoIds = ZcArrayHelper::getSub($list, 'opWaybillInfoId');
|
||||
$waybillTradeMap = $this->opWaybillInfoTradeDao->getOpWaybillInfoIdAndTradeListMap($mallId, $waybillInfoIds);
|
||||
$list = OrderDecryptTool::decryptInfoListByTableName($list, 'op_waybill_info');
|
||||
foreach ($list as &$row) {
|
||||
$row['tradeIds'] = ZcArrayHelper::getSub($waybillTradeMap[$row['opWaybillInfoId']], 'tradeId');
|
||||
foreach ($waybillTradeMap[$row['opWaybillInfoId']] as $trade) {
|
||||
if ($trade['isMaster']) {
|
||||
$row['masterTradeId'] = $trade['tradeId'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getWaybillBillExportData($mallId, $taskId, $logisticsId) {
|
||||
if (CommonTool::anyEmpty($mallId, $taskId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$page = 1;
|
||||
$pageSize = 50;
|
||||
$importMatchResult = [];
|
||||
$importNoMatchResult = [];
|
||||
$noImportHasPrintResult = [];
|
||||
$importAndRecycleResult = [];
|
||||
$logisticsNameMap = [];
|
||||
|
||||
$logisticsInfo = $this->logisticsRepository->getLogisticsByLogisticsId($logisticsId);
|
||||
$logisticsNameMap[$logisticsInfo['logisticsId']] = $logisticsInfo['logisticsName'];
|
||||
|
||||
while (true) {
|
||||
list($opWaybillBillLogList, $total) = $this->opWaybillBillLogDao->searchPage($mallId, $taskId, $page, $pageSize);
|
||||
if (empty($opWaybillBillLogList)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$waybillCodes = array_unique(ZcArrayHelper::getSub($opWaybillBillLogList, 'waybillCode'));
|
||||
$opWaybillInfoList = $this->getWaybillInfoByLogisticsIdAndWaybillCodes($mallId, $logisticsId, $waybillCodes);
|
||||
$opWaybillInfoList = ZcArrayHelper::changeKeyRow($opWaybillInfoList, 'waybillCode');
|
||||
|
||||
$orderIds = ZcArrayHelper::getSub($opWaybillInfoList, 'masterTradeId');
|
||||
$opOrderList = $this->opOrderDao->getListByIds($orderIds);
|
||||
$opOrderList = ZcArrayHelper::changeKeyRow($opOrderList, 'orderId');
|
||||
|
||||
foreach ($opWaybillBillLogList as $opWaybillBillLog) {
|
||||
$type = $opWaybillBillLog['type'];
|
||||
$waybillCode = $opWaybillBillLog['waybillCode'];
|
||||
if ($type == OrderPrintConst::waybillBillTypeImportAndNoMatch) {
|
||||
$importNoMatchResult[] = [
|
||||
'type' => $type,
|
||||
'waybillCode' => $waybillCode,
|
||||
];
|
||||
continue;
|
||||
}
|
||||
$opWaybillInfo = $opWaybillInfoList[$waybillCode];
|
||||
$tmp = [
|
||||
'taskId' => $opWaybillBillLog['opWaybillBillTaskId'],
|
||||
'waybillCode' => $waybillCode,
|
||||
'orderIds' => $opWaybillInfo['tradeIds'],
|
||||
'type' => $type,
|
||||
'receiverProvince' => $opWaybillInfo['receiverProvince'],
|
||||
'receiverCity' => $opWaybillInfo['receiverCity'],
|
||||
'receiverCounty' => $opWaybillInfo['receiverCounty'],
|
||||
'receiverAddress' => $opWaybillInfo['receiverAddress'],
|
||||
'receiverMobile' => CommonTool::decrypt($opWaybillInfo['receiverMobileS'], null),
|
||||
'receiverName' => CommonTool::decrypt($opWaybillInfo['receiverNameS'], null),
|
||||
'pin' => $opOrderList[$opWaybillInfo['masterTradeId']]['pin'],
|
||||
'status' => $opWaybillInfo['status'],
|
||||
];
|
||||
if (in_array($type, [OrderPrintConst::waybillBillTypeNoImportAndHasPrint, OrderPrintConst::waybillBillTypeImportAndRecycle])) {
|
||||
if (!isset($logisticsNameMap[$opWaybillInfo['logisticsId']])) {
|
||||
$logisticsInfo = $this->logisticsRepository->getLogisticsByLogisticsId($logisticsId);
|
||||
$logisticsNameMap[$logisticsInfo['logisticsId']] = $logisticsInfo['logisticsName'];
|
||||
}
|
||||
$tmp['logisticsName'] = $logisticsNameMap[$opWaybillInfo['logisticsId']];
|
||||
if ($type == OrderPrintConst::waybillBillTypeNoImportAndHasPrint) {
|
||||
$noImportHasPrintResult[] = $tmp;
|
||||
} else {
|
||||
$importAndRecycleResult[] = $tmp;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$importMatchResult[] = $tmp;
|
||||
}
|
||||
|
||||
if ($total < $pageSize) {
|
||||
break;
|
||||
}
|
||||
$page ++;
|
||||
}
|
||||
|
||||
return [$importMatchResult, $importNoMatchResult, $importAndRecycleResult, $noImportHasPrintResult];
|
||||
}
|
||||
|
||||
public function getWaybillBillTasksProcessResult($mallId, $taskIds) {
|
||||
if (CommonTool::anyEmpty($mallId, $taskIds)) {
|
||||
return [];
|
||||
}
|
||||
$taskIds = is_array($taskIds) ? $taskIds : [$taskIds];
|
||||
$taskList = $this->opWaybillBillTaskDao->getListOfMallByTaskIds($mallId, $taskIds);
|
||||
$returnTaskList = [];
|
||||
foreach ($taskList as $taskItem) {
|
||||
$returnTaskList[] = [
|
||||
'taskId' => $taskItem['opWaybillBillTaskId'],
|
||||
'shopUsedTotal' => $taskItem['shopUsedTotal'],
|
||||
'importTotal' => $taskItem['importTotal'],
|
||||
'matchTotal' => $taskItem['matchTotal'],
|
||||
'noMatchTotal' => $taskItem['noMatchTotal'],
|
||||
'status' => $taskItem['status'],
|
||||
];
|
||||
}
|
||||
return $returnTaskList;
|
||||
}
|
||||
|
||||
public function deleteWaybillBillTask($mallId, $taskId) {
|
||||
if (!$taskId) {
|
||||
throw new CheckClientException('非法操作');
|
||||
}
|
||||
$ret = $this->opWaybillBillTaskDao->deleteMallTask($mallId, $taskId);
|
||||
if (!$ret) {
|
||||
throw new BizException('删除失败');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue