You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pdd-order-api/app/libs/tool/class.OrderPrintTool.php

1119 lines
39 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
class OrderPrintTool{
public static function convertTplInfo($tpl) {
$tplData = array(
'expressId' => $tpl['op_user_express_tpl_id'],
'tplName' => $tpl['tpl_name'],
'width' => $tpl['tpl_width'],
'height' => $tpl['tpl_height'],
'x' => $tpl['offset_x'],
'y' => $tpl['offset_y'],
'hasHole' => $tpl['has_hole'] ? true : false,
'imageUrl' => OrderPrintTool::opPubAbsUrl($tpl['tpl_img_url']),
'templateUrl' => $tpl['template_url'],
'logisticsId' => $tpl['logistics_id'],
'logisticsCode' => $tpl['logistics_code'],
'expressType' => $tpl['express_type'],
'waybillType' => (empty($tpl['waybill_type']) && $tpl['express_type'] == OrderPrintConst::expressTypePtmd) ? LogisticsConst::waybillPuTong : $tpl['waybill_type'],
'waybillAccount' => $tpl['waybill_account'],
'printer' => $tpl['printer'],
'printSecondSectionWatermark' => $tpl['print_second_section_watermark'] ? 1 : 0,
'isChildParent' => $tpl['is_child_parent'] ? 1 : 0,
'globalStyle' => $tpl['global_style'],
'custom_area_width' => $tpl['custom_area_width'],
'custom_area_height' => $tpl['custom_area_height'],
);
$globalStyle = $tpl['global_style'];
$nodes = array();
foreach ($tpl['position_map'] as $pos) {
$nv = $pos['nv'];
$style = $pos['style'];
$newStyle = array();
$newStyle['top'] = self::convertPx2Mm($style['top']);
$newStyle['left'] = self::convertPx2Mm($style['left']);
$newStyle['width'] = self::convertPx2Mm($style['width']);
$newStyle['height'] = self::convertPx2Mm($style['height']);
$fontSize = !empty($style['font-size']) ? $style['font-size'] : $globalStyle['fontSize'];
$fontSize = (stripos($fontSize, 'px') !== false) ? self::convertPx2Pt($fontSize) : round(preg_replace('/[^\d+|\.]/isU', '', $fontSize));
$newStyle['fontSize'] = $fontSize;
$newStyle['textAlign'] = in_array($style['text-align'], array('center', 'right')) ? $style['text-align'] : 'left';
$newStyle['fontStyle'] = !empty($style['font-style']) ? $style['font-style'] : '';
$newStyle['fontWeight'] = !empty($style['font-weight']) ? $style['font-weight'] : $globalStyle['fontWeight'];
$newStyle['fontFamily'] = empty($style['font-family']) ? $globalStyle['fontFamily'] : $style['font-family'];
if ($nv['field'] == 'line') {
($nv['lineType'] == 'horizontal') ? ($newStyle['height'] = '1') : ($newStyle['width'] = '1');
}
$pos['style'] = $newStyle;
if ($nv['field'] == 'itemTable') {
$tplData['itemTable'] = $pos;
} else {
$nodes[] = $pos;
}
}
$tplData['nodes'] = $nodes;
return $tplData;
}
public static function printSenderAddress($senderAddress, $return = false) {
$string = sprintf('%s %s %s %s %s %s %s', $senderAddress['fullname'], $senderAddress['mobile'], $senderAddress['telephone'], $senderAddress['province'], $senderAddress['city'], $senderAddress['county'], $senderAddress['address']);
if ($return) {
return $string;
}
echo Zc::sh($string);
}
public static function formatSenderAddress($senderAddress) {
if (empty($senderAddress)) {
return array();
}
return array (
'province' => $senderAddress['province'],
'provinceAreaId' => $senderAddress['province_area_id'],
'city' => $senderAddress['city'],
'cityAreaId' => $senderAddress['city_area_id'],
'county' => $senderAddress['county'],
'countyAreaId' => $senderAddress['county_area_id'],
'fullname' => $senderAddress['fullname'],
'address' => $senderAddress['address'],
'mobile' => $senderAddress['mobile'],
'telephone' => $senderAddress['telephone']
);
}
public static function formartOrderDetailNv($orderDetail) {
$nvMap = array(
'orderId' => 'orderId',
'orderSn' => 'orderSn',
'orderStatus' => 'orderStatus',
'orderStatusName' => 'orderStatusName',
'payType' => 'payType',
'goodsAmount' => 'goodsAmount',
'payAmount' => 'payAmount',
'freePostage' => 'freePostage',
'discountAmount' => 'discountAmount',
'platformDiscount' => 'platformDiscount',
'sellerDiscount' => 'sellerDiscount',
'capitalFreeDiscount' => 'capitalFreeDiscount',
'createdTime' => 'orderStartTime',
'confirmTime' => 'confirmTime',
'receiveTime' => 'receiveTime',
'shippingTime' => 'shippingTime',
'updatedAt' => 'modified',
'lastShipTime' => 'lastShipTime',
'remark' => 'sellerMemo',
'sellerNote' => 'sellerNote',
'remarkTag' => 'remarkTag',
'buyerMemo' => 'buyerMemo',
'trackingNumber' => 'waybillCode',
'printExpressStatus' => 'printExpressStatus',
'printInvoiceStatus' => 'printInvoiceStatus',
'gmtPrintExpress' => 'gmtPrintExpress',
'gmtPrintInvoice' => 'gmtPrintInvoice',
'gmtCreate' => 'gmtCreate',
'goodsList' => 'items'
);
$tradeRow = array();
foreach ($orderDetail as $key => $value) {
if (array_key_exists($key, $nvMap)) {
if ($key == 'goodsList') {
$value = self::formartOrderGoodsInfoNv($value);
}
$tradeRow[$nvMap[$key]] = $value;
}
}
return $tradeRow;
}
public static function formartOrderGoodsInfoNv($orderGoodsList) {
$nvMap = array(
'goodsId' => 'goodsId',
'orderId' => 'orderId',
'skuId' => 'skuId',
'goodsName' => 'goodsName',
'skuName' => 'skuName',
'goodsPrice' => 'goodsPrice',
'outerGoodsId' => 'outerGoodsId',
'outerId' => 'outerId',
'goodsCount' => 'goodsCount',
'totalPrice' => 'totalPrice',
'goodsImg' => 'goodsImg',
'goodsSpec' => 'goodsSpec',
'shortTitle' => 'shortTitle',
'weight' => 'weight',
'shortWeight' => 'shortWeight',
'isShipped' => 'isShipped',
'isCanPrint' => 'isCanPrint',
'skPhortTitle' => 'skuShortTitle',
'wareShortTitle' => 'wareShortTitle',
'skuSubName' => 'skuSubName',
'opTrderGoodsId' => 'itemId',
'mallId' => 'mallId',
);
$nvGoodsList = array();
$i = 0;
foreach ($orderGoodsList as $key => $goods) {
$nvGoods = array();
foreach ($goods as $n => $value) {
if (array_key_exists($n, $nvMap)) {
$nvGoods[$nvMap[$n]] = $value;
}
}
$nvGoodsList[$i] = $nvGoods;
$i ++;
}
return $nvGoodsList;
}
public static function formartCustomOrderDetailNv($orderDetail) {
$nvMap = array(
'customCrderId' => 'orderId',
'bizOrderNum' => 'orderSn',
'orderStatus' => 'orderStatus',
'orderStatusName' => 'orderStatusName',
'payType' => 'payType',
'goodsAmount' => 'goodsAmount',
'payAmount' => 'payAmount',
'postage' => 'postage',
'discountAmount' => 'discountAmount',
'buyerMemo' => 'buyerMemo',
'waybill' => 'waybill',
'paymentConfirmTime' => 'paymentConfirmTime',
'logisticsId' => 'logisticsId',
'logisticsName' => 'logisticsName',
'orderStartTime' => 'orderStartTime',
'remark' => 'sellerMemo',
'printExpressStatus' => 'printExpressStatus',
'printInvoiceStatus' => 'printInvoiceStatus',
'expressType' => 'expressType',
'isShipped' => 'isShipped',
'gmtPrintExpress' => 'gmtPrintExpress',
'gmtPrintInvoice' => 'gmtPrintInvoice',
'gmtShipped' => 'gmtShipped',
'gmtCreate' => 'gmtCreate',
'goodsList' => 'items'
);
$tradeRow = array();
foreach ($orderDetail as $key => $value) {
if (array_key_exists($key, $nvMap)) {
if ($key == 'goodsList') {
$value = self::formartCustomOrderGoodsInfoNv($value);
}
$tradeRow[$nvMap[$key]] = $value;
}
}
return $tradeRow;
}
public static function formartCustomOrderGoodsInfoNv($orderGoodsList) {
$nvMap = array(
'customGoodsInfoId' => 'itemId',
'orderId' => 'orderId',
'skuId' => 'skuId',
'title' => 'title',
'goodsName' => 'goodsName',
'skuName' => 'skuName',
'goodsPrice' => 'goodsPrice',
'outerGoodsId' => 'outerGoodsId',
'outerId' => 'outerId',
'goodsCount' => 'goodsCount',
'totalPrice' => 'totalPrice',
'goodsImg' => 'goodsImg',
'goodsSpec' => 'goodsSpec',
'shortTitle' => 'shortTitle',
'weight' => 'weight',
'shortWeight' => 'shortWeight',
'isShipped' => 'isShipped',
'isCanPrint' => 'isCanPrint'
);
$nvGoodsList = array();
foreach ($orderGoodsList as $key => $goods) {
$nvGoods = array();
foreach ($goods as $n => $value) {
if (array_key_exists($n, $nvMap)) {
$nvGoods[$nvMap[$n]] = $value;
}
}
$nvGoodsList[$key] = $nvGoods;
}
return $nvGoodsList;
}
public static function getColorAndOrderFlagMap() {
return [
'red' => '1',
'orange' => '2',
'green' => '3',
'blue' => '4',
'purple' => '5',
];
}
public static function getOrderFlagColor($orderFlag) {
return array_search($orderFlag, self::getColorAndOrderFlagMap());
}
public static function getOrderFlags($colors) {
$flags = [];
$map = self::getColorAndOrderFlagMap();
foreach ($colors as $color) {
if ($map[$color]) {
$flags[] = $map[$color];
}
}
return $flags;
}
public static function getTagAndTagNameMap() {
return [
1 => '红色',
2 => '黄色',
3 => '绿色',
4 => '蓝色',
5 => '紫色',
];
}
public static function getOrderFlag($flag = null) {
$flagImgs = array(
'1' => 'flag-red.png',
'2' => 'flag-yellow.png',
'3' => 'flag-green.png',
'4' => 'flag-blue.png',
'5' => 'flag-purple.png',
);
return $flagImgs[$flag] ? $flagImgs[$flag] : $flagImgs;
}
public static function buildOrderFlagUrl($flag) {
$flagImgs = self::getOrderFlag();
$flagImg = $flagImgs[$flag];
if (!$flagImg) {
return null;
}
return HtmlTool::getStaticUrl('img/flags/' . $flagImg);
}
public static function formatWlbWangdianData($waybillInfo, $subIndex = 0, $printSecondSectionWatermark, $width) {
if ($subIndex == 0) {
$waybillCode = $waybillInfo['waybillCode'];
} else {
$waybillCode = $waybillInfo['subWaybillCodes'][$subIndex - 1];
}
if ($printSecondSectionWatermark) {
$routeCodeArray = explode(' ', $waybillInfo['shortName']);
$secondSectionCode = count($routeCodeArray) == 1 ? $routeCodeArray[0] : $routeCodeArray[1];
$secondSectionCodeWatermark = self::generateSecondSectionCodeWatermark($secondSectionCode, $width);
}
return array(
LogisticsConst::wlbCode => $waybillCode,
LogisticsConst::wlbBarcode => $waybillCode,
LogisticsConst::parentWlbCode => $waybillInfo['waybillCode'],
LogisticsConst::originName => $waybillInfo['originName'],
LogisticsConst::originCode => $waybillInfo['originCode'],
LogisticsConst::consolidationName => $waybillInfo['consolidationName'],
LogisticsConst::consolidationCode => $waybillInfo['consolidationCode'],
LogisticsConst::targetName => $waybillInfo['targetName'],
LogisticsConst::targeCode => $waybillInfo['targeCode'],
LogisticsConst::shortName => $waybillInfo['shortName'],
LogisticsConst::secondSectionCodeWatermark => $secondSectionCodeWatermark,
LogisticsConst::secondSectionCode => empty($secondSectionCode) ? '' : $secondSectionCode,
'isChildWaybill' => $subIndex == 0 ? 0 : 1
);
}
public static function formatPddWlbData($pddData) {
$routingInfo = $pddData['routingInfo'];
return array(
LogisticsConst::wlbCode => $pddData['waybillCode'],
LogisticsConst::wlbBarcode => $pddData['waybillCode'],
LogisticsConst::consolidationName => $routingInfo['endBranchName'],
LogisticsConst::shortName => $routingInfo['bigShotName'],
);
}
public static function opPubAbsUrl($relUrl) {
if (empty($relUrl)) {
return '';
}
return OssTool::getPubOssUrlByOssPath($relUrl);
}
public static function convertMm2Px($mm) {
$unit = 3.779528;
return round($mm * $unit);
}
public static function convertPx2Mm($px) {
$px = preg_replace('/[^\d+|\.]/isU', '', $px);
$unit = 0.264583;
return round($px * $unit, 1);
}
public static function convertPx2Pt ($px){
$px = preg_replace('/[^\d+|\.]/isU', '', $px);
$unit = 0.75;
return round($px * $unit, 2);
}
public static function convertPx2PddUnit($px) {
$px = preg_replace('/[^\d+|\.]/isU', '', $px);
$unit = 2.11640212;
return round($px * $unit, 1);
}
public static function convertMm2PddUnit($mm) {
$mm = preg_replace('/[^\d+|\.]/isU', '', $mm);
$unit = 8;
return round($mm * $unit, 1);
}
public static function convertPt2PddUnit($pt) {
$pt = preg_replace('/[^\d+|\.]/isU', '', $pt);
$unit = 2.82186949;
return round($pt * $unit, 1);
}
public static function mockWaybillInfo($waybillType) {
if ($waybillType == LogisticsConst::waybillJd) {
return array (
LogisticsConst::wlbCode => 'VC3421697441',
LogisticsConst::wlbBarcode => 'VC3421697441',
LogisticsConst::originName => '广州萝岗分拣中心',
LogisticsConst::originCode => '95-C-02-E',
LogisticsConst::targetName => '厦门分拨中心',
LogisticsConst::targeCode => '41-E-03',
LogisticsConst::shortName => '三明永安站'
);
}
return array(
LogisticsConst::wlbCode => '9890000160004',
LogisticsConst::wlbBarcode => '9890000160004',
LogisticsConst::parentWlbCode => '9890000160004',
LogisticsConst::originName => '福田G',
LogisticsConst::originCode => '210901',
LogisticsConst::targetName => '厦门分拨中心',
LogisticsConst::targeCode => '41-E-03',
LogisticsConst::shortName => '440-517'
);
}
public static function mockPddWaybillPrintData($wpCode, $sender, $tplWidth) {
$printData = array(
'waybillCode' => '78100279647394',
'wpCode' => $wpCode,
'routingInfo' => array(
'bigShotName' => '211- 11-51 08',
'endBranchName' => '福州转长乐',
'threeSegmentCode' => '211- 11-51 08',
'objectId' => 1
),
'sender' => array(
'address' => array(
'province' => $sender['province'],
'city' => $sender['city'],
'district' => $sender['district'],
'detail' => $sender['address']
),
'mobile' => $sender['mobile'],
'name' => $sender['fullname']
),
'recipient' => array(
'address' => array(
'province' => '福建省',
'city' => '福州市',
'district' => '长乐市',
'detail' => 'xxxxxxxxxxxxxxxxx'
),
'mobile' => '18000000000',
'name' => '张三',
'phone' => '18000000000'
),
'signature' => '843632A8F61CAA46B8ACC592D2F477EE',
'templateUrl' => 'https://t16img.yangkeduo.com/mms_static/277e5d78f36b8d43eb0d3f921ee2107d.xml'
);
if ($tplWidth == 76) {
$printData['templateUrl'] = 'http://pinduoduoimg.yangkeduo.com/print_template/2019-06-05/5ab595d3a375e28818c3915bd9117745.xml';
}
return $printData;
}
public static function getPrintOrderPageSizeArray() {
return array(20, 50, 100, 200, 500, 1000);
}
public static function getOpSortTypeMap() {
return array(
'paymentConfirmTimeAsc' => '成团时间↑',
'paymentConfirmTimeDesc' => '成团时间↓',
'payTimeAsc' => '付款时间↑',
'payTimeDesc' => '付款时间↓',
'payAmountAsc' => '订单金额↑',
'payAmountDesc' => '订单金额↓',
'lastShipTimeAsc' => '剩余发货时间↑',
'lastShipTimeDesc' => '剩余发货时间↓',
'printExpressTimeAsc' => '打印时间↑',
'printExpressTimeDesc' => '打印时间↓',
'shippingTimeTimeAsc' => '发货时间↑',
'shippingTimeTimeDesc' => '发货时间↓',
'goodsAndSkuIdAsc' => '商品、SKU排序↑',
'goodsAndSkuIdDesc' => '商品、SKU排序↓',
);
}
public static function getFdsOrderSortTypeMap() {
return array(
'allowTimeAsc' => '分配时间↑',
'allowTimeDesc' => '分配时间↓',
'goodsNumberAsc' => '商品数量↑',
'goodsNumberDesc' => '商品数量↓',
);
}
public static function getPrintOrderSortTypeMap() {
return array(
'orderStartTimeDesc' => '下单时间↓',
'orderStartTimeAsc' => '下单时间↑',
'paymentConfirmTimeDesc' => '成团时间↓',
'paymentConfirmTimeAsc' => '成团时间↑',
'shippingTimeDesc' => '订单发货时间↓',
'shippingTimeAsc' => '订单发货时间↑',
);
}
public static function getExportFieldsMap() {
$fieldsMap = array(
'orderFields' => array(
'orderSn' => '订单编号',
'shopName' => '店铺名称',
'orderStatusName' => '订单状态',
'payType' => '支付方式',
'postage' => '运费',
'goodsAmount' => '订单商品金额',
'payAmount' => '实付金额',
'discountAmount' => '优惠金额',
),
'purchaseFields' => array(
'purchasePlatform' => '采购平台',
'purchaseOrderBuyer' => '采购账号',
'purchaseOrderSn' => '采购订单号',
'purchaseOrderStartTime' => '采购下单时间',
'purchaseAlipayMerchantNo' => '商户单号',
'purchasePrice' => '采购金额',
),
'itemFields' => array(
'goodsName' => '标题',
'goodsId' => '商品ID',
'outerGoodsId' => '外部商品编码',
'outerId' => '外部SKU编码',
'wareShortTitle' => '商品简称',
'skuShortTitle' => 'SKU简称',
'goodsSpec' => '规格',
'goodsCount' => '数量',
'goodsPrice' => '单价',
'totalPrice' => '商品总额'
),
'receiveFields' => array(
'bFullname' => '收件人',
'bTelephone' => '固话',
'bMobile' => '手机',
'bFullAddress' => '收货地址',
'orderLogisticsInfo' => '订单物流信息',
'purchaseLogisticsInfo' => '采购物流信息'
),
'otherFields' => array(
'sellerMemo' => '商家备注',
'sellerNote' => '本地备注',
'orderStartTime' => '下单时间'
)
);
return $fieldsMap;
}
public static function getSysDefaultExportFields() {
$fields = array(
'orderFields' => array(
'orderSn',
'orderStatusName',
'payType',
'postage',
'goodsAmount',
'payAmount',
'discountAmount'
),
'itemFields' => array(
'goodsName',
'outerGoodsId',
'outerId',
'goodsSpec',
'goodsCount',
'goodsPrice',
'totalPrice'
),
'receiveFields' => array(
'bFullname',
'bMobile',
'bFullAddress'
),
'otherFields' => array(
'buyerMemo',
'sellerMemo',
'orderStartTime'
)
);
return $fields;
}
public static function getWangdianExpressServiceTypeOptions($logisticsCode) {
if ($logisticsCode == LogisticsConst::SF) {
return array(
'1' => '顺丰特快',
'2' => '顺丰标快',
'6' => '顺丰即日',
'10' => '国际小包',
'12' => '国际特惠配送',
'23' => '顺丰国际特惠(文件)',
'24' => '顺丰国际特惠(包裹)',
'29' => '国际电商专递-标准',
'30' => '三号便利箱(特快)',
'31' => '便利封/袋(特快)',
'32' => '二号便利箱(特快)',
'33' => '岛内件(80CM)',
'35' => '物资配送',
'39' => '岛内件(110CM)',
'50' => '千点取60',
'53' => '电商盒子F1',
'54' => '电商盒子F2',
'59' => 'E顺递',
'60' => '顺丰特快(文件)',
'61' => 'C1类包裹',
'111' => '顺丰干配',
'153' => '整车直达',
'154' => '重货包裹',
'155' => '标准零担',
'199' => '特快包裹',
'201' => '冷运标快',
'202' => '顺丰微小件',
'209' => '高铁专送',
'215' => '大票直送',
'221' => '香港冷运到家(≤60厘米)',
'229' => '精温专递',
'231' => '陆运包裹',
'233' => '精温专递(样本陆)',
'235' => '极效前置-预售',
'238' => '纯重特配',
'242' => '丰网速运',
'247' => '电商标快',
'250' => '极置店配',
'255' => '顺丰卡航',
'256' => '顺丰卡航D类',
'257' => '退换上门',
'258' => '退换自寄',
'260' => '入仓电标',
'261' => 'O2O店配',
'263' => '同城半日达',
'265' => '预售电标',
'266' => '顺丰空配(新)',
'283' => '填舱标快',
'285' => '填舱电标',
);
} elseif ($logisticsCode == LogisticsConst::YTO) {
return array(
'1' => '标准快递',
'2' => '次日达',
'4' => '次晨达',
'8' => '当日达',
);
} else {
return array(
'1' => '标准快递',
);
}
}
public static function getWangdianExpressOrderTypeOptions($logisticsCode) {
if (in_array($logisticsCode, array(LogisticsConst::SF, LogisticsConst::YUNDA, LogisticsConst::YTO))) {
return array(
'1' => '普通订单',
'2' => '货到付款'
);
} else {
return array(
'1' => '普通订单'
);
}
}
public static function getWangdianExpressPayTypeOptions($cpCode){
if($cpCode == LogisticsConst::ZYKD){
return [
LogisticsConst::zhongyouPayTypeSendPay => '寄付',
LogisticsConst::zhongyouPayTypeReceiverPay => '到付',
LogisticsConst::zhongyouPayTypeMonthPay => '月结'
];
}else{
return [];
}
}
public static function getGuaranteeTypeMap() {
return array(
LogisticsConst::guaranteeTypeNo => '不保价',
LogisticsConst::guaranteeTypeOrderAmount => '订单金额保价',
LogisticsConst::guaranteeTypeCustom => '声明价值保价'
);
}
public static function getJdAlphaOrderPayTypeOptions() {
return array(
'1' => '普通订单',
);
}
public static function getJdAlphaOrderWaybillTypeOptions() {
return array(
LogisticsConst::jdAlphaWaybillTypeNormal => '普通运单',
LogisticsConst::jdAlphaWaybillTypeFresh => '生鲜',
LogisticsConst::jdAlphaWaybillTypeAir => '航空',
);
}
public static function getJdAlphaOrderExpressTypeOptions() {
return array(
LogisticsConst::jdAlphaSfExpressTypeMorrow => '顺丰次日',
LogisticsConst::jdAlphaSfExpressTypeNextDay => '顺丰隔日'
);
}
public static function getOrderPrintExpressLogExportForPddFieldsMap() {
$fieldsMap = array(
'order_sn' => '订单号',
'shipping_name' => '快递公司(必填)',
'shipping_sn' => '快递单号',
);
return $fieldsMap;
}
public static function getOrderPrintExpressLogExportFieldsMap() {
$fieldsMap = array(
'mallName' => '店铺',
'orderSn' => '订单号',
'waybillCode' => '物流单号',
'logisticsName' => '物流公司',
'expressTplName' => '打印模板',
'fullname' => '收货人',
'mobile' => '收货人手机',
'fullAddress' => '收货地址',
'printTime' => '打印日期',
'senderName' => '发货人',
'senderMobile' => '发货人手机',
'senderAddress' => '发货地址',
'sellerMemo' => '卖家备注',
'buyerMemo' => '买家备注',
'sellerNote' => '订单便签',
'payAmount' => '订单金额',
'goodsName' => '商品标题',
'goodsId' => '商品ID',
'goodsSpec' => '商品规格',
'skuId' => 'SKUID',
'outerId' => 'SKU编码',
'goodsCount' => '数量',
);
return $fieldsMap;
}
public static function getCustomPrintExpressLogExportFieldsMap() {
$fieldsMap = array(
'mallName' => '店铺',
'orderSn' => '订单号',
'waybillCode' => '物流单号',
'logisticsName' => '物流公司',
'expressTplName' => '打印模板',
'fullname' => '收货人',
'mobile' => '收货人手机',
'fullAddress' => '收货地址',
'printTime' => '打印日期',
'senderName' => '发货人',
'senderMobile' => '发货人手机',
'senderAddress' => '发货地址',
'sellerMemo' => '卖家备注',
'buyerMemo' => '买家备注',
'payAmount' => '订单金额',
'goodsName' => '商品标题',
'goodsId' => '商品ID',
'goodsSpec' => '商品规格',
'skuId' => 'SKUID',
'outerId' => 'SKU编码',
'goodsCount' => '数量',
);
return $fieldsMap;
}
public static function formateReceiverAddressHtml($province, $city, $county, $address) {
$search = array(
'乡',
'镇',
'村',
);
$replace = array(
'<span class="red"><strong>乡</strong></span>',
'<span class="red"><strong>镇</strong></span>',
'<span class="red"><strong>村</strong></span>',
);
$county = str_replace($search, $replace, $county);
$address = str_replace($search, $replace, $address);
return sprintf('<span class="mr_5">%s</span><span class="mr_5">%s</span><span class="mr_5">%s</span><span>%s</span>', $province, $city, $county, $address);
}
public static function joinFullAddress($province, $city, $county, $address) {
return sprintf('%s%s%s%s', $province, $city, $county, $address);
}
public static function replaceTplImageFieldsImgSrcToOssUrl($nodes) {
foreach ($nodes as &$node) {
if (empty($node['imgSrc']) || !preg_match('/^(data:\s*image\/(\w+);base64,)/', $node['imgSrc'])) {
continue;
}
$uploadRet = OrderPrintTool::uploadTplImageToOss($node['imgSrc']);
if (CommonTool::isFailRet($uploadRet)) {
return CommonTool::failResult("上传图片失败: " . $uploadRet['reason']);
}
$node['imgSrc'] = '';
$node['imgPath'] = $uploadRet['ossPath'];
}
return CommonTool::successResult('nodes', $nodes);
}
public static function uploadTplImageToOss($imgDataBase64) {
if (!preg_match('/^(data:\s*image\/(\w+);base64,)/', $imgDataBase64, $result)) {
return CommonTool::failResult('数据格式错误');
}
$ext = $result[2];
if (!in_array($ext, array('jpg', 'jpeg', 'gif', 'png'))) {
return CommonTool::failResult('只允许上传jpg、png、gif的图片');
}
$dir = 'tpl/image/' . date('Y-m-d') . '/';
$name = CommonTool::getUuidName() . '.' . $ext;
$baseUrl = $dir . $name;
$ret = OssClient::uploadImmutableObjectByContent(Zc::C('honor-pub.bucket'), $baseUrl, base64_decode(str_replace($result[1], '', $imgDataBase64)));
if (CommonTool::isFailRet($ret)) {
return $ret;
}
return CommonTool::successResult(array(
'ossPath' => $baseUrl,
));
}
public static function getPddCustomAreaTemplateUrl($tplWidth) {
if ($tplWidth == 76) {
return HtmlTool::getStaticUrl('pdd_one_united_custom_template.xml?20220629');
} else {
return HtmlTool::getStaticUrl('pdd_custom_template.xml?20220629');
}
}
public static function buildWarehouseShelvesKey($warehouse, $shelves) {
return sprintf('%s_%s', $warehouse, $shelves);
}
public static function generateSecondSectionCodeWatermark($secondSectionCode, $width = 377, $height = 74) {
if (empty($secondSectionCode)) {
return '';
}
$codeCharCount = mb_strlen($secondSectionCode, 'utf-8');
$dir = Zc::C('temp.dir') . 'runtime/second_section_code_watermark/' . explode('-', $secondSectionCode)[0] . '/';
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$filename = $dir . md5($secondSectionCode) . '_' . $width . '_px.png';
if (file_exists($filename)) {
return 'data:image/png;base64,' . base64_encode(file_get_contents($filename));
}
$im = imagecreatetruecolor($width, $height);
$bg = imagecolorallocatealpha($im, 255, 255, 255, 127);
$fontColor = imagecolorallocate($im, 86, 87, 89);
imagealphablending($im , false);
imagefilledrectangle($im, 0, 0, $width, $height, $bg);
$font = Zc::C(ZcConfigConst::DirFsApp) . 'views/static/fonts/fzch.ttf';
$fontSize = 70;
$textWidth = 0;
$maxTextWidth = $width - 35;
$maxTextHeight = $height - 5;
$loop = 0;
$x = 0;
$y = 0;
do {
if (++$loop > 10) {
break;
}
$box = imagettfbbox($fontSize, 0, $font, $secondSectionCode);
$minX = min(array($box[0], $box[2], $box[4], $box[6]));
$maxX = max(array($box[0], $box[2], $box[4], $box[6]));
$minY = min(array($box[1], $box[3], $box[5], $box[7]));
$maxY = max(array($box[1], $box[3], $box[5], $box[7]));
$textWidth = $maxX - $minX;
$textHeight = $maxY - $minY;
if ($textWidth <= $maxTextWidth) {
$x = ceil(($width - $textWidth) / 2);
$textHeight = $maxY - $minY;
$y = $height - ceil(($height - $textHeight) / 2);
break;
}
$fontSize = ceil($fontSize * ($maxTextWidth /$textWidth));
if ($textWidth > $maxTextWidth || $textHeight > $maxTextHeight) {
$fontSize --;
}
} while(true);
imagettftext($im, $fontSize, 0, ($x - 5), $y, $fontColor, $font, $secondSectionCode);
imagesavealpha($im , true);
imagepng($im, $filename);
imagedestroy($im);
return 'data:image/png;base64,' . base64_encode(file_get_contents($filename));
}
public static function getPurchaseOrderExportFieldsMap() {
$fieldsMap = array(
'purchaseOrderFields' => array(
'purchaseOrderSeller' => '采购店铺',
'purchasePlatform' => '采购平台',
'purchaseOrderBuyer' => '采购账号',
'purchaseOrderSn' => '采购单号',
'purchaseOrderStartTime' => '采购时间',
'purchaseOrderStatusText' => '采购单状态',
'gmtLastCheckStatus' => '采购单同步时间',
'purchaseOrderPayment' => '采购实付金额',
),
'itemFields' => array(
'goodsName' => '商品标题',
'goodsId' => '商品编码ID',
'skuId' => 'SKU ID',
'skuSubName' => '商品规格',
'itemTotal' => '商品数量',
'goodsPrice' => '商品单价',
),
'orderFields' => array(
'relationStatus' => '采购单是否关联拼多多订单',
'orderSn' => '订单号',
'confirmTime' => '成团时间',
'orderStatusText' => '订单状态',
'mallName' => '店铺名称',
),
);
return $fieldsMap;
}
public static function formatOrderPromise($orderPromiseList, $companyCodeAndLogisticsInfoMap) {
if (empty($orderPromiseList)) {
return [];
}
$newOrderPromiseList = [];
foreach ($orderPromiseList as $orderPromiseInfo) {
$logisticsName = $companyCodeAndLogisticsInfoMap[$orderPromiseInfo['logistics_code']]['logistics_name'];
$newOrderPromiseList[] = [
'promiseId' => $orderPromiseInfo['promise_id'],
'sceneType' => $orderPromiseInfo['scene_type'],
'promiseType' => $orderPromiseInfo['promise_type'],
'promiseDesc' => $orderPromiseInfo['promise_desc'],
'promiseStatus' => $orderPromiseInfo['promise_status'],
'promiseLevel' => $orderPromiseInfo['promise_level'],
'updatedAt' => $orderPromiseInfo['updated_at'],
'promiseDeliveryTime' => $orderPromiseInfo['promise_delivery_time'],
'logisticsCode' => $orderPromiseInfo['logistics_code'],
'logisticsName' => empty($logisticsName) ? '' : $logisticsName,
'wrapperDescription' => $orderPromiseInfo['wrapper_description'],
];
}
return $newOrderPromiseList;
}
public static function getExportExpressLogItemFields(){
return ['goodsName', 'goodsId', 'itemSkuId', 'goodsSpec', 'skuId', 'outerId', 'goodsCount'];
}
public static function checkNeedJoinItem($fields){
$need = false;
$result = array_intersect($fields, self::getExportExpressLogItemFields());
if(!empty($result)){
$need = true;
}
return $need;
}
public static function buildOrderPreMergeKey($fullnameSmd5, $mobileSmd5) {
return CommonTool::smd5Value($fullnameSmd5 . $mobileSmd5);
}
public static function formartOrderGiftsInfoNv($orderGoodsList) {
$nvMap = array(
'goods_id' => 'goodsId',
'order_id' => 'orderId',
'sku_id' => 'skuId',
'goods_name' => 'goodsName',
'goods_price' => 'goodsPrice',
'outer_goods_id' => 'outerGoodsId',
'outer_id' => 'outerId',
'goods_count' => 'goodsCount',
'total_price' => 'totalPrice',
'goods_img' => 'goodsImg',
'goods_spec' => 'goodsSpec',
'short_title' => 'shortTitle',
'weight' => 'weight',
'short_weight' => 'shortWeight',
'is_can_print' => 'isCanPrint',
'sku_short_title' => 'skuShortTitle',
'ware_short_title' => 'wareShortTitle',
'sku_name' => 'skuName',
'sku_sub_name' => 'skuSubName',
);
$nvGoodsList = array();
$i = 0;
foreach ($orderGoodsList as $key => $goods) {
$nvGoods = array();
foreach ($goods as $n => $value) {
if (array_key_exists($n, $nvMap)) {
$nvGoods[$nvMap[$n]] = $value;
}
}
$nvGoods['isGift'] = 1;
$nvGoodsList[$i] = $nvGoods;
$i ++;
}
return $nvGoodsList;
}
public static function getFastSearchOrderFilterOptions() {
return [
'' => '不限订单',
'postage' => '包邮订单',
'isTown' => '乡、村、镇订单',
'lastShippingTimeTip' => '待发货提醒订单',
'hasMerge' => '合并订单',
'notMerge' => '未合并订单',
'preSale' => '预售订单',
'notPreSale' => '非预售订单',
'sfExpress' => '顺丰加价',
'freeSfExpress' => '顺丰包邮',
'sfOrFreeSfExpress' => '顺丰加价或顺丰包邮',
'platformAndSellerDiscount' => '平台优惠券+店铺优惠券',
'platformDiscount' => '平台优惠券',
'sellerDiscount' => '店铺优惠券',
'designatedPackingMaterial' => '指定包材',
'notDesignatedPackingMaterial' => '未指定包材',
'priorityDelivery' => '优先发货承诺',
'notPriorityDelivery' => '无优先发货承诺',
'designatedExpress' => '指定快递承诺',
'notDesignatedExpress' => '无指定快递承诺',
'abnormalReceiveArea' => '地址异常',
'notAbnormalReceiveArea' => '无地址异常',
'noTraceDelivery' => '无痕发货订单',
'notNoTraceDelivery' => '非无痕发货订单',
'hasGift' => '有赠品',
'notGift' => '无赠品',
'hasExtraDelivery' => '有额外包裹',
'notExtraDelivery' => '无额外包裹',
'onlyShowRemoteAreaOrder' => '偏远地区订单',
'isRegionBlackDelayShipping' => '可延迟发货',
'notRegionBlackDelayShipping' => '非可延迟发货',
'hasSubsidyPostage' => '补贴运费红包',
'isCommunityGroup' => '小区团购',
'hasShipAdditional' => '补运费发顺丰',
'addOrAdditionalSfExpress' => '加运费发顺丰+补运费发顺丰',
'shipAdditionalOrder' => '补运费订单',
OrderConst::orderTagTypeProfessionalAppraisal => '珠宝专业鉴定',
OrderConst::orderTagTypeNoProfessionalAppraisal => '无珠宝专业鉴定',
OrderConst::orderConsolidateTypeHk => '中国香港集运',
OrderConst::orderConsolidateTypeXj => '中国新疆中转',
OrderConst::orderConsolidateTypeHskst => '哈萨克斯坦集运',
OrderConst::orderConsolidateTypeXz => '中国西藏中转',
OrderConst::orderConsolidateTypeJapan => '日本集运',
OrderConst::orderConsolidateTypeTw => '中国台湾集运',
OrderConst::orderConsolidateTypeKorea => '韩国集运',
OrderConst::orderConsolidateTypeSingapore => '新加坡集运',
OrderConst::orderConsolidateTypeMalaysia => '马来西亚集运',
OrderConst::orderConsolidateTypeThailand => '泰国集运',
'shipHold' => '暂停发货',
];
}
public static function getFastSearchFdsOrderFilterOptions() {
return [
'' => '不限订单',
OrderPrintConst::opOrderFilterMergeStatusHasMerge => '合并订单',
OrderPrintConst::opOrderFilterMergeStatusNotMerge => '未合并订单',
];
}
public static function getOpPreOutstorageSortTypeMap() {
return array(
'preOutstorageTimeDesc' => '预发货时间降序',
'preOutstorageTimeAsc' => '预发货时间升序',
'paymentConfirmTimeDesc' => '成团时间降序',
'paymentConfirmTimeAsc' => '成团时间升序',
'lastShipTimeDesc' => '剩余时间降序',
'lastShipTimeAsc' => '剩余时间升序',
);
}
public static function convertDtToWeek($startDt, $endDt) {
$weekStartDay = date('N', strtotime($startDt));
$weekEndDay = date('N', strtotime($endDt));
$fixStartTime = strtotime($startDt) + (1 - $weekStartDay) * 24 * 3600;
$fixEndTime = strtotime($endDt) + (7 - $weekEndDay) * 24 * 3600;
$startDt = date('Y-m-d', $fixStartTime);
$endDt = date('Y-m-d', $fixEndTime);
return [$startDt, $endDt];
}
public static function formatExpressItem($expressNo, $cpCode, $expressType, $waybillType, $packageId, $packageCount, $isChildParent, $logisticsName = null) {
return array(
'expressNo' => $expressNo,
'cpCode' => $cpCode,
'expressType' => $expressType,
'waybillType' => $waybillType,
'packageId' => $packageId,
'packageCount' => $packageCount,
'isChildParent' => $isChildParent ? 1 : 0,
'logisticsName' => $logisticsName ?: '',
);
}
public static function isEnsconcedMobile($mobile) {
return strpos($mobile, '*') ? true : false;
}
}