优化打开团购券分享时用户已登录&未登录,店铺已注册&未注册逻辑处理
This commit is contained in:
parent
6921c82ad3
commit
f83bf3dd98
@ -1,6 +1,7 @@
|
||||
<script lang='ts'>
|
||||
import {
|
||||
getCompanyId, getQueryParam,
|
||||
getCompanyId,
|
||||
getQueryParam,
|
||||
getRegisterStoreId,
|
||||
mpUpdate,
|
||||
setCompanyId,
|
||||
@ -120,8 +121,9 @@ export default {
|
||||
logger: logger,
|
||||
companyId: getCompanyId(),
|
||||
storeId: getRegisterStoreId(),
|
||||
shareCompanyId: '',
|
||||
shareStoreId: ''
|
||||
shareCompanyId: '',//分享过来的公司id
|
||||
shareStoreId: '',//分享过来的店铺id
|
||||
sharePath: ''//分享页面路径,方便登录后跳转
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
{
|
||||
"path": "pages/index/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "肃客会员"
|
||||
"navigationBarTitleText": "VIP顾客中心"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -142,7 +142,7 @@
|
||||
<script lang='ts' setup>
|
||||
import { assetsUrl, defaultImage } from '@/utils/assets';
|
||||
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 CouponItem from './components/coupon-item.vue';
|
||||
|
||||
@ -157,7 +157,7 @@ import { getGoodsList } from '@/api/goods';
|
||||
import { GoodsBean } from '@/api/goods/types';
|
||||
import { useUserStore } from '@/store';
|
||||
import { GroupBuyBean, RecordBean } from '@/api/groupbuy/types';
|
||||
import { getStoreId } from '@/api/company';
|
||||
import { getCompanyList } from '@/api/company';
|
||||
|
||||
const userStore = useUserStore();
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
@ -197,6 +197,29 @@ onLoad(async (e: any) => {
|
||||
groupBuyBean.value.price = groupBuyBean.value?.offsetPrice;
|
||||
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');
|
||||
// groupBuyBean.value = await getGroupBuyDetail('1740922051118063618');
|
||||
if(groupBuyBean.value) {
|
||||
@ -210,7 +233,7 @@ onLoad(async (e: any) => {
|
||||
}
|
||||
uni.hideLoading();
|
||||
} else {
|
||||
goPath('/pages/common/login/index');
|
||||
goLogin(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -56,8 +56,12 @@ const { terminalInfo } = storeToRefs(userState);
|
||||
|
||||
const orderBean = ref<OrderBean>();
|
||||
|
||||
onLoad((e: any) => {
|
||||
onLoad(async (e: any) => {
|
||||
orderBean.value = JSON.parse(decodeURIComponent(e?.orderBean));
|
||||
await userState.fetchTerminal();
|
||||
if(!terminalInfo.value) {
|
||||
showToast('当前店铺未配置收款渠道,请联系商家');
|
||||
}
|
||||
});
|
||||
|
||||
const buildSqbParams = computed(() => {
|
||||
@ -65,10 +69,10 @@ const buildSqbParams = computed(() => {
|
||||
client_sn: orderBean.value?.id || '',
|
||||
return_url: '/pages/common/payresult/index',
|
||||
total_amount: Number(((orderBean.value?.totalPrice || 0) * 100).toFixed(2)),
|
||||
terminal_sn: terminalInfo.value.terminalSn,
|
||||
subject: '商品团购券',
|
||||
subject_img: orderBean?.value?.orderGoods[0].images || '',
|
||||
merchant_name: terminalInfo.value.companyName,
|
||||
terminal_sn: terminalInfo.value?.terminalSn,
|
||||
subject: orderBean?.value?.orderGoods[0]?.goodsName || '商品团购券',
|
||||
subject_img: orderBean?.value?.orderGoods[0]?.images || 'xxx',
|
||||
merchant_name: terminalInfo.value?.companyName,
|
||||
notify_url: 'https://www.baidu.com'
|
||||
}, true);
|
||||
|
||||
@ -98,6 +102,10 @@ const navigateTo = (e: any) => {
|
||||
};
|
||||
|
||||
const payment = () => {
|
||||
if(!terminalInfo.value) {
|
||||
showToast('当前店铺未配置收款渠道,请联系商家');
|
||||
return;
|
||||
}
|
||||
const params = {
|
||||
'id': orderBean.value?.id,
|
||||
'orderSn': buildSqbParams.value.client_sn,
|
||||
|
@ -66,19 +66,13 @@ const imageList = ref([]);
|
||||
const orderBean = ref<OrderBean>();
|
||||
const goodsCount = ref(1);
|
||||
|
||||
onLoad((e: any) => {
|
||||
getApp().globalData?.logger?.info('order-coupon-confirm ', e);
|
||||
onLoad(async (e: any) => {
|
||||
try {
|
||||
groupBuyBean.value = JSON.parse(decodeURIComponent(e?.bean));
|
||||
getApp().globalData?.logger?.info('order-coupon-confirm: groupBuyBean', groupBuyBean.value);
|
||||
if(groupBuyBean.value) {
|
||||
imageList.value = groupBuyBean.value?.image?.split(',');
|
||||
getApp().globalData?.logger?.info('order-coupon-confirm: imageList', imageList.value);
|
||||
}
|
||||
|
||||
getApp().globalData?.logger?.info('order-coupon-confirm: userInfo', userInfo.value);
|
||||
getApp().globalData?.logger?.info('order-coupon-confirm: terminalInfo', terminalInfo.value);
|
||||
|
||||
await userState.fetchTerminal(groupBuyBean.value?.companyId || '');
|
||||
createOrder();
|
||||
} catch (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)),
|
||||
terminal_sn: terminalInfo.value?.terminalSn,
|
||||
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,
|
||||
notify_url: 'https://www.baidu.com'
|
||||
}, true);
|
||||
|
||||
return {
|
||||
getApp().globalData?.logger?.info('order-coupon-confirm: buildSqbParams before sign: ', params);
|
||||
const paramsSign = {
|
||||
...params,
|
||||
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) => {
|
||||
@ -138,11 +135,24 @@ const navigateTo = (e: any) => {
|
||||
uni.navigateBack();
|
||||
}
|
||||
});
|
||||
},
|
||||
onFailure: (e: any) => {
|
||||
getApp().globalData?.logger?.error('coupon pay failure params: ', buildSqbParams.value, e);
|
||||
showToast('支付失败', {
|
||||
icon: 'none',
|
||||
complete: () => {
|
||||
uni.navigateBack();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const createOrder = () => {
|
||||
if(!terminalInfo.value) {
|
||||
utils_common_index.showToast('当前店铺未配置收款渠道,请联系商家');
|
||||
return;
|
||||
}
|
||||
const params = {
|
||||
id: groupBuyBean.value?.id,
|
||||
cash: totalPrice.value,
|
||||
|
@ -24,11 +24,13 @@
|
||||
</template>
|
||||
|
||||
<script setup lang='ts'>
|
||||
import { getCompanyList } from '@/api/company';
|
||||
import { useUserStore } from '@/store';
|
||||
import { assetsUrl } from '@/utils/assets';
|
||||
import { showToast } from '@/utils';
|
||||
import { getCompanyId, getOpenId, goPath, showToast } from '@/utils';
|
||||
|
||||
const userStore = useUserStore();
|
||||
const { userInfo } = storeToRefs(userStore);
|
||||
const isAgreePrivacy = ref(false);
|
||||
|
||||
function wechatLogin() {
|
||||
@ -38,9 +40,41 @@ function wechatLogin() {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
//登录成功先判断当前公司有没有注册过
|
||||
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' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -129,10 +129,19 @@ const save = async () => {
|
||||
getApp().globalData?.logger.info('register params: ', registerForm);
|
||||
if(result) {
|
||||
showToast('注册成功');
|
||||
if(getApp()?.globalData && getApp()?.globalData?.sharePath) {
|
||||
uni.reLaunch({
|
||||
url: getApp()?.globalData?.sharePath,
|
||||
onSuccess: () => {
|
||||
getApp().globalData!.sharePath = '';
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await uni.reLaunch({
|
||||
url: '/pages/home/index'
|
||||
});
|
||||
}
|
||||
}
|
||||
uni.hideLoading();
|
||||
};
|
||||
</script>
|
||||
|
@ -5,18 +5,26 @@
|
||||
<script lang='ts' setup>
|
||||
|
||||
import { getStoreId } from '@/api/company';
|
||||
import { isLogin, setCompanyId, setRegisterStoreId } from '@/utils';
|
||||
|
||||
onLoad(async (options) => {
|
||||
getApp().globalData?.logger?.info('ticketsBuy share options: ', options);
|
||||
|
||||
let couponId = options?.couponsId;
|
||||
if(couponId) {
|
||||
const path = `/pages/common/groupbuy/detail?couponId=${couponId}`;
|
||||
if(!isLogin() && getApp()?.globalData) {
|
||||
getApp().globalData!.sharePath = path;
|
||||
}
|
||||
|
||||
if(options?.companyId && options?.creatorId) {
|
||||
const storeId = await getStoreId({
|
||||
companyid: options?.companyId,
|
||||
deviceid: options?.creatorId
|
||||
});
|
||||
setCompanyId(options?.companyId);
|
||||
if(storeId) {
|
||||
// setRegisterStoreId(storeId);
|
||||
setRegisterStoreId(storeId);
|
||||
if(getApp()?.globalData) {
|
||||
getApp().globalData!.shareCompanyId = options?.companyId;
|
||||
getApp().globalData!.shareStoreId = storeId;
|
||||
@ -26,7 +34,7 @@ onLoad(async (options) => {
|
||||
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: `/pages/common/groupbuy/detail?couponId=${couponId}`
|
||||
url: path
|
||||
});
|
||||
}, 300);
|
||||
} else {
|
||||
|
@ -185,6 +185,7 @@ const fetchCompanyList = (fn: any = undefined) => {
|
||||
showRegisterModal();
|
||||
return;
|
||||
}
|
||||
|
||||
if(fn != undefined && fn instanceof Function) {
|
||||
fn(companyList.value, userList.value);
|
||||
} else {
|
||||
@ -209,8 +210,7 @@ const fetchCompanyList = (fn: any = undefined) => {
|
||||
avatarModifyRemind();
|
||||
}
|
||||
}
|
||||
)
|
||||
;
|
||||
);
|
||||
};
|
||||
|
||||
const showRegisterModal = () => {
|
||||
|
@ -4,12 +4,27 @@
|
||||
|
||||
<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);
|
||||
|
||||
if(options?.companyId && options?.storeId && getApp()?.globalData) {
|
||||
if(options?.companyId) {
|
||||
setCompanyId(options?.companyId);
|
||||
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 = options?.storeId;
|
||||
getApp().globalData!.shareStoreId = storeId;
|
||||
}
|
||||
}
|
||||
|
||||
let goodsShareId = '';
|
||||
@ -19,9 +34,13 @@ onLoad((options) => {
|
||||
getApp().globalData?.logger?.info('app share index/index options: goodsShareId ', goodsShareId);
|
||||
|
||||
if(goodsShareId) {
|
||||
const path = `/pages/common/groupbuy/detail?shareId=${goodsShareId}`;
|
||||
if(!isLogin() && getApp()?.globalData) {
|
||||
getApp().globalData!.sharePath = path;
|
||||
}
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: `/pages/common/groupbuy/detail?shareId=${goodsShareId}`
|
||||
url: path
|
||||
});
|
||||
}, 300);
|
||||
} else {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
|
||||
"projectname": "肃客会员",
|
||||
"projectname": "VIP顾客中心",
|
||||
"setting": {
|
||||
"compileHotReLoad": true
|
||||
}
|
||||
|
@ -155,11 +155,11 @@ const useUserStore = defineStore('user', {
|
||||
if(getApp().globalData) {
|
||||
getApp().globalData!.companyId = this.userInfo.companyId;
|
||||
}
|
||||
this.fetchTerminal(this.userInfo?.companyId);
|
||||
this.fetchCompanyInfo();
|
||||
} else {
|
||||
await clearToken();
|
||||
}
|
||||
this.fetchTerminal();
|
||||
this.fetchCompanyInfo();
|
||||
},
|
||||
|
||||
setCompanyInfo(partial: Partial<any>) {
|
||||
@ -183,8 +183,8 @@ const useUserStore = defineStore('user', {
|
||||
this.companyConfigInfo = await getCompanyInfo();
|
||||
},
|
||||
|
||||
async fetchTerminal() {
|
||||
this.terminalInfo = await getTerminal(this.userInfo?.companyId);
|
||||
async fetchTerminal(companyId: string = '') {
|
||||
this.terminalInfo = await getTerminal(companyId || this.userInfo.companyId);
|
||||
},
|
||||
|
||||
// 重置用户信息
|
||||
|
@ -79,11 +79,17 @@ export function goPath(path: string, needAuth: boolean = false) {
|
||||
}
|
||||
}
|
||||
|
||||
export function goLogin() {
|
||||
export function goLogin(reLaunch: boolean = false) {
|
||||
const path = '/pages/common/login/index';
|
||||
if(reLaunch) {
|
||||
uni.reLaunch({
|
||||
url: path
|
||||
}).then();
|
||||
} else {
|
||||
uni.navigateTo({
|
||||
url: '/pages/common/login/index'
|
||||
}).then(r => {
|
||||
});
|
||||
url: path
|
||||
}).then();
|
||||
}
|
||||
}
|
||||
|
||||
export function formatTimeWithZeroPad(num: number): string {
|
||||
|
@ -33,8 +33,8 @@ export const handlePayResult = (orderId: string | undefined, e: any, { onSuccess
|
||||
const str = url.split('?')[1];
|
||||
const resultObj = JSON.parse(str.replaceAll('result=', ''));
|
||||
|
||||
getApp().globalData?.logger?.info('pay reuslt : ', orderId, resultObj);
|
||||
if(resultObj?.is_success === true) {
|
||||
getApp().globalData?.logger?.info('pay success : ', orderId, resultObj);
|
||||
if(onSuccess) {
|
||||
onSuccess(resultObj);
|
||||
} else {
|
||||
@ -46,9 +46,9 @@ export const handlePayResult = (orderId: string | undefined, e: any, { onSuccess
|
||||
});
|
||||
}
|
||||
} else {
|
||||
getApp().globalData?.logger?.error('pay failure :', resultObj);
|
||||
getApp().globalData?.logger?.error('pay failure :', orderId, resultObj);
|
||||
if(onFailure) {
|
||||
onFailure();
|
||||
onFailure(resultObj);
|
||||
} else {
|
||||
const msg = resultObj?.error_message || '支付失败';
|
||||
showToast(msg, {
|
||||
|
@ -26,7 +26,7 @@ function requestInterceptors() {
|
||||
|
||||
// config.header.contentType = "x-www-form-urlencoded"
|
||||
}
|
||||
getApp().globalData?.logger.info('request: ', config);
|
||||
// getApp().globalData?.logger.info('request: ', config);
|
||||
return config;
|
||||
},
|
||||
(
|
||||
@ -53,7 +53,10 @@ function responseInterceptors() {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user