|
|
@@ -7,6 +7,7 @@ use bizHd\goods\classes\GoodsClass;
|
|
|
use bizHd\groupBuy\classes\GroupBuyActivityClass;
|
|
|
use bizHd\groupBuy\classes\GroupBuyClass;
|
|
|
use bizHd\groupBuy\classes\GroupBuyMemberClass;
|
|
|
+use bizHd\order\classes\PsMethodClass;
|
|
|
use bizHd\order\services\OrderService;
|
|
|
use bizHd\shop\classes\ShopClass;
|
|
|
use bizMall\hd\classes\HdClass;
|
|
|
@@ -23,7 +24,8 @@ use Yii;
|
|
|
/**
|
|
|
* 商城端拼团接口
|
|
|
* 落地页 / 团详情 / 开团 / 参团 / 我的拼团
|
|
|
- * 开团/参团订单按团购价结算,不叠加会员折扣、门店满减等优惠
|
|
|
+ * 开团/参团订单按团购价结算,不叠加会员折扣、门店满减、红包
|
|
|
+ * 配送附加费与跑腿距离运费与混合结算同源(PsMethodClass::calcFeeForMallContext / calcMixRunnerFreight)
|
|
|
*/
|
|
|
class GroupBuyController extends BaseController
|
|
|
{
|
|
|
@@ -113,6 +115,8 @@ class GroupBuyController extends BaseController
|
|
|
'showCountdown' => intval($row['showCountdown']),
|
|
|
'detailImages' => $detailImages,
|
|
|
'picTextGoods' => $picTextGoods,
|
|
|
+ // 花束是否包运费:结算页跑腿模式(bouquetIncluded)与混合单同源判断
|
|
|
+ 'freightType' => !empty($goods) ? intval($goods->freightType ?? 0) : 0,
|
|
|
'openGroup' => $openGroup,
|
|
|
]);
|
|
|
}
|
|
|
@@ -137,6 +141,12 @@ class GroupBuyController extends BaseController
|
|
|
if (empty($landing)) {
|
|
|
$landing = GroupBuyActivityClass::getActiveGoodsRowByGoodsId($mainId, intval($this->shopId), intval($detail['goodsId']));
|
|
|
}
|
|
|
+ if (!empty($landing) && !isset($landing['freightType'])) {
|
|
|
+ $landingGoodsId = intval($landing['goodsId'] ?? ($detail['goodsId'] ?? 0));
|
|
|
+ $landingGoods = $landingGoodsId > 0 ? GoodsClass::getById($landingGoodsId, true) : null;
|
|
|
+ // 分享进详情也要带包运费标记,否则结算页跑腿会误走平台报价
|
|
|
+ $landing['freightType'] = !empty($landingGoods) ? intval($landingGoods->freightType ?? 0) : 0;
|
|
|
+ }
|
|
|
$detail['activityGoods'] = $landing;
|
|
|
|
|
|
$currentShopId = intval(Yii::$app->request->get('account', 0));
|
|
|
@@ -313,7 +323,8 @@ class GroupBuyController extends BaseController
|
|
|
|
|
|
/**
|
|
|
* 组装并创建拼团订单(核价以后端活动商品为准)
|
|
|
- * 团购价已是活动优惠价:跳过会员折、门店满减,避免再叠折扣
|
|
|
+ * 团购价已是活动优惠价:跳过会员折、门店满减、红包;运费/包装费与混合结算同源计算
|
|
|
+ * 跑腿(sendType=2)走与混合单相同的 calcMixRunnerFreight,不信任前端报价
|
|
|
*
|
|
|
* @param object $form
|
|
|
* @param array $row
|
|
|
@@ -333,6 +344,9 @@ class GroupBuyController extends BaseController
|
|
|
if (empty($custom) && !empty($currenCustom)) {
|
|
|
$custom = $currenCustom;
|
|
|
}
|
|
|
+ if (empty($custom)) {
|
|
|
+ util::fail('请先登录');
|
|
|
+ }
|
|
|
$hd = $this->hd;
|
|
|
$user = $this->user;
|
|
|
$saleGoodsId = intval($row['goodsId']);
|
|
|
@@ -350,20 +364,101 @@ class GroupBuyController extends BaseController
|
|
|
}
|
|
|
$goodsPrice = bcmul($unitPrice, $goodsNum, 2);
|
|
|
$sendType = intval($form->sendType ?? dict::getDict('sendType', 'shopGet'));
|
|
|
- $sendCost = 0;
|
|
|
- // 跑腿配送暂不在拼团链路单独报价,统一引导自取或送货上门(运费0,与花店协商)
|
|
|
- if ($sendType == dict::getDict('sendType', 'thirdSend')) {
|
|
|
- util::fail('拼团暂不支持跑腿,请选择自取或送货上门');
|
|
|
- }
|
|
|
- if ($sendType == dict::getDict('sendType', 'carGet')) {
|
|
|
+ // 商家配送(0)/跑腿(2)必须有收花人与坐标,与混合结算一致
|
|
|
+ if (in_array($sendType, [dict::getDict('sendType', 'carGet'), dict::getDict('sendType', 'thirdSend')], true)) {
|
|
|
if (empty($form->receiveUserName)) {
|
|
|
util::fail('请填写收花人名字');
|
|
|
}
|
|
|
if (empty($form->receiveMobile) || !stringUtil::isMobile($form->receiveMobile)) {
|
|
|
util::fail('请填写正确的收花人手机号');
|
|
|
}
|
|
|
+ if (empty($form->long) || empty($form->lat)) {
|
|
|
+ util::fail('请先完善地址');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 商家配送(0)/跑腿(2)必填配送时间;自取与物流/快递不强制(与混合结算一致)
|
|
|
+ if (in_array($sendType, [0, 2], true) && empty($form->reachPeriod)) {
|
|
|
+ util::fail('请选择配送时间');
|
|
|
+ }
|
|
|
+
|
|
|
+ $customInfo = PsMethodClass::buildCustomInfo($hd, $custom);
|
|
|
+ $additionalCosts = PsMethodClass::calcFeeForMallContext(
|
|
|
+ $this->shopId,
|
|
|
+ $mainId,
|
|
|
+ $sendType,
|
|
|
+ $goodsPrice,
|
|
|
+ $goodsNum,
|
|
|
+ intval($custom->id),
|
|
|
+ $customInfo
|
|
|
+ );
|
|
|
+ $unMeetSendCost = $additionalCosts['sendCost'] ?? 0;
|
|
|
+ $packingFee = $additionalCosts['packCost'] ?? 0;
|
|
|
+ $psMethodError = PsMethodClass::checkLimit(
|
|
|
+ $this->shopId,
|
|
|
+ $mainId,
|
|
|
+ $sendType,
|
|
|
+ $goodsPrice,
|
|
|
+ $goodsNum,
|
|
|
+ $packingFee,
|
|
|
+ $unMeetSendCost,
|
|
|
+ intval($custom->id),
|
|
|
+ $customInfo
|
|
|
+ );
|
|
|
+ if ($psMethodError !== '') {
|
|
|
+ util::fail($psMethodError);
|
|
|
}
|
|
|
|
|
|
+ $freightType = intval($goodsInfo->freightType ?? 0);
|
|
|
+ $resolvedProduct = [[
|
|
|
+ 'productId' => $saleGoodsId,
|
|
|
+ 'unitType' => 0,
|
|
|
+ 'property' => 0,
|
|
|
+ 'freightType' => $freightType,
|
|
|
+ 'unitPrice' => $unitPrice,
|
|
|
+ 'num' => $goodsNum,
|
|
|
+ ]];
|
|
|
+ $runnerSendCost = 0;
|
|
|
+ $sendDistance = 0;
|
|
|
+ $freightSource = '';
|
|
|
+ // 跑腿距离运费与混合单同源;未达门槛附加运费仍由 calcFee 单独给出
|
|
|
+ if ($sendType == dict::getDict('sendType', 'thirdSend')) {
|
|
|
+ $mapSet = \biz\shop\classes\ShopClass::hasIntraCity($shop);
|
|
|
+ $openIntraCity = $mapSet['openIntraCity'] ?? 0;
|
|
|
+ $runnerPost = [
|
|
|
+ 'receiveUserName' => strval($form->receiveUserName ?? ''),
|
|
|
+ 'receiveMobile' => strval($form->receiveMobile ?? ''),
|
|
|
+ 'address' => strval($form->address ?? ''),
|
|
|
+ 'floor' => strval($form->floor ?? ''),
|
|
|
+ 'city' => strval($form->city ?? ''),
|
|
|
+ 'dist' => strval($form->dist ?? ''),
|
|
|
+ 'long' => $form->long ?? '',
|
|
|
+ 'lat' => $form->lat ?? '',
|
|
|
+ 'deliveryPlatform' => strval($form->deliveryPlatform ?? ''),
|
|
|
+ 'deliveryBracketContent' => strval($form->deliveryBracketContent ?? ''),
|
|
|
+ 'remark' => strval($form->remark ?? ''),
|
|
|
+ ];
|
|
|
+ $runnerResult = PsMethodClass::calcMixRunnerFreight(
|
|
|
+ $shop,
|
|
|
+ $this->shopId,
|
|
|
+ $mainId,
|
|
|
+ $runnerPost,
|
|
|
+ $resolvedProduct,
|
|
|
+ 0,
|
|
|
+ $goodsPrice,
|
|
|
+ $openIntraCity,
|
|
|
+ 0,
|
|
|
+ $goodsNum,
|
|
|
+ 'PT-GB-',
|
|
|
+ '团购单'
|
|
|
+ );
|
|
|
+ $runnerSendCost = $runnerResult['sendCost'];
|
|
|
+ $sendDistance = $runnerResult['sendDistance'];
|
|
|
+ $freightSource = $runnerResult['freightSource'];
|
|
|
+ }
|
|
|
+ $sendCost = bcadd($unMeetSendCost, $runnerSendCost, 2);
|
|
|
+ $modifyPrice = bcadd($goodsPrice, $sendCost, 2);
|
|
|
+ $modifyPrice = bcadd($modifyPrice, $packingFee, 2);
|
|
|
+
|
|
|
$post = [
|
|
|
'sendType' => $sendType,
|
|
|
'receiveUserName' => strval($form->receiveUserName ?? ''),
|
|
|
@@ -371,6 +466,8 @@ class GroupBuyController extends BaseController
|
|
|
'address' => strval($form->address ?? ''),
|
|
|
'floor' => strval($form->floor ?? ''),
|
|
|
'city' => strval($form->city ?? ''),
|
|
|
+ 'dist' => strval($form->dist ?? ''),
|
|
|
+ 'province' => strval($form->province ?? ''),
|
|
|
'long' => strval($form->long ?? ''),
|
|
|
'lat' => strval($form->lat ?? ''),
|
|
|
'showAddress' => strval($form->showAddress ?? ''),
|
|
|
@@ -378,7 +475,13 @@ class GroupBuyController extends BaseController
|
|
|
'reachDate' => !empty($form->reachDate) ? $form->reachDate : date('Y-m-d'),
|
|
|
'reachPeriod' => strval($form->reachPeriod ?? ''),
|
|
|
'sendCost' => $sendCost,
|
|
|
- 'sendDistance' => 0,
|
|
|
+ 'packingFee' => $packingFee,
|
|
|
+ 'sendDistance' => $sendDistance,
|
|
|
+ 'freightSource' => $freightSource,
|
|
|
+ 'runnerSendCost' => $runnerSendCost,
|
|
|
+ 'needCard' => intval($form->needCard ?? 0),
|
|
|
+ 'cardInfo' => intval($form->needCard ?? 0) === 1 ? strval($form->cardInfo ?? '') : '',
|
|
|
+ 'anonymity' => intval($form->anonymity ?? 0),
|
|
|
'sjId' => intval($this->sjId ?: ($shop->sjId ?? 0)),
|
|
|
'shopId' => $this->shopId,
|
|
|
'mainId' => $mainId,
|
|
|
@@ -394,27 +497,20 @@ class GroupBuyController extends BaseController
|
|
|
: strval($user->mobile ?? ''),
|
|
|
'payWay' => 0,
|
|
|
'store' => 0,
|
|
|
- 'modifyPrice' => stringUtil::calcAdd($sendCost, $goodsPrice),
|
|
|
+ 'modifyPrice' => $modifyPrice,
|
|
|
'deadline' => time() + 1800,
|
|
|
'orderSn' => orderSn::getOrderSn(),
|
|
|
'fromType' => dict::getDict('fromType', 'mall'),
|
|
|
'cash' => 0,
|
|
|
'needPrint' => dict::getDict('needPrint', 'need'),
|
|
|
'groupBuyId' => intval($groupBuyId),
|
|
|
- // 拼团价已是活动价:跳过会员折和门店满减,避免 createHdOrder/addOrder 再叠折扣
|
|
|
+ // 拼团价已是活动价:跳过会员折、门店满减、红包,避免再叠优惠
|
|
|
'skipMemberDiscount' => 1,
|
|
|
'skipShopMeetCut' => 1,
|
|
|
- 'product' => [[
|
|
|
- 'productId' => $saleGoodsId,
|
|
|
- 'unitType' => 0,
|
|
|
- 'property' => 0,
|
|
|
- 'unitPrice' => $unitPrice,
|
|
|
- 'num' => $goodsNum,
|
|
|
- ]],
|
|
|
+ 'hbId' => 0,
|
|
|
+ 'hbAmount' => 0,
|
|
|
+ 'product' => $resolvedProduct,
|
|
|
];
|
|
|
- if ($sendType != 1 && empty($post['reachPeriod'])) {
|
|
|
- util::fail('请选择配送时间');
|
|
|
- }
|
|
|
return OrderService::createHdOrder($post, $custom, 0);
|
|
|
}
|
|
|
}
|