优化打开团购券分享时用户已登录&未登录,店铺已注册&未注册逻辑处理

This commit is contained in:
Waiting 2024-06-14 02:21:35 +08:00
parent 6921c82ad3
commit f83bf3dd98
15 changed files with 175 additions and 53 deletions

View File

@ -1,6 +1,7 @@
<script lang='ts'> <script lang='ts'>
import { import {
getCompanyId, getQueryParam, getCompanyId,
getQueryParam,
getRegisterStoreId, getRegisterStoreId,
mpUpdate, mpUpdate,
setCompanyId, setCompanyId,
@ -120,8 +121,9 @@ export default {
logger: logger, logger: logger,
companyId: getCompanyId(), companyId: getCompanyId(),
storeId: getRegisterStoreId(), storeId: getRegisterStoreId(),
shareCompanyId: '', shareCompanyId: '',//id
shareStoreId: '' shareStoreId: '',//id
sharePath: ''//便
} }
}; };

View File

@ -36,7 +36,7 @@
{ {
"path": "pages/index/index", "path": "pages/index/index",
"style": { "style": {
"navigationBarTitleText": "肃客会员" "navigationBarTitleText": "VIP顾客中心"
} }
}, },
{ {

View File

@ -142,7 +142,7 @@
<script lang='ts' setup> <script lang='ts' setup>
import { assetsUrl, defaultImage } from '@/utils/assets'; import { assetsUrl, defaultImage } from '@/utils/assets';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { formatTimeWithZeroPad, goPath, isLogin } from '@/utils'; import { formatTimeWithZeroPad, getCompanyId, getOpenId, goLogin, goPath, isLogin } from '@/utils';
import SkuDialog from '@/components/sku-dialog.vue'; import SkuDialog from '@/components/sku-dialog.vue';
import CouponItem from './components/coupon-item.vue'; import CouponItem from './components/coupon-item.vue';
@ -157,7 +157,7 @@ import { getGoodsList } from '@/api/goods';
import { GoodsBean } from '@/api/goods/types'; import { GoodsBean } from '@/api/goods/types';
import { useUserStore } from '@/store'; import { useUserStore } from '@/store';
import { GroupBuyBean, RecordBean } from '@/api/groupbuy/types'; import { GroupBuyBean, RecordBean } from '@/api/groupbuy/types';
import { getStoreId } from '@/api/company'; import { getCompanyList } from '@/api/company';
const userStore = useUserStore(); const userStore = useUserStore();
const { userInfo } = storeToRefs(userStore); const { userInfo } = storeToRefs(userStore);
@ -197,6 +197,29 @@ onLoad(async (e: any) => {
groupBuyBean.value.price = groupBuyBean.value?.offsetPrice; groupBuyBean.value.price = groupBuyBean.value?.offsetPrice;
bannerList.value = groupBuyBean.value?.image?.split(','); bannerList.value = groupBuyBean.value?.image?.split(',');
} }
const maOpenId = getOpenId() || userInfo.value?.maOpenId;
const data = await getCompanyList(maOpenId);
const companyList = data.map((item: any) => item.company);
let index = companyList.findIndex((res: {
id: string
}) => res.id === (getApp()?.globalData?.shareCompanyId || getCompanyId()));
if(index < 0) {
uni.showModal({
title: '提示',
content: '当前店铺还未注册,请先注册',
showCancel: true,
success: (res) => {
if(res.confirm) {
goPath('/pages/common/register/index');
} else {
goPath('/pages/home/index');
}
}
});
return;
}
// setCompanyId('1512403904150138881'); // setCompanyId('1512403904150138881');
// groupBuyBean.value = await getGroupBuyDetail('1740922051118063618'); // groupBuyBean.value = await getGroupBuyDetail('1740922051118063618');
if(groupBuyBean.value) { if(groupBuyBean.value) {
@ -210,7 +233,7 @@ onLoad(async (e: any) => {
} }
uni.hideLoading(); uni.hideLoading();
} else { } else {
goPath('/pages/common/login/index'); goLogin(true);
} }
}); });

View File

