|
|
@@ -7,6 +7,7 @@ use common\components\util;
|
|
|
use bizHd\hb\classes\HbClass;
|
|
|
use bizHd\hb\classes\HbManageClass;
|
|
|
use bizHd\hb\classes\HbScopeClass;
|
|
|
+use bizMall\hd\classes\HdClass;
|
|
|
|
|
|
class HbController extends BaseController
|
|
|
{
|
|
|
@@ -14,6 +15,7 @@ class HbController extends BaseController
|
|
|
* 我的红包列表
|
|
|
* 返回分页列表,并附带各状态数量供顶部 Tab 展示:
|
|
|
* all 全部、unUse 未使用、used 已使用、expired 已过期
|
|
|
+ * 每条红包额外附带 hdId(xhHd.id),供「去使用」跳转对应店铺商品列表。
|
|
|
*/
|
|
|
public function actionList()
|
|
|
{
|
|
|
@@ -36,12 +38,16 @@ class HbController extends BaseController
|
|
|
if (!empty($respond['list'])) {
|
|
|
$hbIds = array_column($respond['list'], 'id');
|
|
|
$scopeMap = HbScopeClass::getMapByHbIds($hbIds);
|
|
|
+ // 按 shopId 批量查当前用户在该店的 xhHd.id,避免跨店跳转商品列表时缺少门店上下文
|
|
|
+ $shopHdMap = $this->buildShopHdMap(array_column($respond['list'], 'shopId'));
|
|
|
foreach ($respond['list'] as &$v) {
|
|
|
$v['customName'] = $v['custom']['name'] ?? '';
|
|
|
$v = HbScopeClass::attachScopeToHb($v, $scopeMap);
|
|
|
$v['specialApplicableText'] = ((int)$v['specialApplicable'] === 1)
|
|
|
? '特价及活动商品适用'
|
|
|
: '特价及活动商品不适用';
|
|
|
+ $shopId = (int)($v['shopId'] ?? 0);
|
|
|
+ $v['hdId'] = $shopHdMap[$shopId] ?? 0;
|
|
|
if ($v['status'] == 0 && $v['endTime'] < time()) {
|
|
|
//发现红包已过期,需要作废,多有处作废操作,搜索关键词 cancellation_hb
|
|
|
$id = $v['id'];
|
|
|
@@ -52,11 +58,44 @@ class HbController extends BaseController
|
|
|
$respond['expired']++;
|
|
|
}
|
|
|
}
|
|
|
+ unset($v);
|
|
|
}
|
|
|
|
|
|
util::success($respond);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 按 shopId 批量解析当前用户的花店客户关系 id(xhHd.id)。
|
|
|
+ * 「去使用」跳转商品列表必须带 hdId,否则商城接口无法正确绑定客户价与购物车店铺维度。
|
|
|
+ *
|
|
|
+ * @param array $shopIds 红包所属门店 id 列表
|
|
|
+ * @return array shopId => hdId
|
|
|
+ */
|
|
|
+ private function buildShopHdMap($shopIds)
|
|
|
+ {
|
|
|
+ $shopIds = array_values(array_unique(array_filter(array_map('intval', $shopIds ?: []))));
|
|
|
+ if (empty($shopIds) || $this->userId <= 0) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $hdList = HdClass::getAllByCondition(
|
|
|
+ [
|
|
|
+ 'userId' => $this->userId,
|
|
|
+ 'shopId' => ['in', $shopIds],
|
|
|
+ 'delStatus' => 0,
|
|
|
+ ],
|
|
|
+ null,
|
|
|
+ 'id,shopId'
|
|
|
+ );
|
|
|
+ $map = [];
|
|
|
+ foreach ($hdList ?: [] as $hd) {
|
|
|
+ $sid = (int)($hd['shopId'] ?? 0);
|
|
|
+ if ($sid > 0 && !isset($map[$sid])) {
|
|
|
+ $map[$sid] = (int)$hd['id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $map;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 某门店下所有可用红包(附带适用范围)
|
|
|
*/
|