|
|
@@ -2,7 +2,6 @@
|
|
|
|
|
|
namespace mall\controllers;
|
|
|
|
|
|
-use bizHd\custom\classes\CustomClass;
|
|
|
use bizHd\goods\classes\GoodsClass;
|
|
|
use bizHd\groupBuy\classes\GroupBuyActivityClass;
|
|
|
use bizHd\groupBuy\classes\GroupBuyClass;
|
|
|
@@ -10,7 +9,6 @@ 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;
|
|
|
use bizMall\pictext\classes\PicTextGoodsClass;
|
|
|
use common\components\business;
|
|
|
use common\components\dict;
|
|
|
@@ -24,6 +22,7 @@ use Yii;
|
|
|
/**
|
|
|
* 商城端拼团接口
|
|
|
* 落地页 / 团详情 / 开团 / 参团 / 我的拼团
|
|
|
+ * 分享直达或换店后仍带旧 hdId 时,按 account 恢复门店并建客,与 get-home 进店闭环一致
|
|
|
* 开团/参团订单按团购价结算,不叠加会员折扣、门店满减、红包
|
|
|
* 配送附加费与跑腿距离运费与混合结算同源(PsMethodClass::calcFeeForMallContext / calcMixRunnerFreight)
|
|
|
*/
|
|
|
@@ -38,13 +37,13 @@ class GroupBuyController extends BaseController
|
|
|
* 团购商品落地页:活动商品信息 + 商品详情图文 + 当前最快成团开放团
|
|
|
* GET goodsId
|
|
|
* 返回字段与商品详情页对齐:picTextGoods(标题/content JSON)供前端 rich-media-viewer 渲染
|
|
|
+ * 登录态按 account 恢复门店并建客,回传 hdId / inviteBound,与 get-home 进店闭环一致
|
|
|
*/
|
|
|
public function actionGoodsLanding()
|
|
|
{
|
|
|
- $mainId = intval($this->mainId);
|
|
|
- if ($mainId <= 0) {
|
|
|
- util::fail('无效门店');
|
|
|
- }
|
|
|
+ $ctx = $this->recoverShopAndResolveHd();
|
|
|
+ $mainId = $ctx['mainId'];
|
|
|
+
|
|
|
$goodsId = intval(Yii::$app->request->get('goodsId', 0));
|
|
|
if ($goodsId <= 0) {
|
|
|
util::fail('请选择商品');
|
|
|
@@ -118,19 +117,21 @@ class GroupBuyController extends BaseController
|
|
|
// 花束是否包运费:结算页跑腿模式(bouquetIncluded)与混合单同源判断
|
|
|
'freightType' => !empty($goods) ? intval($goods->freightType ?? 0) : 0,
|
|
|
'openGroup' => $openGroup,
|
|
|
+ // 供 mallApp 写入本地 hdId,避免后续开团/参团仍带旧店 hdId
|
|
|
+ 'hdId' => $ctx['hdId'],
|
|
|
+ 'inviteBound' => $ctx['inviteBound'],
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 拼团详情
|
|
|
* GET id
|
|
|
+ * 游客可浏览;已登录则按 account 恢复门店并建客,回传 hdId 供前端缓存
|
|
|
*/
|
|
|
public function actionDetail()
|
|
|
{
|
|
|
- $mainId = intval($this->mainId);
|
|
|
- if ($mainId <= 0) {
|
|
|
- util::fail('无效门店');
|
|
|
- }
|
|
|
+ $ctx = $this->recoverShopAndResolveHd();
|
|
|
+ $mainId = $ctx['mainId'];
|
|
|
$id = intval(Yii::$app->request->get('id', 0));
|
|
|
if ($id <= 0) {
|
|
|
util::fail('请选择拼团');
|
|
|
@@ -148,29 +149,8 @@ class GroupBuyController extends BaseController
|
|
|
$landing['freightType'] = !empty($landingGoods) ? intval($landingGoods->freightType ?? 0) : 0;
|
|
|
}
|
|
|
$detail['activityGoods'] = $landing;
|
|
|
-
|
|
|
- $currentShopId = intval(Yii::$app->request->get('account', 0));
|
|
|
- $hd = HdClass::getByCondition(['shopId' => $currentShopId, 'userId' => $this->userId], false, null, 'id, customId');
|
|
|
- if (empty($hd)) {
|
|
|
- // util::error(errCode::GROUP_BUY_HD_NOT_BOUND, '客户暂无关联此店');
|
|
|
-
|
|
|
- // 客户与当前门店无关系时,立即建立
|
|
|
- if (empty($this->user)) {
|
|
|
- util::fail('请先登录');
|
|
|
- }
|
|
|
- $shop = ShopClass::getById($currentShopId, true);
|
|
|
- if (empty($shop)) {
|
|
|
- util::fail('门店不存在');
|
|
|
- }
|
|
|
- $respond = CustomClass::buildRelation($shop, $this->user);
|
|
|
- if (empty($respond) || empty($respond['hd'])) {
|
|
|
- util::fail('关联门店失败');
|
|
|
- }
|
|
|
- $hdId = intval($respond['hd']->id);
|
|
|
- } else {
|
|
|
- $hdId = intval($hd['id']);
|
|
|
- }
|
|
|
- $detail['hdId'] = $hdId;
|
|
|
+ $detail['hdId'] = $ctx['hdId'];
|
|
|
+ $detail['inviteBound'] = $ctx['inviteBound'];
|
|
|
|
|
|
util::success($detail);
|
|
|
}
|
|
|
@@ -182,11 +162,9 @@ class GroupBuyController extends BaseController
|
|
|
{
|
|
|
$form = new CreateGroupBuyForm();
|
|
|
$form->loadAndValidate();
|
|
|
- $mainId = intval($this->mainId);
|
|
|
+ $ctx = $this->ensureCustomerContext();
|
|
|
+ $mainId = $ctx['mainId'];
|
|
|
$custom = $this->custom;
|
|
|
- if (empty($custom)) {
|
|
|
- util::fail('请先登录');
|
|
|
- }
|
|
|
$customId = intval($custom->id);
|
|
|
$activityGoodsId = intval($form->activityGoodsId);
|
|
|
$goodsNum = max(1, intval($form->goodsNum));
|
|
|
@@ -234,26 +212,9 @@ class GroupBuyController extends BaseController
|
|
|
{
|
|
|
$form = new JoinGroupBuyForm();
|
|
|
$form->loadAndValidate();
|
|
|
- $mainId = intval($this->mainId);
|
|
|
+ $ctx = $this->ensureCustomerContext();
|
|
|
+ $mainId = $ctx['mainId'];
|
|
|
$custom = $this->custom;
|
|
|
- $currentShopId = intval(Yii::$app->request->get('account', 0));
|
|
|
- if (empty($custom)) {
|
|
|
- $hd = HdClass::getByCondition(['shopId' => $currentShopId, 'userId' => $this->userId], false, null, 'id, customId');
|
|
|
- if (empty($hd)) {
|
|
|
- // 客户与当前门店无关系时,立即建立
|
|
|
- if (empty($this->user) || empty($this->shop)) {
|
|
|
- util::fail('请先登录');
|
|
|
- }
|
|
|
- $respond = CustomClass::buildRelation($this->shop, $this->user);
|
|
|
- if (empty($respond) || empty($respond['custom'])) {
|
|
|
- util::fail('关联门店失败');
|
|
|
- }
|
|
|
- $custom = $respond['custom'];
|
|
|
- } else {
|
|
|
- $customId = $hd['customId'];
|
|
|
- $custom = CustomClass::getById($customId, true);
|
|
|
- }
|
|
|
- }
|
|
|
$customId = intval($custom->id);
|
|
|
$groupBuyId = intval($form->groupBuyId);
|
|
|
$goodsNum = max(1, intval($form->goodsNum));
|
|
|
@@ -308,16 +269,13 @@ class GroupBuyController extends BaseController
|
|
|
|
|
|
/**
|
|
|
* 我的拼团列表
|
|
|
+ * 换店后可能仍带旧 hdId,先恢复门店并绑定当前店顾客再查列表
|
|
|
*/
|
|
|
public function actionMyList()
|
|
|
{
|
|
|
- $mainId = intval($this->mainId);
|
|
|
- $custom = $this->custom;
|
|
|
- if (empty($custom)) {
|
|
|
- util::fail('请先登录');
|
|
|
- }
|
|
|
+ $ctx = $this->ensureCustomerContext();
|
|
|
util::success([
|
|
|
- 'list' => GroupBuyClass::getMyList($mainId, intval($custom->id)),
|
|
|
+ 'list' => GroupBuyClass::getMyList($ctx['mainId'], intval($this->custom->id)),
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
@@ -348,6 +306,8 @@ class GroupBuyController extends BaseController
|
|
|
util::fail('请先登录');
|
|
|
}
|
|
|
$hd = $this->hd;
|
|
|
+ $hdId = !empty($hd) ? intval($hd->id ?? 0) : 0;
|
|
|
+ $hdName = !empty($hd) ? strval($hd->name ?? '') : '';
|
|
|
$user = $this->user;
|
|
|
$saleGoodsId = intval($row['goodsId']);
|
|
|
$goodsInfo = GoodsClass::getById($saleGoodsId, true);
|
|
|
@@ -489,8 +449,8 @@ class GroupBuyController extends BaseController
|
|
|
'customId' => intval($custom->id),
|
|
|
'customName' => strval($custom->name ?? ''),
|
|
|
'customNamePy' => stringUtil::py(strval($custom->name ?? '')),
|
|
|
- 'hdId' => intval($hd->id ?? 0),
|
|
|
- 'hdName' => strval($hd->name ?? ''),
|
|
|
+ 'hdId' => $hdId,
|
|
|
+ 'hdName' => $hdName,
|
|
|
'bookName' => strval($user->name ?? ''),
|
|
|
'bookMobile' => !empty($form->bookMobile) && stringUtil::isMobile($form->bookMobile)
|
|
|
? $form->bookMobile
|