|
|
@@ -1,14 +1,51 @@
|
|
|
/**
|
|
|
* 拼团(团购)相关 API
|
|
|
* 供团购详情页:落地信息、团详情、开团、参团、我的拼团
|
|
|
+ * 落地页/团详情登录态会建客并回传 hdId、inviteBound,需带上分享邀请人以便拉新
|
|
|
*/
|
|
|
import https from '@/plugins/luch-request_0.0.7/request'
|
|
|
+import { getShareInviterCustomId, clearShareInviter } from '@/utils/launchScene'
|
|
|
|
|
|
-/** 团购商品落地页:活动商品 + 当前开放团 */
|
|
|
-export const getGoodsLanding = data => https.get('/group-buy/goods-landing', data)
|
|
|
+/**
|
|
|
+ * 给团购浏览请求补上当前店的分享邀请人,并在拉新绑定成功后清缓存。
|
|
|
+ * 与 get-home / shop/info 同一套,保证分享直达团购页也能建客拉新。
|
|
|
+ * @param {Object} [data]
|
|
|
+ * @returns {{params: Object, account: string}}
|
|
|
+ */
|
|
|
+function withShareInviter(data) {
|
|
|
+ const params = Object.assign({}, data || {})
|
|
|
+ const account = uni.getStorageSync('account') || ''
|
|
|
+ const inviterCustomId = getShareInviterCustomId(account)
|
|
|
+ if (inviterCustomId > 0) {
|
|
|
+ params.inviterCustomId = inviterCustomId
|
|
|
+ }
|
|
|
+ return { params, account }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 后端 inviteBound=1 表示本次已用邀请人建客,清掉本地邀请缓存避免重复绑定
|
|
|
+ * @param {Object} res
|
|
|
+ * @param {string|number} account
|
|
|
+ * @returns {Object}
|
|
|
+ */
|
|
|
+function consumeInviteBound(res, account) {
|
|
|
+ if (res && res.code === 1 && res.data && Number(res.data.inviteBound) === 1) {
|
|
|
+ clearShareInviter(account)
|
|
|
+ }
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
+/** 团购商品落地页:活动商品 + 当前开放团;登录态回填 hdId 供页面缓存 */
|
|
|
+export const getGoodsLanding = data => {
|
|
|
+ const { params, account } = withShareInviter(data)
|
|
|
+ return https.get('/group-buy/goods-landing', params).then(res => consumeInviteBound(res, account))
|
|
|
+}
|
|
|
|
|
|
-/** 指定拼团详情(分享进入用 id=groupBuyId) */
|
|
|
-export const getGroupDetail = data => https.get('/group-buy/detail', data)
|
|
|
+/** 指定拼团详情(分享进入用 id=groupBuyId);登录态同样回填 hdId */
|
|
|
+export const getGroupDetail = data => {
|
|
|
+ const { params, account } = withShareInviter(data)
|
|
|
+ return https.get('/group-buy/detail', params).then(res => consumeInviteBound(res, account))
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
* 我要开团
|
|
|
@@ -16,7 +53,10 @@ export const getGroupDetail = data => https.get('/group-buy/detail', data)
|
|
|
* @param {Object} data 业务参数
|
|
|
* @param {Object} config 请求控制,如 hideError 由页面自行弹失败提示(须透传到 post,否则第二参会被丢掉)
|
|
|
*/
|
|
|
-export const createGroup = (data, config = {}) => https.post('/group-buy/create', data, {}, config)
|
|
|
+export const createGroup = (data, config = {}) => {
|
|
|
+ const { params } = withShareInviter(data)
|
|
|
+ return https.post('/group-buy/create', params, {}, config)
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
* 我要参团
|
|
|
@@ -24,7 +64,13 @@ export const createGroup = (data, config = {}) => https.post('/group-buy/create'
|
|
|
* @param {Object} data 业务参数
|
|
|
* @param {Object} config 请求控制,如 hideError 由页面自行弹失败提示
|
|
|
*/
|
|
|
-export const joinGroup = (data, config = {}) => https.post('/group-buy/join', data, {}, config)
|
|
|
+export const joinGroup = (data, config = {}) => {
|
|
|
+ const { params } = withShareInviter(data)
|
|
|
+ return https.post('/group-buy/join', params, {}, config)
|
|
|
+}
|
|
|
|
|
|
-/** 我的拼团列表 */
|
|
|
-export const getMyList = data => https.get('/group-buy/my-list', data)
|
|
|
+/** 我的拼团列表;换店后同样需要按 account 恢复顾客上下文 */
|
|
|
+export const getMyList = data => {
|
|
|
+ const { params } = withShareInviter(data)
|
|
|
+ return https.get('/group-buy/my-list', params)
|
|
|
+}
|