|
|
@@ -29,6 +29,7 @@ use bizHd\stat\classes\StatIncomeClass;
|
|
|
use bizHd\wx\classes\WxOpenClass;
|
|
|
use common\components\dict;
|
|
|
use common\components\imgUtil;
|
|
|
+use common\components\IntraCityExpress;
|
|
|
use common\components\mapUtil;
|
|
|
use common\components\noticeUtil;
|
|
|
use common\components\orderSn;
|
|
|
@@ -416,87 +417,65 @@ class PurchaseClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
//计算距离和运费【另外还有个地方要同步修改,关键词calc_freight_distance】 ssh 20221003
|
|
|
- public static function getDistanceFee($shop, $ghsShop, $weight, $mustHasFee = false)
|
|
|
+ public static function getDistanceFee($shop, $ghsShop, $weight, $custom)
|
|
|
{
|
|
|
-
|
|
|
- //万丽花行 跑腿不算运费
|
|
|
- if ($ghsShop->id == 12003) {
|
|
|
- return ['distance' => 0, 'showDistance' => 0, 'fee' => 0];
|
|
|
+ $ability = ShopClass::hasIntraCity($ghsShop);
|
|
|
+ $openIntraCity = $ability['openIntraCity'] ?? 0;
|
|
|
+ if ($openIntraCity == 0) {
|
|
|
+ //没有开启同城配送能力,不计算运费和距离
|
|
|
+ util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
|
|
|
}
|
|
|
-
|
|
|
$shopLat = $shop->lat ?? '';
|
|
|
$shopLong = $shop->long ?? '';
|
|
|
-
|
|
|
if (empty($shopLat) || empty($shopLong)) {
|
|
|
- util::fail('请完善门店地址哦');
|
|
|
+ util::fail('请完善你的收花地址');
|
|
|
}
|
|
|
-
|
|
|
- $ghsShopLat = $ghsShop->lat ?? '';
|
|
|
- $ghsShopLong = $ghsShop->long ?? '';
|
|
|
- if (empty($ghsShopLat) || empty($ghsShopLong)) {
|
|
|
- util::fail('商家地址有问题');
|
|
|
+ $address = $shop->address ?? '';
|
|
|
+ if (empty($address)) {
|
|
|
+ util::fail('请完善收花地址');
|
|
|
}
|
|
|
-
|
|
|
- //基础配送费8元,0-5公里,每公里+1元,5-100公里,6元起,每公里+2元
|
|
|
- //5-10公斤,2元起,每公斤+2元,10-15公斤,+12元,超过15公斤,+20元
|
|
|
- //00:00 - 06:00 +6元,22:00-24:00 +4元
|
|
|
- //恶劣天气,下单高峰期会临时调整价格
|
|
|
-
|
|
|
- //起步价
|
|
|
- $baseFee = 10;
|
|
|
- $distance = mapUtil::calculateDistance($shopLong, $shopLat, $ghsShopLong, $ghsShopLat);
|
|
|
-
|
|
|
- //0-5公里,每公里+1元,5-100公里,6元起,每公里+2元
|
|
|
- $formatDistance = ceil($distance / 1000);
|
|
|
- $startKiloFee = 6;
|
|
|
- if ($formatDistance < 5) {
|
|
|
- $addDistanceFee = bcmul($formatDistance, 2);
|
|
|
- } elseif ($formatDistance == 5) {
|
|
|
- $addDistanceFee = $startKiloFee;
|
|
|
- } else {
|
|
|
- $overKilo = bcsub($formatDistance, 5);
|
|
|
- $overFee = bcmul($overKilo, 3);
|
|
|
- $addDistanceFee = bcadd($startKiloFee, $overFee);
|
|
|
+ if ($weight <= 0) {
|
|
|
+ util::fail('花材没有重量');
|
|
|
}
|
|
|
|
|
|
- //5-10公斤,2元起,每公斤+2元,10-15公斤,+12元,超过15公斤,+20元
|
|
|
- $formatWeight = ceil($weight);
|
|
|
- if ($formatWeight > 15) {
|
|
|
- $addWeightFee = 20;
|
|
|
- } elseif ($formatWeight >= 10 && $formatWeight <= 15) {
|
|
|
- $addWeightFee = 12;
|
|
|
- } elseif ($formatWeight >= 5 && $formatWeight < 10) {
|
|
|
- $overWeight = bcsub($formatWeight, 4);
|
|
|
- $addWeightFee = bcmul($overWeight, 2);
|
|
|
- } else {
|
|
|
- $addWeightFee = 0;
|
|
|
- }
|
|
|
-
|
|
|
- $addFee = bcadd($addDistanceFee, $addWeightFee, 2);
|
|
|
- $totalFee = bcadd($baseFee, $addFee, 2);
|
|
|
+ $wxStoreId = $ability['wxStoreId'] ?? '';
|
|
|
+ $packageNum = 1;
|
|
|
+ $price = 300;
|
|
|
+ $cargo = [
|
|
|
+ 'cargo_name' => '鲜花花材', // 商品名称 -- $order 中没有,要在 goodsInfo 中取
|
|
|
+ 'cargo_weight' => intval($weight * 1000), // 单位:克 -- 把千克转换为克
|
|
|
+ 'cargo_price' => intval($price * 100), // 单位:分 -- 把元转换为分
|
|
|
+ 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
|
|
|
+ 'cargo_num' => $packageNum
|
|
|
+ ];
|
|
|
|
|
|
- //特殊时段费
|
|
|
- $timeFee = 0;
|
|
|
- $hour = date("G");
|
|
|
- //22:00 - 24:00 +4元
|
|
|
- if (in_array($hour, [22, 23])) {
|
|
|
- $timeFee = 4;
|
|
|
- }
|
|
|
- //00:00 - 06:00 +6元
|
|
|
- if (in_array($hour, [0, 1, 2, 3, 4, 5])) {
|
|
|
- $timeFee = 6;
|
|
|
+ $customName = $custom->customName ?? '';
|
|
|
+ $customMobile = $custom->customMobile ?? '';
|
|
|
+ if (empty($customMobile)) {
|
|
|
+ util::fail('客户手机缺失');
|
|
|
}
|
|
|
- $totalFee = bcadd($totalFee, $timeFee, 2);
|
|
|
-
|
|
|
- //恶劣天气和下单高峰费用
|
|
|
- $weatherFee = 0;
|
|
|
- $totalFee = bcadd($totalFee, $weatherFee, 2);
|
|
|
|
|
|
+ //根据环境变量判断是否使用沙盒环境
|
|
|
+ $useSandBox = getenv('YII_ENV') == 'production' ? 0 : 1;
|
|
|
+ $orderData = [
|
|
|
+ 'wx_store_id' => $wxStoreId,
|
|
|
+ 'user_name' => $customName,
|
|
|
+ 'user_phone' => $customMobile,
|
|
|
+ 'user_lng' => $shopLong,
|
|
|
+ 'user_lat' => $shopLat,
|
|
|
+ 'user_address' => $address,
|
|
|
+ 'cargo' => $cargo,
|
|
|
+ 'use_sandbox' => $useSandBox,
|
|
|
+ ];
|
|
|
+ //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
|
|
|
+ $result = IntraCityExpress::preAddOrder($orderData);
|
|
|
+ if ($result['errcode'] !== 0) {
|
|
|
+ util::fail('运费查询失败');
|
|
|
+ }
|
|
|
+ $distance = $result['distance'] ?? 0;
|
|
|
$showDistance = sprintf("%.1f", ($distance / 1000));
|
|
|
-
|
|
|
- //noticeUtil::push("距离:{$distance} {$showDistance} 重量:{$weight} 费用:{$totalFee}", '15280215347');
|
|
|
-
|
|
|
-
|
|
|
+ $fee = $result['est_fee'] ?? 0;
|
|
|
+ $totalFee = sprintf("%.1f", ($fee / 100));
|
|
|
return ['distance' => $distance, 'showDistance' => $showDistance, 'fee' => $totalFee];
|
|
|
}
|
|
|
|