|
|
<?php
|
|
|
|
|
|
class DsOrderTool {
|
|
|
|
|
|
public static function build1688ProductUrl($sourceItemId) {
|
|
|
return sprintf('https://detail.1688.com/offer/%s.html', $sourceItemId);
|
|
|
}
|
|
|
|
|
|
public static function getMatchSourceSkuInfo($platformOrderItem, $platformSkuIdAndSourceSkuRelationMap, $productInfo) {
|
|
|
if (CommonTool::anyEmpty($platformOrderItem, $productInfo)) {
|
|
|
return [];
|
|
|
}
|
|
|
$platformSkuSubName = $platformOrderItem['skuSubName'];
|
|
|
|
|
|
$matchSkuInfo = $manualRelateSourceSkuInfo = [];
|
|
|
$manualRelateSourceSkuRelation = $platformSkuIdAndSourceSkuRelationMap[$platformOrderItem['skuId']] ? : null;
|
|
|
$sourceItemId = $productInfo['sourceItemId'];
|
|
|
$sourceSellerId = $productInfo['sellerId'] ?: null;
|
|
|
|
|
|
foreach ($productInfo['skus'] as $skuInfo) {
|
|
|
$manualRelateSourceSkuId = $manualRelateSourceSkuRelation['sourceSkuId'];
|
|
|
if ($manualRelateSourceSkuId && $skuInfo['sourceSkuId'] == $manualRelateSourceSkuId) {
|
|
|
$manualRelateSourceSkuInfo = $skuInfo;
|
|
|
break;
|
|
|
}
|
|
|
if (($skuInfo['sourceSkuId'] == $sourceItemId) && !$manualRelateSourceSkuId) {
|
|
|
$matchSkuInfo = $skuInfo;
|
|
|
break;
|
|
|
}
|
|
|
if (DsOrderTool::isSkuSubNameEqual($platformSkuSubName, $skuInfo['skuSubName'])) {
|
|
|
$matchSkuInfo = $skuInfo;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$returnMatchSourceSku = $manualRelateSourceSkuInfo ?: $matchSkuInfo;
|
|
|
if ($returnMatchSourceSku) {
|
|
|
$returnMatchSourceSku['sourceSellerId'] = $sourceSellerId;
|
|
|
$returnMatchSourceSku['sourceRelationVersion'] = $manualRelateSourceSkuRelation['sourceRelationVersion'] ?: null;
|
|
|
}
|
|
|
return $returnMatchSourceSku;
|
|
|
}
|
|
|
|
|
|
public static function isSkuSubNameEqual($platformSkuSubName, $sourceSkuSubName) {
|
|
|
$platformSkuSubNames = explode(' ', self::filterSpecialString($platformSkuSubName));
|
|
|
$sourceSkuSubNames = explode(' ', self::filterSpecialString($sourceSkuSubName));
|
|
|
|
|
|
$platformSkuSubNameLength = $sourceSkuSubNameLength = $findCount = 0;
|
|
|
foreach ($platformSkuSubNames as $platformSkuSubName) {
|
|
|
if (empty($platformSkuSubName)) {
|
|
|
continue;
|
|
|
}
|
|
|
$platformSkuSubNameLength ++;
|
|
|
foreach ($sourceSkuSubNames as $sourceSkuSubName) {
|
|
|
if ($sourceSkuSubName == $platformSkuSubName) {
|
|
|
$findCount ++;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
foreach ($sourceSkuSubNames as $sourceSkuSubName) {
|
|
|
if (empty($sourceSkuSubName)) {
|
|
|
continue;
|
|
|
}
|
|
|
$sourceSkuSubNameLength ++;
|
|
|
}
|
|
|
|
|
|
return ($sourceSkuSubNameLength == $platformSkuSubNameLength && $platformSkuSubNameLength == $findCount);
|
|
|
}
|
|
|
|
|
|
public static function filterSpecialString($skuSubName) {
|
|
|
$skuSubName = str_replace(
|
|
|
array('(', ')', ':', '【', '】', ',', ';', '\|'),
|
|
|
array('(', ')', ':', '[', ']', ',', ';', ' '),
|
|
|
$skuSubName
|
|
|
);
|
|
|
|
|
|
return $skuSubName;
|
|
|
}
|
|
|
|
|
|
public static function getRealSourceSkuPurchaseQuantity($platformItemTotal, $matchSourceSkuInfo, $sourceSkuRelation) {
|
|
|
if (empty($sourceSkuRelation) || empty($matchSourceSkuInfo)) {
|
|
|
return $platformItemTotal;
|
|
|
}
|
|
|
|
|
|
$purchaseQuantity = $platformItemTotal;
|
|
|
|
|
|
$isSourceItemNoSkuFlag = ($matchSourceSkuInfo['sourceItemId'] == $matchSourceSkuInfo['sourceSkuId']);
|
|
|
if ($sourceSkuRelation && (($sourceSkuRelation['sourceSkuId'] == $matchSourceSkuInfo['sourceSkuId']) || ($isSourceItemNoSkuFlag && ($matchSourceSkuInfo['sourceItemId'] == $sourceSkuRelation['sourceItemId'])))) {
|
|
|
$purchaseQuantity = $sourceSkuRelation['sourceNum'] ? ($platformItemTotal * $sourceSkuRelation['sourceNum']) : $platformItemTotal;
|
|
|
}
|
|
|
|
|
|
return $purchaseQuantity;
|
|
|
}
|
|
|
|
|
|
public static function formatRelateSourceProductInfo($item, $matchSourceSkuInfo) {
|
|
|
$nvMap = array(
|
|
|
'skuSubName' => 'skuSubName',
|
|
|
'title' => 'title',
|
|
|
'sellerLoginId' => 'shopName',
|
|
|
'img' => 'logo',
|
|
|
'sourceItemId' => 'sourceItemId',
|
|
|
'price' => 'price',
|
|
|
'consignPrice' => 'consignPrice',
|
|
|
'instanceCode' => 'instanceCode',
|
|
|
'isJxhyOffer' => 'isJxhyOffer',
|
|
|
'jxhyPrice' => 'jxhyPrice',
|
|
|
);
|
|
|
if (!$matchSourceSkuInfo && $item) {
|
|
|
$matchSourceSkuInfo = current($item['skus']);
|
|
|
$matchSourceSkuInfo['skuSubName'] = null;
|
|
|
$matchSourceSkuInfo['price'] = null;
|
|
|
}
|
|
|
$item = array_merge($item, $matchSourceSkuInfo);
|
|
|
|
|
|
$nvItem = array();
|
|
|
foreach ($item as $n => $value) {
|
|
|
if (array_key_exists($n, $nvMap)) {
|
|
|
$nvItem[$nvMap[$n]] = $value;
|
|
|
if ($n == 'sourceItemId') {
|
|
|
$nvItem['productUrl'] = self::build1688ProductUrl($value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $nvItem;
|
|
|
}
|
|
|
|
|
|
public static function formatDsPurchaseOrderItems($purchaseOrderItems) {
|
|
|
$nvMap = array(
|
|
|
'platformItemId' => 'platformItemId',
|
|
|
'platformSkuId' => 'platformSkuId',
|
|
|
'platformOrderId' => 'platformOrderId',
|
|
|
'productId' => 'sourceItemId',
|
|
|
'sourceOrderId' => 'sourceOrderId',
|
|
|
'skuId' => 'sourceSkuId',
|
|
|
'price' => 'price',
|
|
|
'quantity' => 'itemTotal',
|
|
|
'name' => 'title',
|
|
|
'skuSubName' => 'skuSubName',
|
|
|
'productImgUrl' => 'logo',
|
|
|
'productSnapshotUrl' => 'productUrl',
|
|
|
'sellerLoginId' => 'shopName',
|
|
|
'flow' => 'flow',
|
|
|
'isJxhyOffer' => 'isJxhyOffer',
|
|
|
'createTime' => 'createTime',
|
|
|
);
|
|
|
|
|
|
$nvItems = array();
|
|
|
foreach ($purchaseOrderItems as $key => $item) {
|
|
|
$nvItem = array();
|
|
|
foreach ($item as $n => $value) {
|
|
|
if (array_key_exists($n, $nvMap)) {
|
|
|
$nvItem[$nvMap[$n]] = $value;
|
|
|
}
|
|
|
}
|
|
|
$nvItems[$key] = $nvItem;
|
|
|
}
|
|
|
|
|
|
return $nvItems;
|
|
|
}
|
|
|
|
|
|
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 checkNeedDecryptConsigneeInfo($platformOrder, $shopPurchaseSetting, $sourceSellerId) {
|
|
|
if ($shopPurchaseSetting['isEncryptDsOrder'] == 1) {
|
|
|
if ($shopPurchaseSetting['encryptDsOrderType'] == PurchaseOrderConst::dsEncryptOrderTypeAllSeller) {
|
|
|
return false;
|
|
|
}
|
|
|
$allowDsEncryptOrderSellerIds = array_column($shopPurchaseSetting['allowDsEncryptOrderSourceSellers'] ?: [], 'sellerIdMd5');
|
|
|
if (in_array(md5($sourceSellerId), $allowDsEncryptOrderSellerIds)) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
$consigneeInfo = $platformOrder['consigneeInfo'];
|
|
|
$hasDecryptFields = $consigneeInfo['hasDecryptFields'] ?: [];
|
|
|
|
|
|
return (count($hasDecryptFields) != 3);
|
|
|
}
|
|
|
|
|
|
public static function getDsRefundStatusByAfterSaleStatus($afterSaleStatus) {
|
|
|
if (is_null($afterSaleStatus)) {
|
|
|
return null;
|
|
|
}
|
|
|
$map = [
|
|
|
DsOrderConst::refundStatusRefunding => [
|
|
|
AfterSalesConst::afterSalesStatusBuyerApplyRefund,
|
|
|
AfterSalesConst::afterSalesStatusReturnRefund,
|
|
|
AfterSalesConst::afterSalesStatusSellerAgreeRefund,
|
|
|
AfterSalesConst::afterSalesStatusPlatformAgreeRefund,
|
|
|
AfterSalesConst::afterSalesStatusRejectRefund,
|
|
|
AfterSalesConst::afterSalesStatusAgreeReturnRefund,
|
|
|
AfterSalesConst::afterSalesStatusPlatformProcessing,
|
|
|
AfterSalesConst::afterSalesStatusPlatformProcessing,
|
|
|
AfterSalesConst::afterSalesStatusExchangeGoodsWaitSellerProcess,
|
|
|
AfterSalesConst::afterSalesStatusExchangeGoodsWaitBuyerProcess,
|
|
|
AfterSalesConst::afterSalesStatusExchangeGoodsWaitBuyerConfirm,
|
|
|
AfterSalesConst::afterSalesStatusWaitBuyerRejectGoods,
|
|
|
AfterSalesConst::afterSalesStatusExchangeGoodsWaitSellerSend,
|
|
|
AfterSalesConst::afterSalesStatusWaitSellerAgreeRepair,
|
|
|
AfterSalesConst::afterSalesStatusWaitBuyerConfirmDeliver,
|
|
|
AfterSalesConst::afterSalesStatusWaitBuyerConfirm,
|
|
|
],
|
|
|
DsOrderConst::refundStatusClose => [
|
|
|
AfterSalesConst::afterSalesStatusPlatformRejectRefund,
|
|
|
AfterSalesConst::afterSalesStatusBuyerCancelRefund,
|
|
|
AfterSalesConst::afterSalesStatusBuyerProcessOverdue,
|
|
|
AfterSalesConst::afterSalesStatusBuyerRefundOverdue,
|
|
|
AfterSalesConst::afterSalesStatusExchangeGoodsFail,
|
|
|
AfterSalesConst::afterSalesStatusRepairClose,
|
|
|
],
|
|
|
DsOrderConst::refundStatusFinish => [
|
|
|
AfterSalesConst::afterSalesStatusRefundSuccess,
|
|
|
AfterSalesConst::afterSalesStatusExchangeGoodsSuccess,
|
|
|
AfterSalesConst::afterSalesStatusRepairSuccess,
|
|
|
],
|
|
|
];
|
|
|
|
|
|
$dsRefundStatus = null;
|
|
|
foreach ($map as $loopAfterSaleStatus => $afterSaleStatusArr) {
|
|
|
if (in_array($afterSaleStatus, $afterSaleStatusArr)) {
|
|
|
$dsRefundStatus = $loopAfterSaleStatus;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return $dsRefundStatus;
|
|
|
}
|
|
|
|
|
|
public static function getDsAutoPurchaseOrderBufferGmtExec($delayPurchaseMinute, $orderGmtPayTime) {
|
|
|
$time = time();
|
|
|
|
|
|
$orderPayTime = $orderGmtPayTime ? strtotime($orderGmtPayTime) : 0;
|
|
|
$payDiff = $time - $orderPayTime;
|
|
|
$delayPurchaseSecond = $delayPurchaseMinute * 60;
|
|
|
$baseSecond = rand(5, 100);
|
|
|
if ($payDiff < $delayPurchaseSecond) {
|
|
|
$baseSecond += $delayPurchaseSecond - $payDiff;
|
|
|
}
|
|
|
$execTime = $time + $baseSecond;
|
|
|
|
|
|
$h = (int)date('H', $execTime);
|
|
|
if ($h >= 23) {
|
|
|
$execTime += 8 * 3600;
|
|
|
} else if ($h < 8) {
|
|
|
$execTime += (8 - $h) * 3600;
|
|
|
}
|
|
|
|
|
|
return date('Y-m-d H:i:s', $execTime);
|
|
|
}
|
|
|
|
|
|
public static function buildDsWaitPayStatus(&$filter, $appOrderStatus) {
|
|
|
if ($appOrderStatus == DsOrderConst::orderStatusWaitPay) {
|
|
|
$filter['dsWaitPayStatus'] = [
|
|
|
DsOrderConst::dsWaitPayStatusAllUnpaid,
|
|
|
DsOrderConst::dsWaitPayStatusPartWaitPay,
|
|
|
];
|
|
|
$filter['dsPurchaseStatus'] = array(DsOrderConst::dsPurchaseStatusWaitPay);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static function buildSameSourceUniqueKey($sourceSellerId, $instanceCode) {
|
|
|
if (empty($sourceSellerId) && empty($instanceCode)) {
|
|
|
return '';
|
|
|
}
|
|
|
return implode('-', [
|
|
|
$sourceSellerId ?: '',
|
|
|
$instanceCode ?: '',
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
public static function build1688OrderDetailUrl($sourceOrderId) {
|
|
|
return sprintf('https://trade.1688.com/order/new_step_order_detail.htm?orderId=%s&amug_web_biz=fwmkt&amug_web_fl_src=cy',$sourceOrderId);
|
|
|
}
|
|
|
|
|
|
public static function buildMergeOrderBizId(... $param) {
|
|
|
$args = func_get_args();
|
|
|
if (empty($args)) {
|
|
|
return null;
|
|
|
}
|
|
|
sort($args);
|
|
|
return md5(json_encode($args));
|
|
|
}
|
|
|
} |