@ -24,7 +24,9 @@ use Dao\OrderPrint\OpUserExpressTplDao;
use Dao\OrderPrint\WbUserMallDao;
use Exception\BizException;
use Exception\CheckClientException;
use OrderPrintConst;
use PddApi;
use PddOAuthUtil;
use Repository\Mall\MallRepository;
use Repository\OrderPrint\SenderAddressRepository;
@ -460,4 +462,179 @@ class ExpressTplService extends AbstractService {
}
return $senderAddress;
}
public function getUserExpressTplList($mallId, $expressType) {
$expressType = in_array($expressType, [OrderPrintConst::expressTypePtmd, OrderPrintConst::expressTypeDzmd, OrderPrintConst::expressTypeCainaoYun]) ? $_POST['type'] : OrderPrintConst::expressTypePtmd;
$expressTplList = $this->expressTplRepository->getUserExpressTplList($mallId, ['expressType' => $expressType]);
$ownerMallIds = array_filter(ZcArrayHelper::getSub($expressTplList, 'ownerMallId'));
$mallIdAndMallNameMap = $this->mallSDao->getMallIdAndMallNameMap($ownerMallIds);
foreach ($expressTplList as & $expressTpl) {
$expressTpl['ownerMallName'] = $mallIdAndMallNameMap[$expressTpl['ownerMallId']];
}
return $expressTplList;
}
public function getAllExpressTplList($mallId) {
$filter = ['status' => StatusConst::normal];
$expressTplList = $this->expressTplRepository->getUserExpressTplList($mallId, $filter);
$ptmdExpressList = array_filter($expressTplList, function ($value) {
return $value['expressType'] == OrderPrintConst::expressTypePtmd;
});
$dzmdExpressList = array_filter($expressTplList, function ($value) {
return $value['expressType'] == OrderPrintConst::expressTypeDzmd;
});
return [
OrderPrintConst::expressTypePtmd => array_values($ptmdExpressList),
OrderPrintConst::expressTypeDzmd => array_values($dzmdExpressList),
];
}
public function getNormalSysExpressTplMap($expressType, $waybillTypes = null, $sort = null, $allColumns = false) {
$logisticsMap = LogisticsConst::getLogisticsMap();
$tplList = $this->opSysExpressTplDao->searchNormalTplList($expressType, $waybillTypes, $sort);
$columns = ['opSysExpressTplId','cpCode','tplName','tplImgUrl', 'waybillType', 'expressType', 'isChildParent'];
$groupTpls = [];
foreach ($tplList as $key => $tpl) {
if (empty($logisticsMap[$tpl['cpCode']])) {
continue;
}
if (!$allColumns) {
$tpl = ZcArrayHelper::filterColumns($tpl, $columns);
}
$tpl['logisticsName'] = $logisticsMap[$tpl['cpCode']];
$tpl['tplImgUrl'] = OrderPrintTool::opPubAbsUrl( $tpl['tplImgUrl']);
if (empty($groupTpls[$tpl['cpCode']])) {
$groupTpls[$tpl['cpCode']] = [
'cpCode' => $tpl['cpCode'],
'logisticsName' => $logisticsMap[$tpl['cpCode']],
'tpls' => [$tpl]
];
} else {
$groupTpls[$tpl['cpCode']]['tpls'][] = $tpl;
}
}
return array_values($groupTpls);
}
public function getSysExpressTpl($tplId, $operatorInfo) {
$sysExpressTpl = $this->opSysExpressTplDao->getFormatedById($tplId);
$sysExpressTpl['tplWidthPx'] = OrderPrintTool::convertMm2Px($sysExpressTpl['tplWidth']);
$sysExpressTpl['tplHeightPx'] = OrderPrintTool::convertMm2Px($sysExpressTpl['tplHeight']);
if (!empty($sysExpressTpl['tplImgUrl'])) {
$sysExpressTpl['tplImgUrl'] = OrderPrintTool::opPubAbsUrl($sysExpressTpl['tplImgUrl']);
}
if (!empty($sysExpressTpl['waybillCoverImg'])) {
$sysExpressTpl['waybillCoverImg'] = OrderPrintTool::opPubAbsUrl($sysExpressTpl['waybillCoverImg']);
}
$serviceList = $this->getServiceList($sysExpressTpl['waybillType'], $sysExpressTpl['cpCode']);
return ['sysExpressTpl' => $sysExpressTpl, 'serviceList' => $serviceList];
}
private function getServiceList($waybillType, $cpCode) {
$serviceList = [];
if ($waybillType == LogisticsConst::waybillWangdian) {
$serviceList = [
$this->getServiceItem('serviceType', $cpCode),
$this->getServiceItem('orderType', $cpCode),
$this->getServiceItem('payType', $cpCode),
];
if ($cpCode == 'ZYKD') {
$serviceList[] = $this->getServiceItem('payType', $cpCode);
$serviceList[] = $this->getServiceItem('insureType', $cpCode);
}
}
return $serviceList;
}
private function getServiceItem($serviceName, $cpCode, $field = null, $name = null, $remark = null) {
$services = [
'serviceType' => [
'name' => '运单类型',
'field' => 'serviceType',
'options' => CommonTool::convertMapToOptions(OrderPrintTool::getWangdianExpressServiceTypeOptions($cpCode)),
'type' => 'select',
],
'orderType' => [
'name' => '订单类型',
'field' => 'orderType',
'options' => CommonTool::convertMapToOptions(OrderPrintTool::getWangdianExpressOrderTypeOptions($cpCode)),
'type' => 'select',
],
'payType' => [
'name' => '运费支付方式',
'field' => 'payType',
'options' => CommonTool::convertMapToOptions(OrderPrintTool::getWangdianExpressPayTypeOptions($cpCode)),
'type' => 'select',
],
'insureType' => [
'name' => '保价',
'field' => 'insureType',
'options' => CommonTool::convertMapToOptions(OrderPrintTool::getGuaranteeTypeMap()),
'type' => 'select',
]
];
$service = $services[$serviceName] ?: null;
if ($service) {
if ($field) {
$service['field'] = $field;
}
if ($name) {
$service['name'] = $name;
}
if ($remark) {
$service['remark'] = $remark;
}
}
return $service;
}
public function getUserExpressDetail($tplId, $operatorInfo) {
$accessToken = $operatorInfo['mallId'];
$mallId = $operatorInfo['accessToken'];
$expressTpl = $this->expressTplRepository->getUserExpressTplById($mallId, $tplId);
$tplMallId = $expressTpl['ownerMallId'] ? : $mallId;
if (empty($expressTpl)) {
throw new CheckClientException('模板不存在');
}
$isWaybill = ($expressTpl['expressType'] == OrderPrintConst::expressTypeDzmd);
$renderData = array(
'expressTpl' => $expressTpl,
'isWaybill' => $isWaybill,
'cropperW' => $isWaybill ? 600 : 980,
'cropperH' => $isWaybill ? 800 : 600,
'defWidth' => $isWaybill ? 100 : 230,
'defHeight' => $isWaybill ? 180 : 126,
);
if (LogisticsConst::isPddWlb($expressTpl['waybillType'])) {
$pddLogisticsCode = $this->logisticsPlatformDao->getCompanyCodeByLogisticsId($expressTpl['logisticsId'], AppConst::appPlatformPdd);
$searchWaybillRet = PddApi::searchPddWaybill($pddLogisticsCode, $accessToken, $expressTpl['wbUserId']);
$waybillApplyInfo = $searchWaybillRet['waybillApplyInfos'][$pddLogisticsCode];
$renderData['pddWaybillBranchList'] = $waybillApplyInfo['branch_account_cols'];
} elseif ($isWaybill & & LogisticsConst::isWangdianWlb($expressTpl['waybillType'])) {
$renderData['serviceTypeOptions'] = OrderPrintTool::getWangdianExpressServiceTypeOptions($expressTpl['logisticsCode']);
$renderData['orderTypeOptions'] = OrderPrintTool::getWangdianExpressOrderTypeOptions($expressTpl['logisticsCode']);
}
$renderData['pddWayBillUserMap'] = $this->getPddWayBillUserMap($tplMallId);
$renderData['authUrl'] = PddOAuthUtil::buildWbAuthUrl();
$renderData['serviceList'] = $this->getServiceList($expressTpl['waybillType'], $expressTpl['cpCode']);
return $renderData;
}
public function getPddWayBillUserMap($mallId) {
$userList = $this->wbUserMallDao->getListByMallId($mallId);
$mallInfo = $this->mallRepository->getMallInfo($mallId);
$userMap = [
0 => $mallInfo['mallName']
];
foreach ($userList as $user) {
$userMap[$user['wbUserId']] = $user['userName'].'(站外授权)';
}
return $userMap;
}
}