|
|
<?php
|
|
|
|
|
|
class PurchaseTool {
|
|
|
|
|
|
public static function compareOrderAddressAndPurchaseAddress($consignee, $purchaseOrder) {
|
|
|
if ($purchaseOrder['purchaseOrderAddressSuccessSign']) {
|
|
|
return true;
|
|
|
}
|
|
|
$purchaseOrder = self::removeConsigneeSuffix($purchaseOrder, $consignee);
|
|
|
$purchaseOrder = self::removeVirtualNumberSuffix($purchaseOrder, $consignee);
|
|
|
|
|
|
$replaceOrderAddressReg = "/^{$consignee['province']}(省)?({$consignee['city']})?({$consignee['county']})?({$consignee['town']})?/";
|
|
|
$orderAddress = preg_replace($replaceOrderAddressReg, '', $consignee['address']);
|
|
|
$orderAddress = CommonTool::ensconceString($orderAddress, 'sensitiveAddress');
|
|
|
$orderAddress = str_replace(array(' ', '#', '*'), array('', '号', ''), $orderAddress);
|
|
|
$orderAddress = self::removeTbAddressSpecialChars($purchaseOrder, $orderAddress);
|
|
|
|
|
|
$purchaseOrderFullAddress = CommonTool::ensconceString($purchaseOrder['purchaseOrderFullAddress'], 'sensitiveAddress');
|
|
|
$purchaseOrderFullAddress = str_replace(array(' ', '#', '*'), array('', '号', ''), $purchaseOrderFullAddress);
|
|
|
|
|
|
$purchaseOrderFullname = trim($purchaseOrder['purchaseOrderFullname']);
|
|
|
if (self::isEmoji($purchaseOrderFullname)) {
|
|
|
$purchaseOrderFullname = self::filterEmoji($purchaseOrderFullname, '*');
|
|
|
}
|
|
|
$purchaseOrderFullname = CommonTool::ensconceString($purchaseOrderFullname, 'sensitiveName', $purchaseOrder['purchasePlatform']);
|
|
|
$purchaseOrderMobile = CommonTool::ensconceString($purchaseOrder['purchaseOrderMobile'], 'sensitiveMobile');
|
|
|
if (preg_match('#^(\d{1,2})\*+(\d{2})$#', $purchaseOrder['purchaseOrderMobile'], $matchPurchaseOrderMobileRes) && count($matchPurchaseOrderMobileRes) == 3) {
|
|
|
$needRepeatNum = 11 - (strlen($matchPurchaseOrderMobileRes[1]) + strlen($matchPurchaseOrderMobileRes[2]));
|
|
|
$matchPurchaseOrderMobile = sprintf('%s%s%s', $matchPurchaseOrderMobileRes[1], str_repeat('*', $needRepeatNum), $matchPurchaseOrderMobileRes[2]);
|
|
|
$purchaseOrderMobile = CommonTool::ensconceString($matchPurchaseOrderMobile, 'sensitiveMobile');
|
|
|
}
|
|
|
|
|
|
$orderFullname = $consignee['fullname'];
|
|
|
if (self::isEmoji($orderFullname)) {
|
|
|
$orderFullname = self::filterEmoji($orderFullname, '*');
|
|
|
}
|
|
|
$orderFullname = CommonTool::ensconceString($orderFullname, 'sensitiveName', $purchaseOrder['purchasePlatform']);
|
|
|
$orderMobile = CommonTool::ensconceString($consignee['mobile'], 'sensitiveMobile');
|
|
|
if ($purchaseOrder['purchaseFixedMobile']) {
|
|
|
$orderMobile = CommonTool::ensconceString($purchaseOrder['purchaseFixedMobile'], 'sensitiveMobile');
|
|
|
}
|
|
|
|
|
|
$isMatchFullname = strpos($orderFullname, $purchaseOrderFullname) === 0;
|
|
|
if (!$isMatchFullname && preg_match('/^[\x{4e00}-\x{9fa5}a-zA-Z]\*+$/u', $orderFullname) && preg_match('/^[\x{4e00}-\x{9fa5}a-zA-Z]\*[\x{4e00}-\x{9fa5}a-zA-Z]$/u', $purchaseOrderFullname)) {
|
|
|
$isMatchFullname = strpos(mb_substr($orderFullname, 0, 2), mb_substr($purchaseOrderFullname, 0, 2)) === 0;
|
|
|
}
|
|
|
$isMatchMobile = ($purchaseOrderMobile == $orderMobile);
|
|
|
$isMatchAddress = true;
|
|
|
$orderAddressLen = mb_strlen($orderAddress);
|
|
|
for ($i = 0; $i < $orderAddressLen; $i++) {
|
|
|
$addressStr = mb_substr($orderAddress, $i, 1);
|
|
|
$strPos = mb_strpos($purchaseOrderFullAddress, $addressStr);
|
|
|
if ($strPos !== false) {
|
|
|
$purchaseOrderFullAddress = mb_substr($purchaseOrderFullAddress, -(mb_strlen($purchaseOrderFullAddress) - $strPos - 1));
|
|
|
} else {
|
|
|
$isMatchAddress = false;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
$isMatchCounty = (strpos($purchaseOrder['purchaseOrderFullAddress'], mb_substr($consignee['county'], 0, 2)) !== false);
|
|
|
|
|
|
return ($isMatchFullname && $isMatchMobile && $isMatchAddress && $isMatchCounty) ? true : false;
|
|
|
}
|
|
|
|
|
|
public static function removeTbAddressSpecialChars($purchaseOrder, $orderAddress) {
|
|
|
if (in_array($purchaseOrder['purchase_platform'], [PurchaseOrderConst::purchasePlatformTaobao, PurchaseOrderConst::purchasePlatformTmall])) {
|
|
|
$orderAddress = str_replace(['‘', '’', '“', '”'], '', $orderAddress);
|
|
|
}
|
|
|
return $orderAddress;
|
|
|
}
|
|
|
|
|
|
public static function removeVirtualNumberSuffix($purchaseOrder, $consignee) {
|
|
|
$fullnameHasVirtualNoSuffix = self::checkHasVirtualNumberSuffix($purchaseOrder['purchaseOrderFullname']);
|
|
|
$addressHasVirtualNoSuffix = self::checkHasVirtualNumberSuffix($purchaseOrder['purchaseOrderFullAddress']);
|
|
|
if ($fullnameHasVirtualNoSuffix && !self::checkHasVirtualNumberSuffix($consignee['fullname'])) {
|
|
|
$purchaseOrder['purchaseOrderFullname'] = preg_replace('/\[\d{4}\]$/', '', $purchaseOrder['purchaseOrderFullname']);
|
|
|
}
|
|
|
|
|
|
if ($addressHasVirtualNoSuffix && !self::checkHasVirtualNumberSuffix($consignee['address'])) {
|
|
|
$purchaseOrder['purchaseOrderFullAddress'] = preg_replace('/\[\d{4}\]$/', '', $purchaseOrder['purchaseOrderFullAddress']);
|
|
|
}
|
|
|
|
|
|
if ($fullnameHasVirtualNoSuffix && $addressHasVirtualNoSuffix) {
|
|
|
$purchaseOrder['purchaseOrderMobile'] = $consignee['mobile'];
|
|
|
}
|
|
|
|
|
|
return $purchaseOrder;
|
|
|
}
|
|
|
|
|
|
public static function checkHasVirtualNumberSuffix($str) {
|
|
|
return (bool) preg_match('/\[\d{4}\]$/', $str);
|
|
|
}
|
|
|
|
|
|
public static function removeConsigneeSuffix($purchaseOrder, $consignee) {
|
|
|
$purchaseSetting = $purchaseOrder['purchaseSetting'];
|
|
|
if (!$purchaseSetting['isAddConsigneeSuffix']) {
|
|
|
return $purchaseOrder;
|
|
|
}
|
|
|
$addConsigneeNameSuffixFields = $purchaseSetting['addConsigneeNameSuffixFields'];
|
|
|
$addConsigneeAddressSuffixFields = $purchaseSetting['addConsigneeAddressSuffixFields'];
|
|
|
$purchaseOrder['purchaseOrderFullname'] = self::replaceConsigneeSuffix($addConsigneeNameSuffixFields, $consignee, $purchaseOrder['purchaseOrderFullname']);
|
|
|
$purchaseOrder['purchaseOrderFullAddress'] = self::replaceConsigneeSuffix($addConsigneeAddressSuffixFields, $consignee, $purchaseOrder['purchaseOrderFullAddress']);
|
|
|
return $purchaseOrder;
|
|
|
}
|
|
|
|
|
|
public static function replaceConsigneeSuffix($addConsigneeSuffixFields, $consignee, $purchaseOrderField) {
|
|
|
foreach ($addConsigneeSuffixFields as $field) {
|
|
|
switch ($field) {
|
|
|
case 'orderId':
|
|
|
$purchaseOrderField = mb_substr($purchaseOrderField, 0, -1);
|
|
|
break;
|
|
|
case 'receiverName':
|
|
|
$nameLength = mb_strlen($consignee['fullname']);
|
|
|
$subSuffix = mb_substr($purchaseOrderField, -$nameLength);
|
|
|
if (mb_strlen($purchaseOrderField) > $nameLength && $subSuffix == $consignee['fullname']) {
|
|
|
$purchaseOrderField = mb_substr($purchaseOrderField, 0, mb_strlen($purchaseOrderField) - $nameLength);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return $purchaseOrderField;
|
|
|
}
|
|
|
|
|
|
public static function isPddPlatform($platformName) {
|
|
|
return $platformName == PurchaseOrderConst::purchasePlatformPdd;
|
|
|
}
|
|
|
|
|
|
public static function isPddddkUrl($purchaseUrl) {
|
|
|
preg_match('/([\w][\w-]*)\.(?:com\.cn|com|cn|co|net|org|gov|cc|biz|info)(\/|$)/isU', $purchaseUrl, $match);
|
|
|
|
|
|
$purchasePlatform = $match[1];
|
|
|
if ($purchasePlatform != 'pinduoduo' && $purchasePlatform != 'toutiaonanren' && $purchasePlatform != 'yangkeduo') {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
return preg_match('/duo_coupon_landing|p\.pinduoduo\.com\/\w+/isU', $purchaseUrl) ? true : false;
|
|
|
}
|
|
|
|
|
|
public static function getUrlParams($purchaseUrl) {
|
|
|
$urlMap = parse_url($purchaseUrl);
|
|
|
parse_str($urlMap['query'] ?: '', $urlParamsMap);
|
|
|
|
|
|
return $urlParamsMap;
|
|
|
}
|
|
|
|
|
|
public static function getGoodsIdFromUrl($purchaseUrl) {
|
|
|
if (self::isPddddkUrl($purchaseUrl)) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
$urlParamsMap = self::getUrlParams($purchaseUrl);
|
|
|
return $urlParamsMap['goods_id'] ?: 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static function isEmoji($str) {
|
|
|
$rs = preg_match_all('/./u', $str,$match);
|
|
|
if(!$rs){
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
$isMatch = false;
|
|
|
foreach($match[0] as $m){
|
|
|
if(strlen($m) >= 4){
|
|
|
$isMatch = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $isMatch;
|
|
|
}
|
|
|
|
|
|
public static function filterEmoji($str, $replaceStr = '') {
|
|
|
$newStr = preg_replace_callback(
|
|
|
'/./u',
|
|
|
function (array $match) use ($replaceStr) {
|
|
|
return strlen($match[0]) >= 4 ? $replaceStr : $match[0];
|
|
|
},
|
|
|
$str
|
|
|
);
|
|
|
|
|
|
return $newStr;
|
|
|
}
|
|
|
|
|
|
public static function getItemUrlPatterns() {
|
|
|
return array (
|
|
|
PurchaseOrderConst::purchasePlatformTaote => '/(?:item|m)\.(?:taobao|tb)\.(?:com|cn)\/app\/ltao\-fe\/ltao\-lite.*(&id|\?id)=(\d+)/i',
|
|
|
PurchaseOrderConst::purchasePlatformTaobao => '/(?:item|m)\.(?:taobao|tb)\.(?:com|cn).*(&id|\?id)=(\d+)/i',
|
|
|
PurchaseOrderConst::purchasePlatformPdd => '/(yangkeduo|ishangtong|pinduoduo)\.com\/(?:goods(?:\d)*|duo_coupon_landing).*[\?|&](?:goods_id=|goodsId=)(\d+)/i',
|
|
|
PurchaseOrderConst::purchasePlatformTmall => '/detail\.(?:tmall|liangxinyao|yao\.95095|m\.tmall)\.(?:com|hk).*(&id|\?id)=(\d+)/i',
|
|
|
PurchaseOrderConst::purchasePlatform1688 => '/(.*\.1688\.com\/(?:offer|pic)\/|caigou\.1688\.com\/detail\/)(\d+).(htm|html)/isU',
|
|
|
PurchaseOrderConst::purchasePlatformJd => '/(?:item|wqitem|m|xinfang)\.(?:jkcsjd|yiyaojd|jd|paipai|m\.jd|jingxi)\.(com|hk)(\/)(product\/|ware\/view\.action|item\/view)?(\?wareId=)?(?:.*sku=|.*skuId=)?(\d+)(?:\.html|&)?/i',
|
|
|
PurchaseOrderConst::purchasePlatformWsy => '/(?:https?:\/\/)([^.]*)\.?wsy\.com\/item(?:\.htm|\.php|\.html|)\?id=(\d+)/i',
|
|
|
PurchaseOrderConst::purchasePlatformSooxie => '/(?:https:\/\/|http:\/\/)(.*)\.sooxie\.(?:com|net)\/(?:detail\/)?(\d+)/i',
|
|
|
PurchaseOrderConst::purchasePlatformVvic => '/\.vvic\.com\/item(.*uuid=|\/|.*id=)(\w+)/i',
|
|
|
PurchaseOrderConst::purchasePlatform17qcc => '/(www)\.17qcc\.com\/item\/(\d+)\.html/i',
|
|
|
PurchaseOrderConst::purchasePlatform17zwd => '/(?:https?:\/\/)(.*)\.17zwd\.com\/item(?:\d*[\.htm]*\?gid=|\/)(\d+)/i',
|
|
|
PurchaseOrderConst::purchasePlatformBao66 => '/(bao66)\.cn\/(?:p|product)\/([^\.]*?)\./i',
|
|
|
PurchaseOrderConst::purchasePlatformK3 => '/(k3)\.cn\/(p|product)\/([^\.]*?)\./i',
|
|
|
PurchaseOrderConst::purchasePlatformXingfujie => '/(xingfujie)\.cn\/(?:p|product)\/([^\.]*?)\./i',
|
|
|
PurchaseOrderConst::purchasePlatform2tong => '/(2tong)\.cn\/(?:p|product)\/([^\.]*?)\./i',
|
|
|
PurchaseOrderConst::purchasePlatformHznzcn => '/(.*).hznzcn.com\/product-(\d+)\.html/i',
|
|
|
PurchaseOrderConst::purchasePlatformZlycw => '/(.*).zlycw.com\/index\/hyindex\/goodsdetail\.html\?.*goodsid=(\d+)/i',
|
|
|
);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过商品链接获取商品信息
|
|
|
* 代码从Fc精简而来
|
|
|
* @param $url
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function getSourceInfoByItemUrl($url) {
|
|
|
$matchFailRet = [
|
|
|
'itemId' => '',
|
|
|
'source' => '',
|
|
|
'site' => ''
|
|
|
];
|
|
|
|
|
|
if (empty($url)) {
|
|
|
return $matchFailRet;
|
|
|
}
|
|
|
|
|
|
$patterns = self::getItemUrlPatterns();
|
|
|
|
|
|
foreach ($patterns as $realSource => $pattern) {
|
|
|
$matchs = array ();
|
|
|
preg_match($pattern, $url, $matchs);
|
|
|
|
|
|
if (empty($matchs[2]) && ($realSource === PurchaseOrderConst::purchasePlatformJd)) {
|
|
|
$url = self::fixJdUrl($url);
|
|
|
preg_match($pattern, $url, $matchs);
|
|
|
}
|
|
|
if (empty($matchs[2]) && ($realSource == PurchaseOrderConst::purchasePlatform1688)) {
|
|
|
$pattern = '/(.*\.1688\.com\/page\/index\.(?:htm|html)).*offerId=(\d+)(?:&.*)?$/isU';
|
|
|
preg_match($pattern, $url, $matchs);
|
|
|
}
|
|
|
if (!empty($matchs[2])) {
|
|
|
switch ($realSource) {
|
|
|
case PurchaseOrderConst::purchasePlatform17zwd :
|
|
|
case PurchaseOrderConst::purchasePlatformWsy :
|
|
|
case PurchaseOrderConst::purchasePlatformSooxie :
|
|
|
$site = !$matchs[1] ? 'www' : str_replace('.', '', $matchs[1]);
|
|
|
$sourceItemId = $matchs[2];
|
|
|
break;
|
|
|
case PurchaseOrderConst::purchasePlatformVvic :
|
|
|
$site = (strpos($matchs[1], 'uuid') !== false) ? 'old' : 'new';
|
|
|
$sourceItemId = $matchs[2];
|
|
|
break;
|
|
|
case PurchaseOrderConst::purchasePlatformK3 :
|
|
|
$site = '';
|
|
|
if (stripos($url, 'page_id') !== false) {
|
|
|
preg_match('/page_id=(\d+)/', $url, $pageMatchs);
|
|
|
$site = $pageMatchs ? $pageMatchs[1] : '';
|
|
|
}
|
|
|
$sourceItemId = strval($matchs[3]);
|
|
|
break;
|
|
|
case PurchaseOrderConst::purchasePlatformJd :
|
|
|
$site = '';
|
|
|
$sourceItemId = $matchs[5];
|
|
|
break;
|
|
|
default :
|
|
|
$site = '';
|
|
|
$sourceItemId = $matchs[2];
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return array (
|
|
|
'itemId' => $sourceItemId,
|
|
|
'source' => $realSource,
|
|
|
'site' => $site
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $matchFailRet;
|
|
|
}
|
|
|
|
|
|
public static function formatPurchaseTransitAddress($purchaseTransitAddress, $isEnsconceString = true) {
|
|
|
$mobile = $isEnsconceString ? CommonTool::ensconceString($purchaseTransitAddress['mobile'], 'mobile') : $purchaseTransitAddress['mobile'];
|
|
|
return [
|
|
|
'fullname' => $isEnsconceString ? CommonTool::ensconceString($purchaseTransitAddress['user_name']) : $purchaseTransitAddress['user_name'],
|
|
|
'telephone' => $mobile,
|
|
|
'mobile' => $mobile,
|
|
|
'provinceAreaId' => preg_replace('/0{4}$/', '', $purchaseTransitAddress['province_area_id']),
|
|
|
'province' => $purchaseTransitAddress['province'],
|
|
|
'cityAreaId' => $purchaseTransitAddress['city_area_id'],
|
|
|
'city' => $purchaseTransitAddress['city'],
|
|
|
'countyAreaId' => $purchaseTransitAddress['county_area_id'],
|
|
|
'county' => $purchaseTransitAddress['county'],
|
|
|
'townAreaId' => $purchaseTransitAddress['town_area_id'],
|
|
|
'town' => $purchaseTransitAddress['town'],
|
|
|
'address' => $purchaseTransitAddress['address'],
|
|
|
'fullAddress' => $purchaseTransitAddress['full_address'],
|
|
|
'hasHide' => true,
|
|
|
];
|
|
|
}
|
|
|
|
|
|
public static function getPurchaseOrderStatusLabel($purchaseOrderStatus, $logisticsIsAccept = null, $purchasePlatform = '') {
|
|
|
$purchaseOrderStatusAndClassNameMap = [
|
|
|
PurchaseOrderConst::purchaseOrderStatusWaitPay => 'label-warning',
|
|
|
PurchaseOrderConst::purchaseOrderStatusWaitSend => 'label-default',
|
|
|
PurchaseOrderConst::purchaseOrderStatusHasSend => 'label-success',
|
|
|
PurchaseOrderConst::purchaseOrderStatusFinished => 'label-primary',
|
|
|
PurchaseOrderConst::purchaseOrderStatusCancel => 'label-danger',
|
|
|
PurchaseOrderConst::purchaseOrderStatusRefund => 'label-danger',
|
|
|
];
|
|
|
$className = $purchaseOrderStatusAndClassNameMap[$purchaseOrderStatus] ?: 'label-default';
|
|
|
$logisticsAcceptText = (($purchaseOrderStatus == PurchaseOrderConst::purchaseOrderStatusHasSend) && !$logisticsIsAccept && !is_null($logisticsIsAccept)) ? '<strong>(未揽收)</strong>' : '';
|
|
|
$platformName = $purchasePlatform ? PurchaseOrderConst::getPurchasePlatformName($purchasePlatform) : '';
|
|
|
return '<span class="label ' . $className . '">' . $platformName . PurchaseOrderConst::getOrderStatusMaps()[$purchaseOrderStatus] . $logisticsAcceptText . '</span>';
|
|
|
}
|
|
|
|
|
|
public static function isTaobaoShortUrl($url) {
|
|
|
$isTb = stripos($url, 'm.tb.cn') !== false ? true : false;
|
|
|
$isLtao = stripos($url, 'u.ltao.com') !== false ? true : false;
|
|
|
$isQwbev = stripos($url, 'qwbev.net') !== false ? true : false;
|
|
|
return $isTb || $isLtao || $isQwbev;
|
|
|
}
|
|
|
|
|
|
public static function convertTaotePurchaseUrl($url) {
|
|
|
if (empty($url)) {
|
|
|
return null;
|
|
|
}
|
|
|
if (self::isTaobaoShortUrl($url)) {
|
|
|
$content = file_get_contents($url);
|
|
|
if ($_SESSION && $_SESSION[SessionConst::shopId] && $_SESSION[SessionConst::shopId] == 16700961) {
|
|
|
$log = Zc::getLog('order/ware/purchase_url_convert');
|
|
|
$log->info('content: ' . $content);
|
|
|
}
|
|
|
if (!empty($content)) {
|
|
|
preg_match('/var\s*url\s*=\s*\'(.*)\';/', $content, $res);
|
|
|
if (!empty($res[1])) {
|
|
|
$url = $res[1];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (stripos($url, 'market.m.taobao.com/app/nozomi/app-h5-detail/main/index') === false) {
|
|
|
return null;
|
|
|
}
|
|
|
$parseUrlData = parse_url($url);
|
|
|
if (empty($parseUrlData['query'])) {
|
|
|
return null;
|
|
|
}
|
|
|
$params = self::parseUrlQueryParams($parseUrlData['query']);
|
|
|
if (empty($params['id'])) {
|
|
|
return null;
|
|
|
}
|
|
|
return sprintf('https://market.m.taobao.com/app/ltao-fe/ltao-lite/productdetail.html?ft=t&id=%s', $params['id']);
|
|
|
}
|
|
|
|
|
|
public static function parseUrlQueryParams($queryStr) {
|
|
|
$query_pairs = explode('&', $queryStr);
|
|
|
$params = [];
|
|
|
foreach ($query_pairs as $query_pair) {
|
|
|
$item = explode('=', $query_pair);
|
|
|
$params[$item[0]] = $item[1] ?: '';
|
|
|
}
|
|
|
return $params;
|
|
|
}
|
|
|
|
|
|
public static function rebuildPurchaseWareUrlsSource(&$purchaseWareUrls) {
|
|
|
if (!$purchaseWareUrls){
|
|
|
return false;
|
|
|
}
|
|
|
foreach ($purchaseWareUrls as &$purchaseWareUrl) {
|
|
|
if (in_array($purchaseWareUrl['purchase_platform'], [PurchaseOrderConst::purchasePlatformTaobao, PurchaseOrderConst::purchasePlatformTmall])) {
|
|
|
$purchaseWareUrl['purchase_url_source'] = PurchaseOrderConst::purchaseUrlSourceManual;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static function rebuildPurchaseWareUrlSource(&$purchaseWareUrl) {
|
|
|
if (!$purchaseWareUrl) {
|
|
|
return false;
|
|
|
}
|
|
|
if (in_array($purchaseWareUrl['purchase_platform'], [PurchaseOrderConst::purchasePlatformTaobao, PurchaseOrderConst::purchasePlatformTmall])) {
|
|
|
$purchaseWareUrl['purchase_url_source'] = PurchaseOrderConst::purchaseUrlSourceManual;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static function getMatch1688SkuInfo($skuSubNameFromWareUrl, $platformSkuSubName, $sourceItemInfo) {
|
|
|
if (CommonTool::anyEmpty($platformSkuSubName, $sourceItemInfo)) {
|
|
|
return [];
|
|
|
}
|
|
|
$skuSubNamePattern = '/\d+(小时内发货|天内发货)$/ui';
|
|
|
if (preg_match($skuSubNamePattern, $skuSubNameFromWareUrl)) {
|
|
|
$skuSubNameFromWareUrl = preg_replace($skuSubNamePattern, '', $skuSubNameFromWareUrl);
|
|
|
}
|
|
|
if (preg_match($skuSubNamePattern, $platformSkuSubName)) {
|
|
|
$platformSkuSubName = preg_replace($skuSubNamePattern, '', $platformSkuSubName);
|
|
|
}
|
|
|
|
|
|
$matchSkuInfo = [];
|
|
|
foreach ($sourceItemInfo['skus'] as $skuInfo) {
|
|
|
if (!empty($skuSubNameFromWareUrl) && DsOrderTool::isSkuSubNameEqual($skuSubNameFromWareUrl, $skuInfo['skuSubName'])) {
|
|
|
$matchSkuInfo = $skuInfo;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if (empty($skuSubNameFromWareUrl) && !empty($platformSkuSubName) && DsOrderTool::isSkuSubNameEqual($platformSkuSubName, $skuInfo['skuSubName'])) {
|
|
|
$matchSkuInfo = $skuInfo;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $matchSkuInfo;
|
|
|
}
|
|
|
|
|
|
public static function checkNeedDecryptConsigneeInfo($consigneeInfo) {
|
|
|
if ($consigneeInfo['purchaseTransitAddressId']) {
|
|
|
return false;
|
|
|
}
|
|
|
if ($consigneeInfo['isManualInput']) {
|
|
|
return false;
|
|
|
}
|
|
|
$hasDecryptFields = $consigneeInfo['hasDecryptFields'] ?: [];
|
|
|
return (count($hasDecryptFields) != 3);
|
|
|
}
|
|
|
|
|
|
public static function checkConsigneeInfo($consigneeInfo) {
|
|
|
CheckClient::checkEmpty($consigneeInfo['fullname'], 'fullname');
|
|
|
CheckClient::checkEmpty($consigneeInfo['mobile'], 'mobile');
|
|
|
CheckClient::checkEmpty($consigneeInfo['province'], 'province');
|
|
|
CheckClient::checkEmpty($consigneeInfo['city'], 'city');
|
|
|
CheckClient::checkEmpty($consigneeInfo['county'], 'county');
|
|
|
CheckClient::checkEmpty($consigneeInfo['address'], 'address');
|
|
|
CheckClient::checkEmpty($consigneeInfo['fullAddress'], 'fullAddress');
|
|
|
}
|
|
|
|
|
|
public static function getDefaultDsPurchaseOrderSetting() {
|
|
|
return [
|
|
|
'isAutoPurchase' => 0,
|
|
|
'isAutoPay' => 0,
|
|
|
'delayPurchaseMinute' => 0,
|
|
|
'forbiddenPurchaseProfit' => 0,
|
|
|
'isUseForbiddenPurchaseProfit' => 0,
|
|
|
'isUseForbiddenKeywords' => 0,
|
|
|
'forbiddenKeywords' => '',
|
|
|
'isUseAllProduct' => 1,
|
|
|
'isUsePartProduct' => 0,
|
|
|
'isForbidIsolationPurchase' => 0,
|
|
|
'deliveryTimeType' => PurchaseOrderConst::deliveryTimeTypeRightNow,
|
|
|
'isPurchaseLogisticsUpdateToPlatform' => 0,
|
|
|
];
|
|
|
}
|
|
|
|
|
|
public static function isOpenDsEncryptOrderSetting() {
|
|
|
return AppConst::isMsDdOd();
|
|
|
}
|
|
|
|
|
|
public static function rebuildSooxieItemInfo($orderItem, $sourceItemInfo) {
|
|
|
return [
|
|
|
'sourceItemId' => $sourceItemInfo['item_id'],
|
|
|
'sourceItemNo' => $sourceItemInfo['item_no'],
|
|
|
'sourceSellerName' => $sourceItemInfo['item_seller_name'],
|
|
|
'skuSubName' => $orderItem['skuSubName'],
|
|
|
'title' => $orderItem['skuName'],
|
|
|
'stock' => $orderItem['itemTotal'],
|
|
|
];
|
|
|
}
|
|
|
|
|
|
public static function getMatchSooxieSkuInfo($orderItem, $sourceItemInfo) {
|
|
|
if (CommonTool::anyEmpty($orderItem, $sourceItemInfo)) {
|
|
|
return [];
|
|
|
}
|
|
|
// 目前搜鞋网直接用的是抖店的规格,不涉及到规格匹配
|
|
|
$matchSourceSkuInfo = [
|
|
|
'sourceItemId' => $sourceItemInfo['item_id'],
|
|
|
'sourceSkuId' => $orderItem['skuId'],
|
|
|
'sourceItemNo' => $sourceItemInfo['item_no'],
|
|
|
'sourceSellerName' => $sourceItemInfo['item_seller_name'],
|
|
|
'sourceItemPrice' => $sourceItemInfo['item_price'],
|
|
|
'skuSubName' => $orderItem['skuSubName'],
|
|
|
'title' => $orderItem['skuName'],
|
|
|
'stock' => $orderItem['itemTotal'],
|
|
|
];
|
|
|
return $matchSourceSkuInfo;
|
|
|
}
|
|
|
|
|
|
public static function getSooxieSenderIdAndShopIdsMap() {
|
|
|
return [
|
|
|
'D221511BFCABE49C' => [
|
|
|
'91545568',
|
|
|
],
|
|
|
'1EF11F88C4A1F88B' => [
|
|
|
'12022522',
|
|
|
],
|
|
|
'2655F1428715979D' => [
|
|
|
'101010501',
|
|
|
],
|
|
|
'E568D22C51497454' => [
|
|
|
'101860695',
|
|
|
],
|
|
|
'547231AB5BE8771A' => [
|
|
|
'41140698',
|
|
|
],
|
|
|
'EA7FD0F356C17B3E' => [
|
|
|
'87269203',
|
|
|
],
|
|
|
];
|
|
|
}
|
|
|
|
|
|
public static function getAppendShopRemarkFieldsMap() {
|
|
|
$map = [
|
|
|
PurchaseOrderConst::purchasePlatform2Field => [
|
|
|
'name' => '采购平台',
|
|
|
],
|
|
|
PurchaseOrderConst::purchaseOrderSnField => [
|
|
|
'name' => '采购单号',
|
|
|
],
|
|
|
PurchaseOrderConst::purchaseOrderBuyer => [
|
|
|
'name' => '采购账号',
|
|
|
],
|
|
|
PurchaseOrderConst::purchasePaymentField => [
|
|
|
'name' => '采购成本',
|
|
|
],
|
|
|
PurchaseOrderConst::purchaseOrderSellerField => [
|
|
|
'name' => '上家店铺名称',
|
|
|
],
|
|
|
PurchaseOrderConst::purchaseOrderNumField => [
|
|
|
'name' => '采购数量',
|
|
|
],
|
|
|
PurchaseOrderConst::logisticsInfoField => [
|
|
|
'name' => '快递及运单号',
|
|
|
],
|
|
|
PurchaseOrderConst::shopNameField => [
|
|
|
'name' => '抖店店铺名称',
|
|
|
],
|
|
|
PurchaseOrderConst::totalProfitField => [
|
|
|
'name' => '总利润',
|
|
|
],
|
|
|
PurchaseOrderConst::profitRatioField => [
|
|
|
'name' => '利润率',
|
|
|
],
|
|
|
];
|
|
|
return $map;
|
|
|
}
|
|
|
|
|
|
public static function getAppendShopNoteFieldsMap() {
|
|
|
$map = [
|
|
|
PurchaseOrderConst::purchasePlatform2Field => [
|
|
|
'name' => '采购平台',
|
|
|
],
|
|
|
PurchaseOrderConst::purchaseOrderSnField => [
|
|
|
'name' => '采购单号',
|
|
|
],
|
|
|
PurchaseOrderConst::purchaseOrderBuyer => [
|
|
|
'name' => '采购账号',
|
|
|
],
|
|
|
PurchaseOrderConst::purchasePaymentField => [
|
|
|
'name' => '采购成本',
|
|
|
],
|
|
|
PurchaseOrderConst::logisticsInfoField => [
|
|
|
'name' => '快递及运单号',
|
|
|
],
|
|
|
PurchaseOrderConst::purchaseOrderSellerField => [
|
|
|
'name' => '上家店铺名称',
|
|
|
],
|
|
|
PurchaseOrderConst::purchaseOrderNumField => [
|
|
|
'name' => '采购数量',
|
|
|
],
|
|
|
PurchaseOrderConst::shopNameField => [
|
|
|
'name' => '抖店店铺名称',
|
|
|
],
|
|
|
PurchaseOrderConst::totalProfitField => [
|
|
|
'name' => '总利润',
|
|
|
],
|
|
|
PurchaseOrderConst::profitRatioField => [
|
|
|
'name' => '利润率',
|
|
|
],
|
|
|
];
|
|
|
return $map;
|
|
|
}
|
|
|
|
|
|
public static function getAutoFillRemarkFieldsMap() {
|
|
|
$map = [
|
|
|
PurchaseOrderConst::autoFillRemarkTypeSku => [
|
|
|
'name' => '抖店商品规格',
|
|
|
],
|
|
|
PurchaseOrderConst::autoFillRemarkTypeOnlyVenderRemark => [
|
|
|
'name' => '抖店商家备注',
|
|
|
],
|
|
|
PurchaseOrderConst::autoFillRemarkTypeOnlyOrderRemark => [
|
|
|
'name' => '抖店买家留言',
|
|
|
],
|
|
|
PurchaseOrderConst::autoFillRemarkTypePlatformName => [
|
|
|
'name' => '平台名称',
|
|
|
],
|
|
|
PurchaseOrderConst::autoFillRemarkTypePlatformShopName => [
|
|
|
'name' => '抖店店铺名称',
|
|
|
],
|
|
|
PurchaseOrderConst::autoFillRemarkTypePlatformOrderId => [
|
|
|
'name' => '抖店订单号',
|
|
|
],
|
|
|
];
|
|
|
return $map;
|
|
|
}
|
|
|
|
|
|
public static function getAutoFillOrderMemoFieldsMap() {
|
|
|
$map = [
|
|
|
PurchaseOrderConst::autoFillOrderMemoTypeShopName => [
|
|
|
'name' => '抖店店铺名称',
|
|
|
],
|
|
|
PurchaseOrderConst::autoFillOrderMemoTypeOrderId => [
|
|
|
'name' => '抖店订单号',
|
|
|
],
|
|
|
PurchaseOrderConst::autoFillOrderMemoTypePlatformName => [
|
|
|
'name' => '抖店平台',
|
|
|
],
|
|
|
PurchaseOrderConst::autoFillOrderMemoTypeSellerRemark => [
|
|
|
'name' => '抖店商家备注',
|
|
|
],
|
|
|
PurchaseOrderConst::autoFillOrderMemoTypeOrderRemark => [
|
|
|
'name' => '抖店买家留言',
|
|
|
],
|
|
|
];
|
|
|
return $map;
|
|
|
}
|
|
|
|
|
|
public static function getDefaultAppendVenderRemarkTpl() {
|
|
|
return implode('#', [
|
|
|
sprintf('<span contenteditable="false" data-field="%s">#%s#</span>', PurchaseOrderConst::purchasePlatform2Field, '采购平台'),
|
|
|
sprintf('<span contenteditable="false" data-field="%s">#%s#</span>', PurchaseOrderConst::purchaseOrderSnField, '采购单号'),
|
|
|
sprintf('<span contenteditable="false" data-field="%s">#%s#</span>', PurchaseOrderConst::logisticsInfoField, '快递及运单号'),
|
|
|
sprintf('<span contenteditable="false" data-field="%s">#%s#</span>', PurchaseOrderConst::purchaseOrderBuyer, '采购账号'),
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
public static function getRemarkTplRegPattern() {
|
|
|
$pattern = '@([^</span>]*)<span.*?data-field="([^"]+)"[^>]*?>#(?:[^#]+)#</span>([^<span>]*)@is';
|
|
|
return $pattern;
|
|
|
}
|
|
|
|
|
|
public static function isUpgradeRemarkSetting($purchaseSetting, $isDsPurchase = false) {
|
|
|
if ($isDsPurchase) {
|
|
|
return !empty($purchaseSetting['hasGuideSetAutoFillRemark']);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static function convertAppendShopRemarkFields($purchaseSettingRow) {
|
|
|
$appendShopRemarkFieldsMap = PurchaseTool::getAppendShopRemarkFieldsMap();
|
|
|
$shopRemarkFields = $purchaseSettingRow['append_shop_remark_fields'] ? unserialize($purchaseSettingRow['append_shop_remark_fields']) : null;
|
|
|
$customValue = $purchaseSettingRow['append_shop_remark_custom'];
|
|
|
$convertTpl = '';
|
|
|
if ($shopRemarkFields) {
|
|
|
$tpls = [];
|
|
|
foreach ($shopRemarkFields as $field) {
|
|
|
$fieldInfo = $appendShopRemarkFieldsMap[$field];
|
|
|
if ($fieldInfo) {
|
|
|
$tpls[] = sprintf('<span contenteditable="false" data-field="%s">#%s#</span>', $field, $fieldInfo['name']);
|
|
|
}
|
|
|
}
|
|
|
$convertTpl = implode('#', $tpls) . ($customValue && in_array(PurchaseOrderConst::customField, $shopRemarkFields) ? '#' . $customValue : '');
|
|
|
}
|
|
|
return $convertTpl;
|
|
|
}
|
|
|
|
|
|
public static function convertAppendShopNoteFields($purchaseSettingRow) {
|
|
|
$appendShopRemarkFieldsMap = PurchaseTool::getAppendShopNoteFieldsMap();
|
|
|
$shopNoteFields = $purchaseSettingRow['append_shop_note_fields'] ? unserialize($purchaseSettingRow['append_shop_note_fields']) : null;
|
|
|
$customValue = $purchaseSettingRow['append_shop_note_custom'];
|
|
|
$convertTpl = '';
|
|
|
if ($shopNoteFields) {
|
|
|
$tpls = [];
|
|
|
foreach ($shopNoteFields as $field) {
|
|
|
$fieldInfo = $appendShopRemarkFieldsMap[$field];
|
|
|
if ($fieldInfo) {
|
|
|
$tpls[] = sprintf('<span contenteditable="false" data-field="%s">#%s#</span>', $field, $fieldInfo['name']);
|
|
|
}
|
|
|
}
|
|
|
$convertTpl = implode('#', $tpls) . ($customValue && in_array(PurchaseOrderConst::customField, $shopNoteFields) ? '#' . $customValue : '');
|
|
|
}
|
|
|
return $convertTpl;
|
|
|
}
|
|
|
|
|
|
public static function convertAutoFillRemarkTypes($purchaseSettingRow) {
|
|
|
$autoFillRemarkFieldsMap = PurchaseTool::getAutoFillRemarkFieldsMap();
|
|
|
$autoFillRemarkTypes = $purchaseSettingRow['auto_fill_remark_types'] ? unserialize($purchaseSettingRow['auto_fill_remark_types']) : null;
|
|
|
$customValue = $purchaseSettingRow['custom_remark'];
|
|
|
$convertTpl = '';
|
|
|
if ($autoFillRemarkTypes) {
|
|
|
$tpls = [];
|
|
|
foreach ($autoFillRemarkTypes as $field) {
|
|
|
$fieldInfo = $autoFillRemarkFieldsMap[$field];
|
|
|
if ($fieldInfo) {
|
|
|
$tpls[] = sprintf('<span contenteditable="false" data-field="%s">#%s#</span>', $field, $fieldInfo['name']);
|
|
|
}
|
|
|
}
|
|
|
$convertTpl = implode(',', $tpls);
|
|
|
if (in_array(PurchaseOrderConst::autoFillRemarkTypeCustomRemark, $autoFillRemarkTypes)) {
|
|
|
$convertTpl .= $customValue;
|
|
|
}
|
|
|
}
|
|
|
return $convertTpl;
|
|
|
}
|
|
|
|
|
|
public static function convertAutoFillMomoFields($purchaseSettingRow) {
|
|
|
$autoFillOrderMemoFieldsMap = PurchaseTool::getAutoFillOrderMemoFieldsMap();
|
|
|
$autoFillMomoFields = $purchaseSettingRow['auto_fill_order_memo'] ? unserialize($purchaseSettingRow['auto_fill_order_memo']) : null;
|
|
|
$convertTpl = '';
|
|
|
if ($autoFillMomoFields) {
|
|
|
$tpls = [];
|
|
|
foreach ($autoFillMomoFields as $field) {
|
|
|
$fieldInfo = $autoFillOrderMemoFieldsMap[$field];
|
|
|
if ($field == 'shop_name_and_order_id') {
|
|
|
$tpls[] = sprintf('<span contenteditable="false" data-field="%s">#%s#</span>', PurchaseOrderConst::autoFillOrderMemoTypeShopName, '抖店店铺名称');
|
|
|
$tpls[] = sprintf('<span contenteditable="false" data-field="%s">#%s#</span>', PurchaseOrderConst::autoFillOrderMemoTypeOrderId, '抖店订单号');
|
|
|
} else {
|
|
|
if ($fieldInfo) {
|
|
|
$tpls[] = sprintf('<span contenteditable="false" data-field="%s">#%s#</span>', $field, $fieldInfo['name']);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
$convertTpl = implode('', $tpls);
|
|
|
}
|
|
|
return $convertTpl;
|
|
|
}
|
|
|
|
|
|
public static function removeRemarkMobileTplHashTag($tpl) {
|
|
|
$pattern = '@<span contenteditable="false" data-field="receiver_mobile">#(?:[^#]+)#</span>@is';
|
|
|
return preg_replace($pattern, '', $tpl);
|
|
|
}
|
|
|
|
|
|
public static function getDsPurchaseSettingFieldNames() {
|
|
|
return [
|
|
|
'deliveryTimeType',
|
|
|
'isPurchaseLogisticsUpdateToPlatform',
|
|
|
'isDsGivenProductAutoRelate',
|
|
|
];
|
|
|
}
|
|
|
|
|
|
public static function ensconcePurchaseOrderInfo($purchaseOrderInfo)
|
|
|
{
|
|
|
if (empty($purchaseOrderInfo)) {
|
|
|
return $purchaseOrderInfo;
|
|
|
}
|
|
|
|
|
|
$virtualNumberPattern = '/\[\d+\]/';
|
|
|
if (!empty($purchaseOrderInfo['purchaseOrderFullname'])) {
|
|
|
$fullname = CommonTool::filterEmoji($purchaseOrderInfo['purchaseOrderFullname'], '*');
|
|
|
$fullnameVirtualNumber = '';
|
|
|
if (preg_match($virtualNumberPattern, $fullname, $fullnameVirtualNumberMatches)) {
|
|
|
$fullnameVirtualNumber = $fullnameVirtualNumberMatches[0];
|
|
|
$fullname = preg_replace($virtualNumberPattern, '', $fullname);
|
|
|
}
|
|
|
|
|
|
$fullname = CommonTool::ensconceString($fullname, 'sensitiveName');
|
|
|
$purchaseOrderInfo['purchaseOrderFullname'] = $fullname . $fullnameVirtualNumber;
|
|
|
}
|
|
|
|
|
|
if (!empty($purchaseOrderInfo['purchaseOrderMobile'])) {
|
|
|
$purchaseOrderInfo['purchaseOrderMobile'] = CommonTool::ensconceString($purchaseOrderInfo['purchaseOrderMobile'], 'mobile');
|
|
|
}
|
|
|
|
|
|
if (!empty($purchaseOrderInfo['purchaseOrderFullAddress'])) {
|
|
|
$fullAddress = $purchaseOrderInfo['purchaseOrderFullAddress'];
|
|
|
$fullAddressVirtualNumber = '';
|
|
|
if (preg_match($virtualNumberPattern, $fullAddress, $fullAddressVirtualNumberMatches)) {
|
|
|
$fullAddressVirtualNumber = $fullAddressVirtualNumberMatches[0];
|
|
|
$fullAddress = preg_replace($virtualNumberPattern, '', $fullAddress);
|
|
|
}
|
|
|
|
|
|
$fullAddress = CommonTool::ensconceString($fullAddress, 'sensitiveFullAddress');
|
|
|
$purchaseOrderInfo['purchaseOrderFullAddress'] = $fullAddress . $fullAddressVirtualNumber;
|
|
|
}
|
|
|
|
|
|
return $purchaseOrderInfo;
|
|
|
}
|
|
|
} |