diff --git a/app/libs/controller/order/class.PrintSettingController.php b/app/libs/controller/order/class.PrintSettingController.php index ee143ae..acf31c2 100644 --- a/app/libs/controller/order/class.PrintSettingController.php +++ b/app/libs/controller/order/class.PrintSettingController.php @@ -489,6 +489,14 @@ class PrintSettingController extends AbstractApiController { return $this->renderSuccess($data); } + /** + * @api GET 获取已申请的物流和对应的系统模板 + */ + public function getAppliedLogisticsSysExpressTpl() { + $appliedLogisticsList = $this->expressTplService->getAppliedLogisticsSysExpressTpl(CommonTool::getOperatorInfo()); + return $this->renderSuccess(['appliedLogisticsList' => $appliedLogisticsList]); + } + /** * @api GET 获取有系统快递单模板的快递公司列表 */ diff --git a/app/libs/daos/Common/LogisticsPlatformDao.php b/app/libs/daos/Common/LogisticsPlatformDao.php index 873b95c..8923422 100644 --- a/app/libs/daos/Common/LogisticsPlatformDao.php +++ b/app/libs/daos/Common/LogisticsPlatformDao.php @@ -11,6 +11,11 @@ class LogisticsPlatformDao extends AbstractDao { return $this->queryFirstField('select company_code from %b where logistics_id = %i and platform = %s', $this->getTable(), $logisticsId, $platform); } + public function getCompanyCodeAndLogisticsIdMap($logisticsIds, $platform) { + $rows = $this->query('select company_code, logistics_id from %b where logistics_id in %li and platform = %s', $this->getTable(), $logisticsIds, $platform); + return array_column($rows, 'companyCode', 'logisticsId'); + } + public function getByCompanyId($companyId, $platform) { return $this->queryFirstRow('select * from %b where company_id = %i and platform = %s', $this->getTable(), $companyId, $platform); } diff --git a/app/libs/services/OrderPrint/ExpressTplService.php b/app/libs/services/OrderPrint/ExpressTplService.php index 2a2f3c3..015c6b4 100644 --- a/app/libs/services/OrderPrint/ExpressTplService.php +++ b/app/libs/services/OrderPrint/ExpressTplService.php @@ -792,4 +792,64 @@ class ExpressTplService extends AbstractService { } return $result; } + + public function getAllNetSites($wbUserId, $operatorInfo) { + $accessToken = $operatorInfo['accessToken']; + $searchWaybillRet = PddApi::searchPddWaybill(null, $accessToken, $wbUserId); + CheckClient::checkIsFailRet($searchWaybillRet); + $companyCodeAndNetSitesMap = []; + foreach ($searchWaybillRet['waybillApplyInfos'] as $companyCode => $netSiteInfo) { + $companyCodeAndNetSitesMap[$companyCode] = $this->buildNetSiteList($netSiteInfo); + } + return $companyCodeAndNetSitesMap; + } + + public function getAppliedLogisticsSysExpressTpl($operatorInfo) { + $logisticsList = $this->opSysExpressTplDao->getExistsLogisticsList(); + $logisticsIdAndLogisticsNameMap = array_column($logisticsList, 'logisticsName', 'logisticsId'); + $logisticsIds = array_column($logisticsList, 'logisticsId'); + $companyCodeAndLogisticsIdMap = $this->logisticsPlatformDao->getCompanyCodeAndLogisticsIdMap($logisticsIds, AppConst::appPlatformPdd); + $companyCodeAndNetSitesMap = $this->getAllNetSites(0, $operatorInfo); + $appliedLogisticsList = []; + $appliedLogisticsIds = []; + foreach ($companyCodeAndLogisticsIdMap as $logisticsId => $companyCode) { + if (empty($companyCodeAndNetSitesMap[$companyCode])) { + continue; + } + $appliedLogisticsList[] = [ + 'logisticsId' => strval($logisticsId), + 'logisticsName' => $logisticsIdAndLogisticsNameMap[$logisticsId], + 'netsites' => $companyCodeAndNetSitesMap[$companyCode], + ]; + $appliedLogisticsIds[] = $logisticsId; + } + + if ($appliedLogisticsList) { + $sysExpressTplPageData = $this->getSysExpressTplList(['logisticsIds' => $appliedLogisticsIds, 'waybillType' => LogisticsConst::waybillPdd, 'pageSize' => 50 * count($appliedLogisticsIds)]); + $tplList = $sysExpressTplPageData['list']; + $logisticsIdsAndSysTplMap = ZcArrayHelper::changeKey($tplList, 'logisticsId', true); + foreach ($appliedLogisticsList as &$appliedLogistics) { + $appliedLogistics['sysExpressTplList'] = $this->usortExpressTplList($logisticsIdsAndSysTplMap[$appliedLogistics['logisticsId']]); + } + } + + return $appliedLogisticsList; + } + + private function usortExpressTplList($tplList) { + $scoreList = []; + foreach ($tplList as $tpl) { + if (strpos($tpl['tplName'], '一联') !== false) { + $score = 10; + } elseif (strpos($tpl['tplName'], '二联') !== false) { + $score = 8; + } else { + $score = 0; + } + $scoreList[] = $score; + } + + array_multisort($scoreList, SORT_DESC, $tplList); + return $tplList; + } } \ No newline at end of file