Эх сурвалжийг харах

零售端-登录绑定关系处理

ouyang 22 цаг өмнө
parent
commit
dc30e794e6

+ 35 - 0
mallApp/src/api/shop/index.js

@@ -17,6 +17,41 @@ export const getInfo = data => {
 	})
 }
 
+/**
+ * wangCg 登录成功后重拉 /shop/info,用于建客与分享拉新绑定
+ * 有邀请缓存时先清本地 hdId,否则 request 会拼上 hdId,后端不走 buildRelation
+ * @param {string|number} [account] 门店 account,默认取本地缓存
+ * @returns {Promise<Object|null>} shop/info 的 data,失败返回 null
+ */
+export function refreshShopInfoAfterLogin(account) {
+	const shopAccount = account || uni.getStorageSync('account') || ''
+	if (!shopAccount) {
+		return Promise.resolve(null)
+	}
+	uni.setStorageSync('account', shopAccount)
+	const inviterCustomId = getShareInviterCustomId(shopAccount)
+	if (inviterCustomId > 0) {
+		uni.removeStorageSync('hdId')
+	}
+	return getInfo({ account: shopAccount }).then((shopRes) => {
+		if (!shopRes || shopRes.code !== 1 || !shopRes.data) {
+			return null
+		}
+		const data = shopRes.data
+		if (data.info) {
+			uni.setStorageSync('currentShop', data.info)
+		}
+		const hd = data.hd
+		if (hd && (hd.id || hd.hdId)) {
+			const hdId = Number(hd.id || hd.hdId) || 0
+			if (hdId > 0) {
+				uni.setStorageSync('hdId', hdId)
+			}
+		}
+		return data
+	}).catch(() => null)
+}
+
 /** *
  * 门店列表 b
  */

+ 7 - 12
mallApp/src/components/home/bannerSwiper.vue

