From e9fee5eb55517ffcaaa3f9aa8fbc2dcdece82b52 Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Fri, 5 Jan 2024 00:41:19 +0800 Subject: [PATCH] yh --- .../filter/class.InitController.php | 55 +- .../order/class.FdsOrderPrintController.php | 302 ---------- app/libs/daos/Admin/TimerTokenApplyLogDao.php | 11 + app/libs/daos/Order/OpOrderDao.php | 4 + app/libs/daos/Order/OpOrderGoodsDao.php | 16 + .../daos/OrderPrint/OpAssemblyTaskDao.php | 20 + .../daos/OrderPrint/OpAssemblyTaskItemDao.php | 13 + .../OrderPrint/OpAssemblyTaskStageDao.php | 8 + .../daos/OrderPrint/OpWaybillBillLogDao.php | 11 + .../daos/OrderPrint/OpWaybillBillQueueDao.php | 8 + .../daos/OrderPrint/OpWaybillBillTaskDao.php | 32 ++ app/libs/daos/OrderPrint/OpWaybillInfoDao.php | 5 + .../daos/OrderPrint/OpWaybillInfoTradeDao.php | 6 + .../repository/Common/LogisticsRepository.php | 2 +- app/libs/services/Admin/AdminService.php | 33 ++ .../services/AfterSale/AfterSaleService.php | 11 + .../services/OrderPrint/AssemblyService.php | 502 +++++++++++++++++ .../OrderPrint/WaybillBillService.php | 514 ++++++++++++++++++ 18 files changed, 1219 insertions(+), 334 deletions(-) delete mode 100644 app/libs/controller/order/class.FdsOrderPrintController.php create mode 100644 app/libs/daos/Admin/TimerTokenApplyLogDao.php create mode 100644 app/libs/daos/OrderPrint/OpAssemblyTaskDao.php create mode 100644 app/libs/daos/OrderPrint/OpAssemblyTaskItemDao.php create mode 100644 app/libs/daos/OrderPrint/OpAssemblyTaskStageDao.php create mode 100644 app/libs/daos/OrderPrint/OpWaybillBillLogDao.php create mode 100644 app/libs/daos/OrderPrint/OpWaybillBillQueueDao.php create mode 100644 app/libs/daos/OrderPrint/OpWaybillBillTaskDao.php create mode 100644 app/libs/services/AfterSale/AfterSaleService.php create mode 100644 app/libs/services/OrderPrint/AssemblyService.php create mode 100644 app/libs/services/OrderPrint/WaybillBillService.php diff --git a/app/libs/controller/filter/class.InitController.php b/app/libs/controller/filter/class.InitController.php index 108f7fc..b86e312 100644 --- a/app/libs/controller/filter/class.InitController.php +++ b/app/libs/controller/filter/class.InitController.php @@ -1,5 +1,9 @@ rbacClient = new \JxJflowClient\lib\RbacClient('bizCache'); $this->mallRbacService = MallRbacService::instance(); + $this->adminService = AdminService::instance(); $this->affiliateAccountService = Zc::singleton('AffiliateAccountService'); $this->redis = RedisExt::factory('bizCache'); @@ -66,7 +69,7 @@ class InitController extends ZcController { $sessionId = $_COOKIE[Zc::C('sessionName')] ? $_COOKIE[Zc::C('sessionName')] : ''; if (AppConst::isPddDzJxcApp() && !$sessionId) { - return $this->forward(RouteConst::frontHomeIndex); + throw new UnauthorizedException('请先登录'); } Zc::startSessionWithParams(Zc::C('sessionName'), CommonTool::getCookieDomain(), $sessionId, Zc::C('sessionType'), []); @@ -77,25 +80,20 @@ class InitController extends ZcController { } if (AppConst::isRubyDesktop() && empty($_SESSION[SessionConst::ryUserId])) { - $_GET['type'] = 'logout'; - return $this->forward('ruby_dt/' . RubyRouteConst::userLogin); + throw new UnauthorizedException('请先登录'); } if (empty($_SESSION[SessionConst::mallId])) { if ($_GET['apItemUrl']) { $_SESSION[SessionConst::apItemUrl] = $_GET['apItemUrl']; } - return $this->forward(RouteConst::frontHomeIndex); + throw new UnauthorizedException('请先登录'); } if (AppConst::isNeedCheckSubAccountPermission()) { $isHasPermissionFlag = $this->checkSubAccountPermissionRoute(); if (!$isHasPermissionFlag) { - if (CommonTool::isAjax()) { - $this->renderJSON(CommonTool::failResult('访问权限限制,请联系管理员')); - exit(); - } - return $this->forward(RouteConst::frontErrorNoPermission); + throw new PermissionDeniedException('访问权限限制,请联系管理员'); } } @@ -109,11 +107,11 @@ class InitController extends ZcController { $isDenyRequestMall = $this->solidRedis->sIsMember(RedisKeyConst::mallDenyRequestMallIds, $_SESSION[SessionConst::mallId]); if ($isDenyRequestMall || in_array($_SESSION[SessionConst::mallId], $blackMallIds) || CommonTool::isBlackClientIp()) { header("HTTP/1.1 500"); - exit; + throw new AccessDeniedException('禁止访问'); } if ($_GET['route'] != RouteConst::commonAuthMockUser && $this->isInAccessBlackList($_SESSION[SessionConst::mallId])) { - die('禁止访问'); + throw new PermissionDeniedException('禁止访问'); } $this->initSessionRequestIsElectron(); @@ -130,14 +128,7 @@ class InitController extends ZcController { $applyUrl = sprintf('http://jflow.jiancent.com/open/rbac/applyAuthPermission?adminId=%s&userId=%s&platform=%s&permission=%s', $_SESSION[SessionConst::mockAdminId], $_SESSION[SessionConst::mallId], \JxJflowClient\lib\AuthApiConst::platformPddMsOrder, $route); $syncUrl = Zc::url(AdminRouteConst::adminAuthRsyncAdminRbac); $reason = sprintf("访问权限限制,你可以先 点此申请权限, 待审核通过后再点此同步权限", $applyUrl, $syncUrl); - - if ($_SERVER['CONTENT_TYPE'] == 'application/x-www-form-urlencoded') { - header('Content-Type:text/html;Charset=UTF-8;'); - die(json_encode(CommonTool::failResult($reason), true)); - } else { - header('Content-type: application/json'); - die(json_encode(CommonTool::failResult($reason), JSON_UNESCAPED_UNICODE)); - } + throw new PermissionDeniedException($reason); } } @@ -304,8 +295,9 @@ class InitController extends ZcController { * 这个操作,是让inner open底下的代码,只有内网ip和自己店铺能访问 */ public function innerOpen() { + $params = $_GET; $ip = CommonTool::clientIp(); - if ($this->checkTimerToken($ip)) { + if ($this->checkTimerToken($ip, $params)) { return ; } @@ -318,8 +310,8 @@ class InitController extends ZcController { } } - private function checkTimerToken($clientIp) { - $timerToken = $_GET['timerToken']; + private function checkTimerToken($clientIp, $params) { + $timerToken = $params['timerToken']; if (empty($timerToken)) { return false; } @@ -331,15 +323,16 @@ class InitController extends ZcController { } $adminService = new AdminService(); - $checkRet = $adminService->checkTimerToken($timerToken, $clientIp); - $adminService->addTimerTokenUsedLog($timerToken, $_GET, $checkRet); - - if (CommonTool::isFailRet($checkRet)) { - $log->info("checkTimerToken [{$timerToken}] clientIp[{$clientIp}] failRet:" . print_r($checkRet, true)); + try { + $adminService->checkTimerToken($timerToken, $clientIp); + $adminService->addTimerTokenUsedLog($timerToken, $params, StatusConst::success, '成功'); + } catch (Exception $e) { + $adminService->addTimerTokenUsedLog($timerToken, $params, StatusConst::fail, $e->getMessage()); + $log->info("checkTimerToken [{$timerToken}] clientIp[{$clientIp}] failReason:" . $e->getMessage()); return false; } - $log->info("check exec timer valid, clientIp[{$clientIp}] get info:" . print_r($_GET, true)); + $log->info("check exec timer valid, clientIp[{$clientIp}] get info:" . print_r($params, true)); return true; } diff --git a/app/libs/controller/order/class.FdsOrderPrintController.php b/app/libs/controller/order/class.FdsOrderPrintController.php deleted file mode 100644 index 0eae2d9..0000000 --- a/app/libs/controller/order/class.FdsOrderPrintController.php +++ /dev/null @@ -1,302 +0,0 @@ -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'] . '参数错误
'; - $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'] .'
'; - $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'] . '参数错误
'; - $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'] .'
'; - $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])); - } -} \ No newline at end of file diff --git a/app/libs/daos/Admin/TimerTokenApplyLogDao.php b/app/libs/daos/Admin/TimerTokenApplyLogDao.php new file mode 100644 index 0000000..e4a7beb --- /dev/null +++ b/app/libs/daos/Admin/TimerTokenApplyLogDao.php @@ -0,0 +1,11 @@ +queryFirstField('SELECT client_ip FROM %b WHERE timer_token = %s AND gmt_expire >= NOW() LIMIT 1', $this->getTable(), $timerToken); + } +} diff --git a/app/libs/daos/Order/OpOrderDao.php b/app/libs/daos/Order/OpOrderDao.php index 4d35ab8..ccdfa90 100644 --- a/app/libs/daos/Order/OpOrderDao.php +++ b/app/libs/daos/Order/OpOrderDao.php @@ -1016,4 +1016,8 @@ class OpOrderDao extends AbstractDao { $list = $this->query('select order_id,receiver_name_s,receiver_phone_s,address from %b where order_id in %li', $this->getTable(), $orderIds); return ZcArrayHelper::changeKeyRow($list, 'orderId'); } + + public function searchOrderIdsCursor($mallIds, $lastOrderId, $joinStr, $whereStr, $limit) { + return $this->queryFirstColumn("SELECT o.order_id FROM op_order o %l WHERE o.mall_id in %li and o.`order_id` > %i %l order by o.`order_id` asc limit %i", $joinStr, $mallIds, $lastOrderId, $whereStr, $limit); + } } diff --git a/app/libs/daos/Order/OpOrderGoodsDao.php b/app/libs/daos/Order/OpOrderGoodsDao.php index 4fca049..2613592 100644 --- a/app/libs/daos/Order/OpOrderGoodsDao.php +++ b/app/libs/daos/Order/OpOrderGoodsDao.php @@ -3,6 +3,7 @@ namespace Dao\Order; use Dao\AbstractDao; +use Dao\Goods\OpGoodsShortDao; use ZcArrayHelper; class OpOrderGoodsDao extends AbstractDao { @@ -21,4 +22,19 @@ class OpOrderGoodsDao extends AbstractDao { $rows = $this->query('select order_sn, order_id, sum(goods_count) as item_total from %b where order_sn in %ls group by order_sn', $this->getTable(), $orderSns); return ZcArrayHelper::changeKey($rows, 'orderSn'); } + + public function searchWithGoodsShort($orderIds, $filterCondition) { + $where = []; + if(!empty($filterCondition['warehouse'])) { + $where[] = $this->prepare("AND ogs.`warehouse` like %ss", $filterCondition['warehouse']); + } + + if(!empty($filterCondition['shelves'])) { + $where[] = $this->prepare("AND ogs.`shelves` like %ss", $filterCondition['shelves']); + } + + $goodsShortTbl = OpGoodsShortDao::tableName(); + $whereStr = implode(' ', $where); + return $this->query('select og.*, ogs.warehouse, ogs.shelves from %b og left join %b ogs on og.goods_id = ogs.goods_id where og.order_id in %li %l order by og.op_order_goods_id asc', $this->getTable(), $goodsShortTbl, $orderIds, $whereStr); + } } diff --git a/app/libs/daos/OrderPrint/OpAssemblyTaskDao.php b/app/libs/daos/OrderPrint/OpAssemblyTaskDao.php new file mode 100644 index 0000000..364d0d5 --- /dev/null +++ b/app/libs/daos/OrderPrint/OpAssemblyTaskDao.php @@ -0,0 +1,20 @@ +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; + } +} \ No newline at end of file diff --git a/app/libs/daos/OrderPrint/OpAssemblyTaskItemDao.php b/app/libs/daos/OrderPrint/OpAssemblyTaskItemDao.php new file mode 100644 index 0000000..aa5e6f4 --- /dev/null +++ b/app/libs/daos/OrderPrint/OpAssemblyTaskItemDao.php @@ -0,0 +1,13 @@ +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); + } +} \ No newline at end of file diff --git a/app/libs/daos/OrderPrint/OpAssemblyTaskStageDao.php b/app/libs/daos/OrderPrint/OpAssemblyTaskStageDao.php new file mode 100644 index 0000000..b9efca3 --- /dev/null +++ b/app/libs/daos/OrderPrint/OpAssemblyTaskStageDao.php @@ -0,0 +1,8 @@ +queryPage('select * from %b owbl where owbl.mall_id = %i and owbl.op_waybill_bill_task_id = %i', $this->getTable(), $mallId, $taskId, $page, $pageSize); + } +} \ No newline at end of file diff --git a/app/libs/daos/OrderPrint/OpWaybillBillQueueDao.php b/app/libs/daos/OrderPrint/OpWaybillBillQueueDao.php new file mode 100644 index 0000000..c9931ad --- /dev/null +++ b/app/libs/daos/OrderPrint/OpWaybillBillQueueDao.php @@ -0,0 +1,8 @@ +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; + } +} \ No newline at end of file diff --git a/app/libs/daos/OrderPrint/OpWaybillInfoDao.php b/app/libs/daos/OrderPrint/OpWaybillInfoDao.php index 99fae7f..674052d 100644 --- a/app/libs/daos/OrderPrint/OpWaybillInfoDao.php +++ b/app/libs/daos/OrderPrint/OpWaybillInfoDao.php @@ -98,4 +98,9 @@ class OpWaybillInfoDao extends AbstractDao { ' where owi.waybill_from = %s and owi.logistics_id = %i and owit.trade_id = %s', $this->getTable(), $owitTbl, \OrderPrintConst::waybillFromPdd, $logisticsId, $orderSn); return (int)$count; } + + public function getListByLogisticsIdAndWaybillCodes($mallId, $logisticsId, $waybillCodes) { + $where = $this->prepare('and logistics_id = %i and waybill_code in %ls', $logisticsId, $waybillCodes); + return $this->query('select * from %b where mall_id = %i %l order by op_waybill_info_id desc', $this->getTable(), $mallId, $where); + } } \ No newline at end of file diff --git a/app/libs/daos/OrderPrint/OpWaybillInfoTradeDao.php b/app/libs/daos/OrderPrint/OpWaybillInfoTradeDao.php index b6587fe..8592fc8 100644 --- a/app/libs/daos/OrderPrint/OpWaybillInfoTradeDao.php +++ b/app/libs/daos/OrderPrint/OpWaybillInfoTradeDao.php @@ -4,6 +4,7 @@ namespace Dao\OrderPrint; use CommonTool; use Dao\AbstractDao; +use ZcArrayHelper; class OpWaybillInfoTradeDao extends AbstractDao { public function getListByWaybillInfoIds($mallId, $waybillInfoIds) { @@ -29,4 +30,9 @@ class OpWaybillInfoTradeDao extends AbstractDao { return (int)$count; } + + public function getOpWaybillInfoIdAndTradeListMap($mallId, $waybillInfoIds) { + $tradeRows = $this->query('select op_waybill_info_id, trade_id from %b where op_waybill_info_id in %li and mall_id = %i', $this->getTable(), $waybillInfoIds, $mallId); + return ZcArrayHelper::changeKey($tradeRows, 'opWaybillInfoId', true); + } } \ No newline at end of file diff --git a/app/libs/repository/Common/LogisticsRepository.php b/app/libs/repository/Common/LogisticsRepository.php index 9dd0f92..85b6cfd 100644 --- a/app/libs/repository/Common/LogisticsRepository.php +++ b/app/libs/repository/Common/LogisticsRepository.php @@ -24,7 +24,7 @@ class LogisticsRepository extends AbstractRepository { $rows = $this->logisticsDao->getMapByIds($logisticsIds); $logisticsPlatforms = $this->logisticsPlatformDao->getListByLogisticsId($logisticsIds); foreach ($logisticsPlatforms as $logisticsPlatform) { - $rows[$logisticsPlatform['logistics_id']]['platforms'][$logisticsPlatform['platform']] = $logisticsPlatform; + $rows[$logisticsPlatform['logisticsId']]['platforms'][$logisticsPlatform['platform']] = $logisticsPlatform; } return $rows; } diff --git a/app/libs/services/Admin/AdminService.php b/app/libs/services/Admin/AdminService.php index 092d694..6542c41 100644 --- a/app/libs/services/Admin/AdminService.php +++ b/app/libs/services/Admin/AdminService.php @@ -2,17 +2,24 @@ namespace Service\Admin; +use CommonTool; use Dao\Admin\AdminBackgroundLogDao; use Dao\Admin\AdminDao; +use Dao\Admin\TimerTokenApplyLogDao; +use Exception\BizException; +use Exception\CheckClientException; use Service\AbstractService; +use StatusConst; class AdminService extends AbstractService { private $adminDao; private $adminBackgroundLogDao; + private $timerTokenApplyLogDao; protected function __construct() { $this->adminDao = AdminDao::instance(); $this->adminBackgroundLogDao = AdminBackgroundLogDao::instance(); + $this->timerTokenApplyLogDao = TimerTokenApplyLogDao::instance(); } public function login($username, $password) { @@ -27,4 +34,30 @@ class AdminService extends AbstractService { public function addAdminBackgroundLog($adminId, $action, $content, $notes = null) { $this->adminBackgroundLogDao->add($adminId, $action, $content, $notes); } + + public function checkTimerToken($timerToken, $clientIp) { + if (CommonTool::anyEmpty($timerToken, $clientIp)) { + throw new CheckClientException('校验参数有误'); + } + + $applyClientIp = $this->timerTokenApplyLogDao->getClientIpByTimerToken($timerToken); + if (empty($applyClientIp)) { + throw new BizException('token无效,或已过期'); + } + + if ($applyClientIp !== $clientIp) { + throw new BizException('clientIp 与applyClientIp不一致'); + } + } + + public function addTimerTokenUsedLog($timerToken, $get, $result, $reason) { + $insertDo = [ + 'timer_token' => $timerToken, + 'route' => CommonTool::transLateRoute($get['route']), + 'get_info' => $get ? json_encode($get) : null, + 'result' => $result, + 'reason' => $reason ?: null, + ]; + return $this->timerTokenApplyLogDao->insert($insertDo); + } } \ No newline at end of file diff --git a/app/libs/services/AfterSale/AfterSaleService.php b/app/libs/services/AfterSale/AfterSaleService.php new file mode 100644 index 0000000..c252e69 --- /dev/null +++ b/app/libs/services/AfterSale/AfterSaleService.php @@ -0,0 +1,11 @@ +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; + } +} \ No newline at end of file diff --git a/app/libs/services/OrderPrint/WaybillBillService.php b/app/libs/services/OrderPrint/WaybillBillService.php new file mode 100644 index 0000000..bf4359d --- /dev/null +++ b/app/libs/services/OrderPrint/WaybillBillService.php @@ -0,0 +1,514 @@ +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('删除失败'); + } + } +} \ No newline at end of file