|
|
@@ -22,6 +22,7 @@ use common\components\dateUtil;
|
|
|
use common\components\delivery\util\DeliveryQuoteUtil;
|
|
|
use common\components\dict;
|
|
|
use common\components\imgUtil;
|
|
|
+use common\components\mapUtil;
|
|
|
use common\components\noticeUtil;
|
|
|
use common\components\orderSn;
|
|
|
use Yii;
|
|
|
@@ -622,30 +623,114 @@ class PurchaseController extends BaseController
|
|
|
// xhShMethod 门店:下单前按配置写入不满最低消费时的附加包装费/运费,关键词 sh_method_area
|
|
|
$newShMethod = dict::getNewMethodShop();
|
|
|
if (in_array($ghsShopId, $newShMethod)) {
|
|
|
- $shMethodBigNum = 0;
|
|
|
- foreach ($productList as $itemData) {
|
|
|
- $shMethodBigNum += floatval($itemData['bigNum'] ?? 0);
|
|
|
- }
|
|
|
- $additionalCosts = ShMethodClass::calcFee(
|
|
|
- $ghsShopId,
|
|
|
- $ghsMainId,
|
|
|
- $sendType,
|
|
|
- $shMethodItemAmount,
|
|
|
- $shMethodBigNum,
|
|
|
- $customId,
|
|
|
- $ghsInfo
|
|
|
- );
|
|
|
-
|
|
|
- // 如果产生了附加运费,与前面可能产生的 sendCost 进行累加或覆盖
|
|
|
- if ($additionalCosts['sendCost'] > 0) {
|
|
|
- $post['sendCost'] = bcadd($post['sendCost'] ?? 0, $additionalCosts['sendCost'], 2);
|
|
|
+
|
|
|
+ $shCurrentConfig = shMethodClass::getConfig($ghsShopId, $ghsMainId, $sendType);
|
|
|
+ $shCurrentName = $shCurrentConfig['name'] ?? '';
|
|
|
+ if (isset($shCurrentConfig['status']) && $shCurrentConfig['status'] == 0) {
|
|
|
+ util::fail($shCurrentName . '已停用');
|
|
|
}
|
|
|
|
|
|
- // 如果产生了附加包装费,覆盖前面赋值的 packCost
|
|
|
- if ($additionalCosts['packCost'] > 0) {
|
|
|
- $post['packCost'] = $additionalCosts['packCost'];
|
|
|
+ if ($sendType == dict::getDict('sendType', 'thirdSend')) {
|
|
|
+ //如果是发跑腿
|
|
|
+
|
|
|
+ // 生成随机订单号,不要跟原来的订单号混起来,跑腿-销售单-
|
|
|
+ $prefix = 'PT-XSD-' . $this->mainId . '-';
|
|
|
+ $orderSn = $prefix . round(microtime(true) * 1000);
|
|
|
+
|
|
|
+ $calcType = $shCurrentConfig['calcType'] ?? 0;
|
|
|
+ if ($calcType == 1) {
|
|
|
+ //使用自定义计算费用
|
|
|
+ $startKm = $shCurrentConfig['startKm'] ?? 0;
|
|
|
+ $startPrice = $shCurrentConfig['startPrice'] ?? 0;
|
|
|
+ $perKmPrice = $shCurrentConfig['perKmPrice'] ?? 0;//超出起步,每公里加收金额
|
|
|
+ $changeRate = $shCurrentConfig['changeRate'] ?? 0;//负值时为降价百分比,正值时为涨价百分比
|
|
|
+ if ($startKm <= 0 || $startPrice <= 0 || $perKmPrice <= 0) {
|
|
|
+ util::fail('算运费失败,请更换配送方式');
|
|
|
+ }
|
|
|
+ //计算客户到店的距离,骑电动车
|
|
|
+ $distanceRespond = mapUtil::calcShopDistanceByEleBike($custom, $ghsShopInfo);
|
|
|
+ $sendDistance = $distanceRespond['distanceKm'] ?? 0;
|
|
|
+ if ($sendDistance <= 0) {
|
|
|
+ util::fail('算运费失败,距离是0,请选到店自取');
|
|
|
+ }
|
|
|
+ // 计算运费逻辑
|
|
|
+ $sendCost = $startPrice;
|
|
|
+ if ($sendDistance > $startKm) {
|
|
|
+ $extraDistance = bcsub($sendDistance, $startKm, 2);
|
|
|
+ $extraCost = bcmul($extraDistance, $perKmPrice, 2);
|
|
|
+ $sendCost = bcadd($sendCost, $extraCost, 2);
|
|
|
+ }
|
|
|
+ if ($changeRate != 0) {
|
|
|
+ // 临时涨价/降价百分比
|
|
|
+ $rate = bcadd(1, bcdiv($changeRate, 100, 4), 4);
|
|
|
+ $sendCost = bcmul($sendCost, $rate, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ $post['sendCost'] = bcadd($post['sendCost'] ?? 0, $sendCost, 2);
|
|
|
+ $post['sendDistance'] = $sendDistance;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 使用 DeliveryQuoteUtil 获取配送报价
|
|
|
+ try {
|
|
|
+ $quoteResult = DeliveryQuoteUtil::getDeliveryQuote([
|
|
|
+ 'productList' => $productList,
|
|
|
+ 'deliveryPlatform' => $post['deliveryPlatform'],
|
|
|
+ 'deliveryBracketContent' => $post['deliveryBracketContent'], // 平台多报价识别id
|
|
|
+ 'ghsInfo' => $ghsInfo,
|
|
|
+ 'custom' => $custom,
|
|
|
+ 'order' => [
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
+ 'goodsType' => 1, //商品类型:0 花束 1 花材
|
|
|
+ 'itemTotalAmount' => $post['itemTotalAmount'] ?? 0,
|
|
|
+ 'remark' => $post['remark'] ?? '',
|
|
|
+ ],
|
|
|
+ 'mainId' => $this->mainId,
|
|
|
+ 'productCount' => $productCount,
|
|
|
+ //当前配送方式
|
|
|
+ 'shConfig' => $shCurrentConfig,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $sendCost = $quoteResult['sendCost'];
|
|
|
+ $sendDistance = $quoteResult['sendDistance'];
|
|
|
+
|
|
|
+ $post['sendCost'] = bcadd($post['sendCost'] ?? 0, $sendCost, 2);
|
|
|
+ $post['sendDistance'] = $sendDistance;
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ noticeUtil::push("计算跑腿费用出错了:" . $e->getMessage(), '15280215347');
|
|
|
+ util::fail('下单失败,请选其他配送方式');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //如果是不是发跑腿,比如送货上门和发快递,则可能要收运费或打包费任一
|
|
|
+
|
|
|
+ $shMethodBigNum = 0;
|
|
|
+ foreach ($productList as $itemData) {
|
|
|
+ $shMethodBigNum += floatval($itemData['bigNum'] ?? 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ $additionalCosts = ShMethodClass::calcFee(
|
|
|
+ $shCurrentConfig,
|
|
|
+ $sendType,
|
|
|
+ $shMethodItemAmount,
|
|
|
+ $shMethodBigNum,
|
|
|
+ $customId,
|
|
|
+ $ghsInfo
|
|
|
+ );
|
|
|
+
|
|
|
+ // 如果产生了附加运费,与前面可能产生的 sendCost 进行累加或覆盖
|
|
|
+ if ($additionalCosts['sendCost'] > 0) {
|
|
|
+ $post['sendCost'] = bcadd($post['sendCost'] ?? 0, $additionalCosts['sendCost'], 2);
|
|
|
+ }
|
|
|
+ // 如果产生了附加包装费,覆盖前面赋值的 packCost。
|
|
|
+ if ($additionalCosts['packCost'] > 0) {
|
|
|
+ $post['packCost'] = $additionalCosts['packCost'];
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- }else{
|
|
|
+
|
|
|
+ } else {
|
|
|
|
|
|
//同城发货包装费和运费的计算
|
|
|
$sendCost = 0;
|
|
|
@@ -658,7 +743,7 @@ class PurchaseController extends BaseController
|
|
|
util::fail('不能使用跑腿');
|
|
|
}
|
|
|
if ($openIntraCity == 1) {
|
|
|
- // 生成随机订单号,不要跟原来的混起来,跑腿-销售单-
|
|
|
+ // 生成随机订单号,不要跟原来的单号混起来,跑腿-销售单-
|
|
|
$prefix = 'PT-XSD-' . $this->mainId . '-';
|
|
|
$orderSn = $prefix . round(microtime(true) * 1000);
|
|
|
|
|
|
@@ -688,7 +773,8 @@ class PurchaseController extends BaseController
|
|
|
$sendCost = $quoteResult['sendCost'];
|
|
|
$sendDistance = $quoteResult['sendDistance'];
|
|
|
} catch (\Exception $e) {
|
|
|
- util::fail($e->getMessage());
|
|
|
+ noticeUtil::push("计算跑腿费用出错了:" . $e->getMessage(), '15280215347');
|
|
|
+ util::fail('下单失败,请选其他配送方式');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -770,7 +856,7 @@ class PurchaseController extends BaseController
|
|
|
|
|
|
//情意花卉,必选品
|
|
|
if ($ghsShopId == 100883) {
|
|
|
- $hasMust = array_intersect($ids, [5017957,5036067,5036089,5036099,5017958,5036063,5017948,5035980,5036073,5036075,5036076,5036117,5036118,5017949,5035979,5035976,5035928,5035930,5036061,5035879]);
|
|
|
+ $hasMust = array_intersect($ids, [5017957, 5036067, 5036089, 5036099, 5017958, 5036063, 5017948, 5035980, 5036073, 5036075, 5036076, 5036117, 5036118, 5017949, 5035979, 5035976, 5035928, 5035930, 5036061, 5035879]);
|
|
|
if (empty($hasMust)) {
|
|
|
util::fail('请返回选择 必选商品');
|
|
|
}
|