@@ -184,7 +184,7 @@ export default {
       return ((cached && cached.serviceWx) || '').trim()
     },
     /**
-     * 未登录则通知父页弹出 wangCg(与加购入口一致,不跳转登录页
+     * 未登录则通知父页弹出 wangCg(客服 / 加购等入口共用
      * @returns {boolean} true=已登录可继续
      */
     requireLogin() {
@@ -196,7 +196,7 @@ export default {
     },
     /**
      * 首页客服悬浮入口
-     * 未登录 → wangCg;已设置微信二维码 → 客服页;否则直达在线聊天
+     * 未登录 → 父页弹 wangCg;已登录 → 客服页 /pages/home/service
      */
     goChat() {
       if (!this.requireLogin()) {
@@ -204,18 +204,13 @@ export default {
       }
       const account = this.account || uni.getStorageSync('account') || ''
       const hdId = this.hdId || uni.getStorageSync('hdId') || ''
-      // 有二维码走客服页;无二维码跳过中间页,直达聊天
-      if (this.resolveServiceWx()) {
-        uni.navigateTo({
-          url: `/pages/home/service?account=${account}&hdId=${hdId}`
-        })
-        return
-      }
-      this.goChatPage()
+      uni.navigateTo({
+        url: `/pages/home/service?account=${account}&hdId=${hdId}`
+      })
     },
     /**
-     * 跳转在线咨询聊天页
-     * 参数与客服页 / 商品详情 goChat 保持一致(不含商品信息)
+     * 跳转在线咨询聊天页(客服页内部等场景复用)
+     * 参数与商品详情 goChat 保持一致(不含商品信息)
      */
     goChatPage() {
       if (!this.requireLogin()) {

+ 16 - 4
mallApp/src/pages/goods/detail.vue

@@ -178,7 +178,7 @@ import productMins from "@/mixins/cgProduct";
 import { mapGetters } from "vuex";
 import { getDetail } from "@/api/goods";
 import { getHdInfo } from "@/api/hd";
-import { getInfo } from "@/api/shop";
+import { getInfo, refreshShopInfoAfterLogin } from "@/api/shop";
 import { BUY_NOW_MIX_LIST_KEY } from "@/constant/storageKeys";
 import RichMediaViewer from "@/components/RichMediaViewer/index.vue";
 export default {
@@ -362,11 +362,23 @@ export default {
         query: { needBack: 1, account: this.account }
       });
     },
-    /** 登录成功后刷新门店客户与商品详情 */
+    /**
+     * 登录成功:重拉 shop/info 建客/拉新,再刷新商品详情
+     */
     loginSuccess() {
       this.globalLoginStyle = 1;
-      this.syncMyCustomId();
-      this.loadGoodsDetail();
+      refreshShopInfoAfterLogin(this.account).then((data) => {
+        if (data && data.custom && data.custom.id) {
+          this.myCustomId = Number(data.custom.id);
+        }
+        if (data && data.hd && (data.hd.id || data.hd.hdId)) {
+          const hdId = Number(data.hd.id || data.hd.hdId) || 0;
+          if (hdId > 0) {
+            this.hdId = hdId;
+          }
+        }
+        this.loadGoodsDetail();
+      });
     },
     /**
      * 购物车 / 咨询 / 加入购物车 / 购买前校验登录:未登录则弹出 wangCg

+ 18 - 4
mallApp/src/pages/groupBuy/detail.vue

@@ -153,7 +153,7 @@ import {
   joinGroup
 } from '@/api/group-buy'
 import { getHdInfo } from '@/api/hd'
-import { getInfo } from '@/api/shop'
+import { getInfo, refreshShopInfoAfterLogin } from '@/api/shop'
 import { GROUP_BUY_HD_NOT_BOUND } from '@/constant/errCode'
 
 export default {
@@ -282,12 +282,26 @@ export default {
       return n % 1 === 0 ? String(n) : n.toFixed(2)
     },
     /**
-     * wangCg 登录/注册成功回调
-     * 刷新详情数据(分享进页会回填 hdId,供开团/参团/支付使用)
+     * wangCg 登录/注册成功:先重拉 shop/info 建客/拉新,再刷新团购详情
      */
     loginSuccess() {
       this.globalLoginStyle = 1
-      this.init()
+      refreshShopInfoAfterLogin(this.account).then((data) => {
+        if (data && data.custom && data.custom.id) {
+          this.myCustomId = Number(data.custom.id)
+        }
+        if (data && data.hd && (data.hd.id || data.hd.hdId)) {
+          const hdId = Number(data.hd.id || data.hd.hdId) || 0
+          if (hdId > 0) {
+            uni.setStorageSync('hdId', hdId)
+            if (!this.option) {
+              this.option = {}
+            }
+            this.$set(this.option, 'hdId', hdId)
+          }
+        }
+        this.init()
+      })
     },
     init() {
       uni.showLoading({ title: '加载中', mask: true })

+ 16 - 2
mallApp/src/pages/home/index.vue

@@ -137,7 +137,7 @@ import wangCg from '@/components/wangCg'
 import { mapGetters } from 'vuex'
 import { getHome } from '@/api/home-page-config'
 import { getHdInfo } from '@/api/hd'
-import { getInfo } from '@/api/shop'
+import { getInfo, refreshShopInfoAfterLogin } from '@/api/shop'
 import { checkArrival } from '@/api/hb'
 
 /**
@@ -298,10 +298,24 @@ export default {
         query: { needBack: 1, account: this.account }
       })
     },
-    /** 加购登录成功:收起弹层并刷新购物车角标 */
+    /**
+     * 加购/客服等登录成功:收起弹层,并重拉 shop/info 建客/拉新绑定
+     */
     onCartLoginSuccess() {
       this.cartLoginStyle = 1
       this.refreshCartBadgeCount()
+      refreshShopInfoAfterLogin(this.account).then((data) => {
+        if (!data) {
+          return
+        }
+        if (data.custom && data.custom.id) {
+          this.myCustomId = Number(data.custom.id)
+        }
+        if (data.info) {
+          this.shopInfo = data.info
+        }
+        this.checkHbArrival()
+      })
     },
     /**
      * 页面初始化

+ 19 - 2
mallApp/src/pages/home/shop-category.vue

@@ -356,7 +356,7 @@ import { getClass, getList } from '@/api/category'
 import { getProductDataApi } from '@/api/item'
 import { getCategorySetting } from '@/api/category-setting'
 import { shopNoticeShowList } from '@/api/shop-notice'
-import { getInfo } from '@/api/shop'
+import { getInfo, refreshShopInfoAfterLogin } from '@/api/shop'
 import { getLimitBuyInfo } from '@/api/order'
 import { list, share } from '@/mixins'
 import { parseFilterIds, encodeFilterValue, stashGoodsListFilter } from '@/utils/goodsListFilter'
@@ -535,9 +535,26 @@ export default {
         query: { needBack: 1, account: this.shopAccount }
       })
     },
-    /** 登录成功后收起弹层 */
+    /**
+     * 登录成功:收起弹层,重拉 shop/info 建客/拉新,并回填本页 hdId
+     */
     onCartLoginSuccess() {
       this.cartLoginStyle = 1
+      refreshShopInfoAfterLogin(this.shopAccount).then((data) => {
+        if (!data) {
+          return
+        }
+        if (data.custom && data.custom.id) {
+          this.myCustomId = Number(data.custom.id)
+        }
+        const hd = data.hd
+        if (hd && (hd.id || hd.hdId)) {
+          const hdId = Number(hd.id || hd.hdId) || 0
+          if (hdId > 0) {
+            this.hdId = hdId
+          }
+        }
+      })
     },
     /** 花材加购:未登录先弹登录层 */
     onItemAdd(info) {

+ 75 - 36
mallApp/src/pages/item/detail.vue

@@ -57,9 +57,16 @@
       @goShop="goShopIndex"
       @goCart="goCartPage"
     />
+    <!-- 按需弹出:仅购物车/加购/购买触发,浏览详情默认不弹 -->
+    <wangCg :loginStyle.sync="globalLoginStyle" @goToLogin="loginTo" @loginSuccess="loginSuccess" />
   </view>
 </template>
 <script>
+/**
+ * 花材详情:游客可浏览 get-mall-item-info;
+ * 点「我的购物车 / 加入购物车 / 立即购买」再弹 wangCg;
+ * 登录成功后 refreshShopInfoAfterLogin,新客走 shop/info 建客并绑定邀请关系。
+ */
 import AppImg from "@/components/app-img";
 import AppSwiper from "@/components/app-swiper";
 import AppTag from "@/components/module/app-tag.vue";
@@ -67,10 +74,11 @@ import AppTrademark from "@/components/module/app-trademark";
 import RichMediaViewer from "@/components/RichMediaViewer/index.vue";
 import BuyFoot from "./components/buy-foot.vue";
 import SelPopup from "./components/sel-popup.vue";
+import wangCg from "@/components/wangCg";
 import { mapGetters } from "vuex";
 import { getMallItemInfo } from "@/api/item";
 import { getHdInfo } from "@/api/hd";
-import { getInfo } from "@/api/shop";
+import { getInfo, refreshShopInfoAfterLogin } from "@/api/shop";
 import productMins from "@/mixins/cgProduct";
 import { share } from "@/mixins";
 export default {
@@ -83,7 +91,8 @@ export default {
     BuyFoot,
     SelPopup,
     AppImg,
-    RichMediaViewer
+    RichMediaViewer,
+    wangCg
   },
   data() {
     return {
@@ -97,26 +106,22 @@ export default {
 			pageType: "cg",
       autoLoad:false,
       hdId:0,
+      account: 0,
       /** 分享 path 追加 inviterCustomId 用,不改变进入页 query(除 hdId) */
       myCustomId: 0,
-      previewContent: []
+      previewContent: [],
+      /** wangCg:1=隐藏,0=显示;覆盖全局 mixin 默认 0,避免进页即弹 */
+      globalLoginStyle: 1
     };
   },
 	watch: {
-		loginInfo(newVal) {
-      if(!this.$util.isEmpty(newVal)){
-        this.globalLoginStyle = 1
-      }else{
-        this.globalLoginStyle = 0
-      }
+		loginInfo() {
+      // 已登录则收起弹层;未登录不主动弹出(由 ensureLogin 触发)
+      this.syncLoginStyle()
 		}
 	},
   onShow () {
-      if(!this.$util.isEmpty(this.loginInfo)){
-        this.globalLoginStyle = 1
-      }else{
-        this.globalLoginStyle = 0
-      }
+      this.syncLoginStyle()
   },
   onShareAppMessage() {
     const path = this.buildItemSharePath()
@@ -135,8 +140,57 @@ export default {
     ...mapGetters({ shopUser: "getShopUser",loginInfo:"getLoginInfo" })
   },
   methods: {
+    /**
+     * 同步 wangCg:仅在已登录时强制关闭;未登录保持现状(由操作入口 ensureLogin 弹出)
+     */
+    syncLoginStyle() {
+      if (!this.$util.isEmpty(this.loginInfo)) {
+        this.globalLoginStyle = 1
+      }
+    },
+    loginTo() {
+      const account = this.account || (this.option && this.option.account) || uni.getStorageSync('account') || ''
+      this.$util.pageTo({
+        url: '/pages/login/index',
+        query: { needBack: 1, account }
+      })
+    },
+    /**
+     * wangCg 登录成功:重拉 shop/info 建客/拉新绑定,再刷新花材详情
+     */
+    loginSuccess() {
+      this.globalLoginStyle = 1
+      const account = this.account || (this.option && this.option.account) || uni.getStorageSync('account') || ''
+      refreshShopInfoAfterLogin(account).then((data) => {
+        if (data && data.custom && data.custom.id) {
+          this.myCustomId = Number(data.custom.id)
+        }
+        if (data && data.hd && (data.hd.id || data.hd.hdId)) {
+          const hdId = Number(data.hd.id || data.hd.hdId) || 0
+          if (hdId > 0) {
+            this.hdId = hdId
+          }
+        }
+        const id = (this.option && this.option.id) || (this.data && this.data.id) || 0
+        if (id) {
+          this.getItemDetail(id, account)
+        }
+      })
+    },
+    /**
+     * 我的购物车 / 加入购物车 / 立即购买前校验:未登录弹 wangCg
+     * @returns {boolean}
+     */
+    ensureLogin() {
+      if (!this.$util.isEmpty(this.loginInfo)) {
+        this.globalLoginStyle = 1
+        return true
+      }
+      this.globalLoginStyle = 0
+      return false
+    },
     getAffirmUrl() {
-      const account = this.option.account || ''
+      const account = this.account || (this.option && this.option.account) || ''
       return `/pages/billing/affirmMix?account=${account}&hdId=${this.hdId}`
     },
     onPopupConfirm(num) {
@@ -160,10 +214,11 @@ export default {
       }
     },
     goShopIndex() {
-      this.$util.pageTo({ url: `/pages/item/item?account=${this.option.account}&hdId=${this.hdId}`, type: 2 })
+      const account = this.account || (this.option && this.option.account) || ''
+      this.$util.pageTo({ url: `/pages/item/item?account=${account}&hdId=${this.hdId}`, type: 2 })
     },
     goCartPage() {
-      if (!this.checkLogin()) {
+      if (!this.ensureLogin()) {
         return
       }
       this.$util.pageTo({ url: this.getAffirmUrl(), type: 2 })
@@ -177,6 +232,7 @@ export default {
 
       const id = this.option.id ? this.option.id : 0
       const account = this.option.account ? this.option.account : 0
+      this.account = account
 
       // 太阳码参数已在 App / globalMixins 中展开为 account、id
       if (Number(id) > 0 && Number(account) > 0) {
@@ -285,25 +341,8 @@ export default {
     changeNum(e) {
       this.buyNum = e.value;
     },
-    checkLogin() {
-      if (this.globalLoginStyle == 0) {
-        const that = this
-        uni.showModal({
-          title: '提示',
-          content: '请先注册登录哦',
-          confirmText: '好的',
-          success(res) {
-            if (res.confirm) {
-              that.pageTo({ url: '/pages/login/index', type: 2 })
-            }
-          }
-        })
-        return false
-      }
-      return true
-    },
     openCartPopup() {
-      if (!this.checkLogin()) {
+      if (!this.ensureLogin()) {
         return
       }
       if (!this.data || !this.data.id) {
@@ -319,7 +358,7 @@ export default {
       this.popupShow = true
     },
     openBuyPopup() {
-      if (!this.checkLogin()) {
+      if (!this.ensureLogin()) {
         return
       }
       if (!this.data || !this.data.id) {