@ -56,8 +56,12 @@ const { terminalInfo } = storeToRefs(userState);
const orderBean = ref<OrderBean>(); const orderBean = ref<OrderBean>();
onLoad((e: any) => { onLoad(async (e: any) => {
orderBean.value = JSON.parse(decodeURIComponent(e?.orderBean)); orderBean.value = JSON.parse(decodeURIComponent(e?.orderBean));
await userState.fetchTerminal();
if(!terminalInfo.value) {
showToast('当前店铺未配置收款渠道,请联系商家');
}
}); });
const buildSqbParams = computed(() => { const buildSqbParams = computed(() => {
@ -65,10 +69,10 @@ const buildSqbParams = computed(() => {
client_sn: orderBean.value?.id || '', client_sn: orderBean.value?.id || '',
return_url: '/pages/common/payresult/index', return_url: '/pages/common/payresult/index',
total_amount: Number(((orderBean.value?.totalPrice || 0) * 100).toFixed(2)), total_amount: Number(((orderBean.value?.totalPrice || 0) * 100).toFixed(2)),
terminal_sn: terminalInfo.value.terminalSn, terminal_sn: terminalInfo.value?.terminalSn,
subject: '商品团购券', subject: orderBean?.value?.orderGoods[0]?.goodsName || '商品团购券',
subject_img: orderBean?.value?.orderGoods[0].images || '', subject_img: orderBean?.value?.orderGoods[0]?.images || 'xxx',
merchant_name: terminalInfo.value.companyName, merchant_name: terminalInfo.value?.companyName,
notify_url: 'https://www.baidu.com' notify_url: 'https://www.baidu.com'
}, true); }, true);
@ -80,7 +84,7 @@ const buildSqbParams = computed(() => {
const navigateTo = (e: any) => { const navigateTo = (e: any) => {
handlePayResult(orderBean.value?.id, e, { handlePayResult(orderBean.value?.id, e, {
onSuccess: (options:any) => { onSuccess: (options: any) => {
showToast('支付成功', { showToast('支付成功', {
icon: 'success', icon: 'success',
complete: () => { complete: () => {
@ -98,6 +102,10 @@ const navigateTo = (e: any) => {
}; };
const payment = () => { const payment = () => {
if(!terminalInfo.value) {
showToast('当前店铺未配置收款渠道,请联系商家');
return;
}
const params = { const params = {
'id': orderBean.value?.id, 'id': orderBean.value?.id,
'orderSn': buildSqbParams.value.client_sn, 'orderSn': buildSqbParams.value.client_sn,

View File

@ -66,19 +66,13 @@ const imageList = ref([]);
const orderBean = ref<OrderBean>(); const orderBean = ref<OrderBean>();
const goodsCount = ref(1); const goodsCount = ref(1);
onLoad((e: any) => { onLoad(async (e: any) => {
getApp().globalData?.logger?.info('order-coupon-confirm ', e);
try { try {
groupBuyBean.value = JSON.parse(decodeURIComponent(e?.bean)); groupBuyBean.value = JSON.parse(decodeURIComponent(e?.bean));
getApp().globalData?.logger?.info('order-coupon-confirm: groupBuyBean', groupBuyBean.value);
if(groupBuyBean.value) { if(groupBuyBean.value) {
imageList.value = groupBuyBean.value?.image?.split(','); imageList.value = groupBuyBean.value?.image?.split(',');
getApp().globalData?.logger?.info('order-coupon-confirm: imageList', imageList.value);
} }
await userState.fetchTerminal(groupBuyBean.value?.companyId || '');
getApp().globalData?.logger?.info('order-coupon-confirm: userInfo', userInfo.value);
getApp().globalData?.logger?.info('order-coupon-confirm: terminalInfo', terminalInfo.value);
createOrder(); createOrder();
} catch (e) { } catch (e) {
getApp().globalData?.logger?.error('order-coupon-confirm: exception ', e); getApp().globalData?.logger?.error('order-coupon-confirm: exception ', e);
@ -110,15 +104,18 @@ const buildSqbParams = computed(() => {
total_amount: Number(((totalPrice.value || 0) * 100).toFixed(2)), total_amount: Number(((totalPrice.value || 0) * 100).toFixed(2)),
terminal_sn: terminalInfo.value?.terminalSn, terminal_sn: terminalInfo.value?.terminalSn,
subject: groupBuyBean.value?.name || '商品团购券', subject: groupBuyBean.value?.name || '商品团购券',
subject_img: (imageList.value?.length > 0 && imageList.value[0]) || '', subject_img: (imageList.value?.length > 0 && imageList.value[0]) || 'xxx',
merchant_name: terminalInfo.value?.companyName, merchant_name: terminalInfo.value?.companyName,
notify_url: 'https://www.baidu.com' notify_url: 'https://www.baidu.com'
}, true); }, true);
return { getApp().globalData?.logger?.info('order-coupon-confirm: buildSqbParams before sign: ', params);
const paramsSign = {
...params, ...params,
sign: hexMD5(parseParameter(params) + '&key=' + terminalInfo.value?.terminalKey).toUpperCase() sign: hexMD5(parseParameter(params) + '&key=' + terminalInfo.value?.terminalKey).toUpperCase()
}; };
getApp().globalData?.logger?.info('order-coupon-confirm: buildSqbParams after sign: ', paramsSign);
return paramsSign;
}); });
const navigateTo = (e: any) => { const navigateTo = (e: any) => {
@ -138,11 +135,24 @@ const navigateTo = (e: any) => {
uni.navigateBack(); uni.navigateBack();
} }
}); });
},
onFailure: (e: any) => {
getApp().globalData?.logger?.error('coupon pay failure params: ', buildSqbParams.value, e);
showToast('支付失败', {
icon: 'none',
complete: () => {
uni.navigateBack();
}
});
} }
}); });
}; };
const createOrder = () => { const createOrder = () => {
if(!terminalInfo.value) {
utils_common_index.showToast('当前店铺未配置收款渠道,请联系商家');
return;
}
const params = { const params = {
id: groupBuyBean.value?.id, id: groupBuyBean.value?.id,
cash: totalPrice.value, cash: totalPrice.value,

View File

@ -24,11 +24,13 @@
</template> </template>
<script setup lang='ts'> <script setup lang='ts'>
import { getCompanyList } from '@/api/company';
import { useUserStore } from '@/store'; import { useUserStore } from '@/store';
import { assetsUrl } from '@/utils/assets'; import { assetsUrl } from '@/utils/assets';
import { showToast } from '@/utils'; import { getCompanyId, getOpenId, goPath, showToast } from '@/utils';
const userStore = useUserStore(); const userStore = useUserStore();
const { userInfo } = storeToRefs(userStore);
const isAgreePrivacy = ref(false); const isAgreePrivacy = ref(false);
function wechatLogin() { function wechatLogin() {
@ -38,9 +40,41 @@ function wechatLogin() {
} }
uni.showLoading(); uni.showLoading();
userStore.login().then(() => { userStore.login().then(async () => {
const maOpenId = getOpenId() || userInfo.value?.maOpenId;
const data = await getCompanyList(maOpenId);
const companyList = data.map((item: any) => item.company);
uni.hideLoading(); uni.hideLoading();
uni.reLaunch({ url: '/pages/home/index' });
//
let index = companyList.findIndex((res: {
id: string
}) => res.id === (getApp()?.globalData?.shareCompanyId || getCompanyId()));
if(index < 0) {
uni.showModal({
title: '提示',
content: '当前店铺还未注册,请先注册',
showCancel: true,
success: (res) => {
if(res.confirm) {
goPath('/pages/common/register/index');
} else {
goPath('/pages/home/index');
}
}
});
return;
}
if(getApp()?.globalData && getApp()?.globalData?.sharePath) {
uni.reLaunch({
url: getApp()?.globalData?.sharePath,
onSuccess: () => {
getApp().globalData!.sharePath = '';
}
});
} else {
uni.reLaunch({ url: '/pages/home/index' });
}
}); });
} }

View File

@ -129,9 +129,18 @@ const save = async () => {
getApp().globalData?.logger.info('register params: ', registerForm); getApp().globalData?.logger.info('register params: ', registerForm);
if(result) { if(result) {
showToast('注册成功'); showToast('注册成功');
await uni.reLaunch({ if(getApp()?.globalData && getApp()?.globalData?.sharePath) {
url: '/pages/home/index' uni.reLaunch({
}); url: getApp()?.globalData?.sharePath,
onSuccess: () => {
getApp().globalData!.sharePath = '';
}
});
} else {
await uni.reLaunch({
url: '/pages/home/index'
});
}
} }
uni.hideLoading(); uni.hideLoading();
}; };

View File

@ -5,18 +5,26 @@
<script lang='ts' setup> <script lang='ts' setup>
import { getStoreId } from '@/api/company'; import { getStoreId } from '@/api/company';
import { isLogin, setCompanyId, setRegisterStoreId } from '@/utils';
onLoad(async (options) => { onLoad(async (options) => {
getApp().globalData?.logger?.info('ticketsBuy share options: ', options); getApp().globalData?.logger?.info('ticketsBuy share options: ', options);
let couponId = options?.couponsId; let couponId = options?.couponsId;
if(couponId) { if(couponId) {
const path = `/pages/common/groupbuy/detail?couponId=${couponId}`;
if(!isLogin() && getApp()?.globalData) {
getApp().globalData!.sharePath = path;
}
if(options?.companyId && options?.creatorId) { if(options?.companyId && options?.creatorId) {
const storeId = await getStoreId({ const storeId = await getStoreId({
companyid: options?.companyId, companyid: options?.companyId,
deviceid: options?.creatorId deviceid: options?.creatorId
}); });
setCompanyId(options?.companyId);
if(storeId) { if(storeId) {
// setRegisterStoreId(storeId); setRegisterStoreId(storeId);
if(getApp()?.globalData) { if(getApp()?.globalData) {
getApp().globalData!.shareCompanyId = options?.companyId; getApp().globalData!.shareCompanyId = options?.companyId;
getApp().globalData!.shareStoreId = storeId; getApp().globalData!.shareStoreId = storeId;
@ -26,7 +34,7 @@ onLoad(async (options) => {
setTimeout(() => { setTimeout(() => {
uni.reLaunch({ uni.reLaunch({
url: `/pages/common/groupbuy/detail?couponId=${couponId}` url: path
}); });
}, 300); }, 300);
} else { } else {

View File

@ -185,6 +185,7 @@ const fetchCompanyList = (fn: any = undefined) => {
showRegisterModal(); showRegisterModal();
return; return;
} }
if(fn != undefined && fn instanceof Function) { if(fn != undefined && fn instanceof Function) {
fn(companyList.value, userList.value); fn(companyList.value, userList.value);
} else { } else {
@ -209,8 +210,7 @@ const fetchCompanyList = (fn: any = undefined) => {
avatarModifyRemind(); avatarModifyRemind();
} }
} }
) );
;
}; };
const showRegisterModal = () => { const showRegisterModal = () => {

View File

@ -4,12 +4,27 @@
<script lang='ts' setup> <script lang='ts' setup>
onLoad((options) => { import { isLogin, setCompanyId, setRegisterStoreId } from '@/utils';
import { getStoreId } from '@/api/company';
onLoad(async (options) => {
getApp().globalData?.logger?.info('app share index/index options: ', options); getApp().globalData?.logger?.info('app share index/index options: ', options);
if(options?.companyId && options?.storeId && getApp()?.globalData) { if(options?.companyId) {
getApp().globalData!.shareCompanyId = options?.companyId; setCompanyId(options?.companyId);
getApp().globalData!.shareStoreId = options?.storeId; let storeId = options?.storeId || await getStoreId({
companyid: options?.companyId,
deviceid: options?.creatorId
});
if(storeId) {
setRegisterStoreId(storeId);
}
if(getApp()?.globalData) {
getApp().globalData!.shareCompanyId = options?.companyId;
getApp().globalData!.shareStoreId = storeId;
}
} }
let goodsShareId = ''; let goodsShareId = '';
@ -19,9 +34,13 @@ onLoad((options) => {
getApp().globalData?.logger?.info('app share index/index options: goodsShareId ', goodsShareId); getApp().globalData?.logger?.info('app share index/index options: goodsShareId ', goodsShareId);
if(goodsShareId) { if(goodsShareId) {
const path = `/pages/common/groupbuy/detail?shareId=${goodsShareId}`;
if(!isLogin() && getApp()?.globalData) {
getApp().globalData!.sharePath = path;
}
setTimeout(() => { setTimeout(() => {
uni.reLaunch({ uni.reLaunch({
url: `/pages/common/groupbuy/detail?shareId=${goodsShareId}` url: path
}); });
}, 300); }, 300);
} else { } else {

View File

@ -1,6 +1,6 @@
{ {
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "肃客会员", "projectname": "VIP顾客中心",
"setting": { "setting": {
"compileHotReLoad": true "compileHotReLoad": true
} }

View File

@ -155,11 +155,11 @@ const useUserStore = defineStore('user', {
if(getApp().globalData) { if(getApp().globalData) {
getApp().globalData!.companyId = this.userInfo.companyId; getApp().globalData!.companyId = this.userInfo.companyId;
} }
this.fetchTerminal(this.userInfo?.companyId);
this.fetchCompanyInfo();
} else { } else {
await clearToken(); await clearToken();
} }
this.fetchTerminal();
this.fetchCompanyInfo();
}, },
setCompanyInfo(partial: Partial<any>) { setCompanyInfo(partial: Partial<any>) {
@ -183,8 +183,8 @@ const useUserStore = defineStore('user', {
this.companyConfigInfo = await getCompanyInfo(); this.companyConfigInfo = await getCompanyInfo();
}, },
async fetchTerminal() { async fetchTerminal(companyId: string = '') {
this.terminalInfo = await getTerminal(this.userInfo?.companyId); this.terminalInfo = await getTerminal(companyId || this.userInfo.companyId);
}, },
// 重置用户信息 // 重置用户信息

View File

@ -79,11 +79,17 @@ export function goPath(path: string, needAuth: boolean = false) {
} }
} }
export function goLogin() { export function goLogin(reLaunch: boolean = false) {
uni.navigateTo({ const path = '/pages/common/login/index';
url: '/pages/common/login/index' if(reLaunch) {
}).then(r => { uni.reLaunch({
}); url: path
}).then();
} else {
uni.navigateTo({
url: path
}).then();
}
} }
export function formatTimeWithZeroPad(num: number): string { export function formatTimeWithZeroPad(num: number): string {

View File

@ -33,8 +33,8 @@ export const handlePayResult = (orderId: string | undefined, e: any, { onSuccess
const str = url.split('?')[1]; const str = url.split('?')[1];
const resultObj = JSON.parse(str.replaceAll('result=', '')); const resultObj = JSON.parse(str.replaceAll('result=', ''));
getApp().globalData?.logger?.info('pay reuslt : ', orderId, resultObj);
if(resultObj?.is_success === true) { if(resultObj?.is_success === true) {
getApp().globalData?.logger?.info('pay success : ', orderId, resultObj);
if(onSuccess) { if(onSuccess) {
onSuccess(resultObj); onSuccess(resultObj);
} else { } else {
@ -46,9 +46,9 @@ export const handlePayResult = (orderId: string | undefined, e: any, { onSuccess
}); });
} }
} else { } else {
getApp().globalData?.logger?.error('pay failure :', resultObj); getApp().globalData?.logger?.error('pay failure :', orderId, resultObj);
if(onFailure) { if(onFailure) {
onFailure(); onFailure(resultObj);
} else { } else {
const msg = resultObj?.error_message || '支付失败'; const msg = resultObj?.error_message || '支付失败';
showToast(msg, { showToast(msg, {

View File

@ -26,7 +26,7 @@ function requestInterceptors() {
// config.header.contentType = "x-www-form-urlencoded" // config.header.contentType = "x-www-form-urlencoded"
} }
getApp().globalData?.logger.info('request: ', config); // getApp().globalData?.logger.info('request: ', config);
return config; return config;
}, },
( (
@ -53,7 +53,10 @@ function responseInterceptors() {
return data; return data;
} }
getApp().globalData?.logger.info('response: ', data); getApp().globalData?.logger.info(response.config.url, {
'request': response.config,
'response': data
});
// 请求成功则返回结果 // 请求成功则返回结果
if(data.code === 200 || data?.retcode == 0) { if(data.code === 200 || data?.retcode == 0) {