修改公众号关注逻辑,增加电子围栏

This commit is contained in:
2025-11-25 13:24:35 +08:00
parent 26f5beb660
commit 4d78311aaf
10 changed files with 1315 additions and 1057 deletions

View File

@@ -1,5 +1,5 @@
// const debug = process.env.NODE_ENV == 'development' ? true : false; // const debug = process.env.NODE_ENV == 'development' ? true : false;
const debug = false; const debug = true;
// #ifdef H5 // #ifdef H5
const proxyApi = "/api"; const proxyApi = "/api";
// #endif // #endif

View File

@@ -24,11 +24,18 @@ onMounted(() => {
// 页面加载完成后生成二维码 // 页面加载完成后生成二维码
const userInfo = uni.cache.get("userInfo") || {}; const userInfo = uni.cache.get("userInfo") || {};
const wechatAcQrcode = userInfo.wechatAcQrcode || ""; const wechatAcQrcode = userInfo.wechatAcQrcode || "";
codeOptions.value.code = wechatAcQrcode; if(!userInfo.isAc){
codeOptions.value.code = wechatAcQrcode;
}
}); });
const emit = defineEmits(["generate"]); const emit = defineEmits(["generate"]);
function qrcodeResult(e) { function qrcodeResult(e) {
emit("generate", e.img.tempFilePath); const userInfo = uni.cache.get("userInfo") || {};
if(!userInfo.isAc){
emit("generate", e.img.tempFilePath);
}
} }
</script> </script>

View File

@@ -7,6 +7,6 @@
"lodash": "^4.17.21", "lodash": "^4.17.21",
"pinia": "^2.3.1", "pinia": "^2.3.1",
"pinia-plugin-unistorage": "^0.1.2", "pinia-plugin-unistorage": "^0.1.2",
"ysk-utils": "^1.0.45" "ysk-utils": "^1.0.78"
} }
} }

View File

@@ -326,33 +326,8 @@ const indexsRef = ref(null);
onShow(async () => { onShow(async () => {
try { try {
uni.getLocation({ await storeuser.getLocation()
type: 'wgs84', proxy.$isResolve();
success: async (res) => {
console.log('getLocation',res);
let successres = await APIgeocodelocation({
lng: res.longitude,
lat: res.latitude
});
if (successres) {
let datastorage = {
country: successres.addressComponent.country, // "中国"
province: successres.addressComponent.province, //province: "陕西省"
address: successres.addressComponent.city, //district: "西安市"
district: successres.addressComponent.district, //district: "未央区"
lng: res.longitude,
lat: res.latitude
};
uni.cache.set('getLocationstorage', datastorage);
// 登录
proxy.$isResolve();
}
},
fail(error) {
console.error('获取经纬度失败',error);
}
});
const shopId=uni.cache.get('shopId') const shopId=uni.cache.get('shopId')
if(shopId){ if(shopId){
indexsRef.value.getVipConfig(); indexsRef.value.getVipConfig();

View File

@@ -1227,6 +1227,10 @@ const disablePayType = computed(() => {
arr.add("余额支付"); arr.add("余额支付");
} }
} }
if (cartStore.orderCostSummary.orderOriginFinalPayAmount <= 0) {
arr.add("微信支付");
}
//充值并付款时只能微信支付 //充值并付款时只能微信支付
if (rechargeItem.value.id) { if (rechargeItem.value.id) {
arr.add("余额支付"); arr.add("余额支付");

File diff suppressed because it is too large Load Diff

View File

@@ -250,7 +250,7 @@
></view> ></view>
</view> </view>
<text class="num">{{ ifcartNumber(item) }}</text> <text class="num">{{ ifcartNumber(item) }}</text>
<view class="btn"> <view class="btn" >
<up-icon <up-icon
name="plus-circle-fill" name="plus-circle-fill"
color="#E9AB7A" color="#E9AB7A"
@@ -495,7 +495,7 @@
</view> </view>
<text class="num">{{ ifcartNumber(item1) }}</text> <text class="num">{{ ifcartNumber(item1) }}</text>
<view class="btn"> <view class="btn" >
<up-icon <up-icon
name="plus-circle-fill" name="plus-circle-fill"
color="#E9AB7A" color="#E9AB7A"
@@ -1674,15 +1674,33 @@ const isProductAvailable = async (sellDaysStr, startTimeStr, endTimeStr) => {
return isInRange; return isInRange;
}; };
// 单规格 /**
const singleclick = async (item, i) => { * 判断商品是否可售
console.log("单规格商品点击事件:", item, i); * @param {Object} item
*/
function juageProductAvailable(item) {
if (!isProductAvailable(item.days, item.startTime, item.endTime)) { if (!isProductAvailable(item.days, item.startTime, item.endTime)) {
uni.showToast({ uni.showToast({
title: "不在可售时间内", title: "不在可售时间内",
}); });
return false; return false;
} }
if(item.isStock&&item.stockNumber<item.suitNum){
uni.showToast({
title: "库存不足",
icon: "none",
});
return false;
}
return true
}
// 单规格
const singleclick = async (item, i) => {
console.log("单规格商品点击事件:", item, i);
if(!juageProductAvailable(item)){
return false;
}
// 判断购物车是否有该选中商品 // 判断购物车是否有该选中商品
let res = null; let res = null;
try { try {
@@ -3055,7 +3073,7 @@ function toHistory() {
} }
.shop_sku_box:last-child { .shop_sku_box:last-child {
padding-bottom: 60rpx; padding-bottom: 140rpx;
} }
.shop_sku_box { .shop_sku_box {

59
pnpm-lock.yaml generated
View File

@@ -30,8 +30,8 @@ importers:
specifier: ^0.1.2 specifier: ^0.1.2
version: 0.1.2 version: 0.1.2
ysk-utils: ysk-utils:
specifier: ^1.0.40 specifier: ^1.0.78
version: 1.0.40 version: 1.0.78
packages: packages:
@@ -39,17 +39,17 @@ packages:
resolution: {integrity: sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==} resolution: {integrity: sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==}
engines: {node: '>=6.9.0'} engines: {node: '>=6.9.0'}
'@babel/helper-validator-identifier@7.27.1': '@babel/helper-validator-identifier@7.28.5':
resolution: {integrity: sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow==} resolution: {integrity: sha512-qSs4ifwzKJSV39ucNjsvc6WVHs6b7S03sOh2OcHF9UHfVPqWWALUsNUVzhSBiItjRZoLHx7nIarVjqKVusUZ1Q==}
engines: {node: '>=6.9.0'} engines: {node: '>=6.9.0'}
'@babel/parser@7.28.4': '@babel/parser@7.28.5':
resolution: {integrity: sha512-yZbBqeM6TkpP9du/I2pUZnJsRMGGvOuIrhjzC1AwHwW+6he4mni6Bp/m8ijn0iOuZuPI2BfkCoSRunpyjnrQKg==} resolution: {integrity: sha512-KKBU1VGYR7ORr3At5HAtUQ+TV3SzRCXmA/8OdDZiLDBIZxVyzXuztPjfLd3BV1PRAQGCMWWSHYhL0F8d5uHBDQ==}
engines: {node: '>=6.0.0'} engines: {node: '>=6.0.0'}
hasBin: true hasBin: true
'@babel/types@7.28.4': '@babel/types@7.28.5':
resolution: {integrity: sha512-bkFqkLhh3pMBUQQkpVgWDWq/lqzc2678eUyDlTBhRqhCHFguYYGM0Efga7tYk4TogG/3x0EEl66/OQ+WGbWB/Q==} resolution: {integrity: sha512-qQ5m48eI/MFLQ5PxQj4PFaprjyCTLI37ElWMmNs0K8Lk3dVeOdNpB3ks8jc7yM5CDmVC73eMVk/trk3fgmrUpA==}
engines: {node: '>=6.9.0'} engines: {node: '>=6.9.0'}
'@dcloudio/types@3.4.21': '@dcloudio/types@3.4.21':
@@ -104,8 +104,8 @@ packages:
bignumber.js@9.3.1: bignumber.js@9.3.1:
resolution: {integrity: sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==} resolution: {integrity: sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==}
csstype@3.1.3: csstype@3.2.3:
resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} resolution: {integrity: sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==}
dayjs@1.11.18: dayjs@1.11.18:
resolution: {integrity: sha512-zFBQ7WFRvVRhKcWoUh+ZA1g2HVgUbsZm9sbddh8EC5iv93sui8DVVz1Npvz+r6meo9VKfa8NyLWBsQK1VvIKPA==} resolution: {integrity: sha512-zFBQ7WFRvVRhKcWoUh+ZA1g2HVgUbsZm9sbddh8EC5iv93sui8DVVz1Npvz+r6meo9VKfa8NyLWBsQK1VvIKPA==}
@@ -120,11 +120,15 @@ packages:
jsbarcode@3.12.1: jsbarcode@3.12.1:
resolution: {integrity: sha512-QZQSqIknC2Rr/YOUyOkCBqsoiBAOTYK+7yNN3JsqfoUtJtkazxNw1dmPpxuv7VVvqW13kA3/mKiLq+s/e3o9hQ==} resolution: {integrity: sha512-QZQSqIknC2Rr/YOUyOkCBqsoiBAOTYK+7yNN3JsqfoUtJtkazxNw1dmPpxuv7VVvqW13kA3/mKiLq+s/e3o9hQ==}
loadsh@0.0.4:
resolution: {integrity: sha512-U+wLL8InpfRalWrr+0SuhWgGt10M4OyAk6G8xCYo2rwpiHtxZkWiFpjei0vO463ghW8LPCdhqQxXlMy2qicAEw==}
deprecated: This is a typosquat on the popular Lodash package. This is not maintained nor is the original Lodash package.
lodash@4.17.21: lodash@4.17.21:
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
magic-string@0.30.19: magic-string@0.30.21:
resolution: {integrity: sha512-2N21sPY9Ws53PZvsEpVtNuSW+ScYbQdp4b9qUaL+9QkHUrGFKo56Lg9Emg5s9V/qrtNBmiR01sYhUOwu3H+VOw==} resolution: {integrity: sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==}
nanoid@3.3.11: nanoid@3.3.11:
resolution: {integrity: sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==} resolution: {integrity: sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==}
@@ -173,23 +177,23 @@ packages:
typescript: typescript:
optional: true optional: true
ysk-utils@1.0.40: ysk-utils@1.0.78:
resolution: {integrity: sha512-Hi+XI7sykGJizExMY5kVWIBhPvO3wudp2q92Vqv6zI6eDtquLz4CwxIfOLEXFfn5crYXVu/yfJQVjK3WAyNYDQ==} resolution: {integrity: sha512-Bgr5B3WWiy0nbgL91QVKoVPYm4wt13Rlav757zEjMVRHbmTjwFEhi3wJlYus0JGd52mbknSxXHMazAPHXwA7uQ==}
snapshots: snapshots:
'@babel/helper-string-parser@7.27.1': {} '@babel/helper-string-parser@7.27.1': {}
'@babel/helper-validator-identifier@7.27.1': {} '@babel/helper-validator-identifier@7.28.5': {}
'@babel/parser@7.28.4': '@babel/parser@7.28.5':
dependencies: dependencies:
'@babel/types': 7.28.4 '@babel/types': 7.28.5
'@babel/types@7.28.4': '@babel/types@7.28.5':
dependencies: dependencies:
'@babel/helper-string-parser': 7.27.1 '@babel/helper-string-parser': 7.27.1
'@babel/helper-validator-identifier': 7.27.1 '@babel/helper-validator-identifier': 7.28.5
'@dcloudio/types@3.4.21': {} '@dcloudio/types@3.4.21': {}
@@ -202,7 +206,7 @@ snapshots:
'@vue/compiler-core@3.5.22': '@vue/compiler-core@3.5.22':
dependencies: dependencies:
'@babel/parser': 7.28.4 '@babel/parser': 7.28.5
'@vue/shared': 3.5.22 '@vue/shared': 3.5.22
entities: 4.5.0 entities: 4.5.0
estree-walker: 2.0.2 estree-walker: 2.0.2
@@ -215,13 +219,13 @@ snapshots:
'@vue/compiler-sfc@3.5.22': '@vue/compiler-sfc@3.5.22':
dependencies: dependencies:
'@babel/parser': 7.28.4 '@babel/parser': 7.28.5
'@vue/compiler-core': 3.5.22 '@vue/compiler-core': 3.5.22
'@vue/compiler-dom': 3.5.22 '@vue/compiler-dom': 3.5.22
'@vue/compiler-ssr': 3.5.22 '@vue/compiler-ssr': 3.5.22
'@vue/shared': 3.5.22 '@vue/shared': 3.5.22
estree-walker: 2.0.2 estree-walker: 2.0.2
magic-string: 0.30.19 magic-string: 0.30.21
postcss: 8.5.6 postcss: 8.5.6
source-map-js: 1.2.1 source-map-js: 1.2.1
@@ -250,7 +254,7 @@ snapshots:
'@vue/reactivity': 3.5.22 '@vue/reactivity': 3.5.22
'@vue/runtime-core': 3.5.22 '@vue/runtime-core': 3.5.22
'@vue/shared': 3.5.22 '@vue/shared': 3.5.22
csstype: 3.1.3 csstype: 3.2.3
'@vue/server-renderer@3.5.22(vue@3.5.22)': '@vue/server-renderer@3.5.22(vue@3.5.22)':
dependencies: dependencies:
@@ -262,7 +266,7 @@ snapshots:
bignumber.js@9.3.1: {} bignumber.js@9.3.1: {}
csstype@3.1.3: {} csstype@3.2.3: {}
dayjs@1.11.18: {} dayjs@1.11.18: {}
@@ -272,9 +276,11 @@ snapshots:
jsbarcode@3.12.1: {} jsbarcode@3.12.1: {}
loadsh@0.0.4: {}
lodash@4.17.21: {} lodash@4.17.21: {}
magic-string@0.30.19: magic-string@0.30.21:
dependencies: dependencies:
'@jridgewell/sourcemap-codec': 1.5.5 '@jridgewell/sourcemap-codec': 1.5.5
@@ -314,7 +320,8 @@ snapshots:
'@vue/server-renderer': 3.5.22(vue@3.5.22) '@vue/server-renderer': 3.5.22(vue@3.5.22)
'@vue/shared': 3.5.22 '@vue/shared': 3.5.22
ysk-utils@1.0.40: ysk-utils@1.0.78:
dependencies: dependencies:
bignumber.js: 9.3.1 bignumber.js: 9.3.1
loadsh: 0.0.4
lodash: 4.17.21 lodash: 4.17.21

View File

@@ -1,273 +1,365 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { APIuserlogin, APIuser } from "@/common/api/api.js";
import { import {
defineStore APIproductqueryShop,
} from 'pinia'; APIusershopInfodetail,
import { APIshopUserInfo,
ref } from "@/common/api/member.js";
} from 'vue'; import { getDistance } from "@/utils/address.js";
import { import { APIgeocodelocation } from "@/common/api/api.js";
APIuserlogin,
APIuser export const Storelogin = defineStore("login", {
} from '@/common/api/api.js' state: () => ({
import { token: "",
APIproductqueryShop, miniAppOpenId: "",
APIusershopInfodetail, userInfo: "",
APIshopUserInfo shopInfo: {},
} from '@/common/api/member.js' }),
export const Storelogin = defineStore('login', { actions: {
state: () => ({ async getShopInfo(shopId) {
token: '', const shopRes = await APIusershopInfodetail({
miniAppOpenId: '', shopId,
userInfo: '', });
shopInfo: {} console.log(shopRes);
}), },
actions: { actionslogin() {
async getShopInfo(shopId) { return new Promise(async (resolve, reject) => {
const shopRes = await APIusershopInfodetail({ // #ifdef MP-WEIXIN
shopId uni.login({
}) provider: "weixin",
console.log(shopRes); success: (data) => {
}, // 微信小程序环境
actionslogin() { uni.getUserInfo({
return new Promise(async (resolve, reject) => { provider: "weixin",
// #ifdef MP-WEIXIN success: async (infoRes) => {
uni.login({ let res = await APIuserlogin({
provider: 'weixin', code: data.code, //临时登录凭证
success: (data) => { rawData: infoRes.rawData,
// 微信小程序环境 source: "wechat",
uni.getUserInfo({ });
provider: 'weixin', if (res) {
success: async (infoRes) => { this.token = res.token;
let res = await APIuserlogin({ this.miniAppOpenId = res.userInfo.miniAppOpenId;
code: data.code, //临时登录凭证 this.userInfo = res.userInfo;
rawData: infoRes.rawData, uni.cache.set("token", res.token);
source: 'wechat' uni.cache.set("userInfo", res.userInfo);
}) uni.cache.set("followIndex", res.followIndex || "");
if (res) { }
this.token = res.token resolve(true);
this.miniAppOpenId = res.userInfo },
.miniAppOpenId fail: (err) => {
this.userInfo = res.userInfo reject(false);
uni.cache.set('token', res.token); },
uni.cache.set('userInfo', res.userInfo); });
uni.cache.set('followIndex', res.followIndex||''); },
} });
resolve(true); // #endif
}, // #ifdef MP-ALIPAY
fail: (err) => { my.getAuthCode({
reject(false); scopes: "auth_base",
} success: async (data) => {
}); // 支付宝小程序环境
} // my.getAuthUserInfo({
}); // success: async (infoRes) => {
// #endif let res = await APIuserlogin({
// #ifdef MP-ALIPAY code: data.authCode, //临时登录凭证
my.getAuthCode({ // rawData: JSON.stringify(infoRes),
scopes: 'auth_base', source: "alipay",
success: async (data) => { });
// 支付宝小程序环境 if (res) {
// my.getAuthUserInfo({ this.token = res.token;
// success: async (infoRes) => { this.miniAppOpenId = res.userInfo.miniAppOpenId;
let res = await APIuserlogin({ this.userInfo = res.userInfo;
code: data.authCode, //临时登录凭证 uni.cache.set("token", res.token);
// rawData: JSON.stringify(infoRes), uni.cache.set("openId", res.userInfo.alipayOpenId);
source: 'alipay' uni.cache.set("userInfo", res.userInfo);
}) resolve(true);
if (res) { }
this.token = res.token },
this.miniAppOpenId = res.userInfo.miniAppOpenId fail: () => {
this.userInfo = res.userInfo reject(false);
uni.cache.set('token', res.token); },
uni.cache.set('openId', res.userInfo });
.alipayOpenId) // #endif
uni.cache.set('userInfo', res.userInfo); });
resolve(true); },
} },
},
fail: () => {
reject(false);
}
})
// #endif
})
}
}
}); });
export const productStore = defineStore('product', { export const productStore = defineStore("product", {
actions: { state: () => ({
getQueryString(url, name) { //解码 location: {
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i') latitude: "",
var r = url.substr(1).match(reg) longitude: "",
if (r != null) { },
return r[2] shopInfo: {
} shopId: "",
return null; isOrderFence: 0,
}, },
// 扫码请求 }),
scanCodeactions(q) { actions: {
console.log('扫码内容', q) getLocation() {
return new Promise(async (resolve, reject) => { return new Promise((resolve, reject) => {
if (q) { console.log("获取经纬度");
console.log(q) uni.getLocation({
let tableCode = "" type: "wgs84",
// #ifdef MP-WEIXIN altitude: true,
tableCode = this.getQueryString(decodeURIComponent(q), 'code') isHighAccuracy: true,
// #endif success: (res) => {
// #ifdef MP-ALIPAY console.log("获取经纬度成功", res);
tableCode = q
// #endif
// #ifdef H5
tableCode = q.tableCode
// #endif
console.log(tableCode);
// 储存卓玛
uni.cache.set('tableCode', tableCode)
if (tableCode) {
console.log('台桌码', uni.cache.get('tableCode'));
let data = await this.actionsproductqueryShop(tableCode)
console.log('data', data)
// -4请求登录
if (data.code == '500') {
if (await this.actionslogin()) {
// 成功 接着在调用
await this.actionsproductqueryShop()
}
}
// 是否免除桌位费 0否1是
if (uni.cache.get('shopInfo').isTableFee == 0) {
uni.reLaunch({
url: '/pages/product/choosetable'
});
} else {
uni.reLaunch({
url: '/pages/product/index'
});
}
} this.location = res;
} else { this.APIgeocodelocation();
// #ifdef APP || MP-WEIXIN || MP-ALIPAY resolve(res);
uni.scanCode({ },
success: async (res) => { fail: (err) => {
let tableCode = this.getQueryString( console.error("获取经纬度失败", err);
decodeURIComponent(res.result), 'code') reject(err);
// 储存卓玛 },
uni.cache.set('tableCode', tableCode) });
if (tableCode) { });
let data = await this.actionsproductqueryShop() },
if (!data) { async APIgeocodelocation() {
uni.showToast({ let successres = await APIgeocodelocation({
title: '店铺已过期或其他问题,请联系商家', lng: this.location.longitude,
icon:'none' lat: this.location.latitude,
}) });
return if (successres) {
} let datastorage = {
// -4请求登录 country: successres.addressComponent.country, // "中国"
const store = Storelogin() province: successres.addressComponent.province, //province: "陕西省"
if (data.code == '-4') { address: successres.addressComponent.city, //district: "西安市"
if (await store.actionslogin()) { district: successres.addressComponent.district, //district: "未央区"
// 成功 接着在调用 lng: this.location.longitude,
await this.actionsproductqueryShop() lat: this.location.latitude,
} };
} uni.cache.set("getLocationstorage", datastorage);
// 是否免除桌位费 0否1是 }
if (uni.cache.get('shopInfo').isTableFee == 0) { },
uni.navigateTo({ getQueryString(url, name) {
url: '/pages/product/choosetable' //解码
}); var reg = new RegExp("(^|&|/?)" + name + "=([^&|/?]*)(&|/?|$)", "i");
} else { var r = url.substr(1).match(reg);
uni.reLaunch({ if (r != null) {
url: '/pages/product/index' return r[2];
}); }
} return null;
},
} /**
}, * 扫码请求
fail: (res) => { * @param {*} q
console.log(res) * @returns
} */
}); async scanCodeactions(q) {
// #endif console.log("扫码内容", q);
} return new Promise(async (resolve, reject) => {
if (q) {
console.log(q);
let tableCode = "";
// #ifdef MP-WEIXIN
tableCode = this.getQueryString(decodeURIComponent(q), "code");
// #endif
// #ifdef MP-ALIPAY
tableCode = q;
// #endif
// #ifdef H5
tableCode = q.tableCode;
// #endif
console.log(tableCode);
// 储存卓玛
uni.cache.set("tableCode", tableCode);
if (tableCode) {
console.log("台桌码", uni.cache.get("tableCode"));
let data = await this.actionsproductqueryShop(tableCode);
}) console.log("data", data);
}, // -4请求登录
if (data.code == "500") {
if (await this.actionslogin()) {
// 成功 接着在调用
await this.actionsproductqueryShop();
}
}
const canOrder = await this.computedDistance();
}
} else {
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
uni.scanCode({
success: async (res) => {
let tableCode = this.getQueryString(
decodeURIComponent(res.result),
"code"
);
// 储存卓玛
uni.cache.set("tableCode", tableCode);
if (tableCode) {
let data = await this.actionsproductqueryShop();
if (!data) {
uni.showToast({
title: "店铺已过期或其他问题,请联系商家",
icon: "none",
});
return;
}
// -4请求登录
const store = Storelogin();
if (data.code == "-4") {
if (await store.actionslogin()) {
// 成功 接着在调用
await this.actionsproductqueryShop();
}
}
const canOrder = await this.computedDistance();
}
},
fail: (res) => {
console.log(res);
},
});
// #endif
}
});
},
// /通过桌码获取当前店铺信息 //计算距离判断是否可以点餐
actionsproductqueryShop(tableCode) { async computedDistance() {
console.log('台桌码',tableCode); return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => { console.log("店铺经纬度", this.shopInfo.lat, this.shopInfo.lng);
// try { console.log(
try { "用户经纬度",
let res = await APIproductqueryShop({ this.location.latitude,
tableCode: tableCode ? tableCode : uni.cache.get('tableCode'), this.location.longitude
}) );
if (res) {
res.shopInfo.isVip = res.vip ? '1' : '0'
res.shopTable.shopExtendMap = res.shopExtendMap
// 店铺信息
uni.cache.set('shopTable', res.shopTable)
// 台桌信息
uni.cache.set('shopInfo', res.shopInfo)
uni.cache.set('shopId', res.shopTable.shopId, 30)
// 当前用户距离店铺的米数
uni.cache.set('distance', res.distance)
resolve(res) if (this.shopInfo.isOrderFence == 0) {
} else { this.jumpToOrderPage();
console.error('通过桌码获取当前店铺信息失败' ,res) resolve(true);
reject() return;
} }
const juli = getDistance(
this.location.latitude,
this.location.longitude,
this.shopInfo.lat,
this.shopInfo.lng
);
const orderFenceDistance = (
(this.shopInfo.orderFenceDistance || 2000) / 2000
).toFixed(2);
} catch (error) { console.log("距离", juli);
console.log(error);
reject()
//TODO handle the exception
}
// } catch (e) { if (this.shopInfo.isOrderFence && juli > orderFenceDistance) {
// reject(false) uni.showModal({
// } title: "提示",
confirmText: "重新定位",
content:
"抱歉,您当前距离店铺过远,为保障您的用餐体验,请您到店后或在门店附近再下单。若您已在店铺附近,可尝试重新定位",
success: async(res) => {
if (res.confirm) {
console.log("用户点击了确认");
await this.getLocation();
this.computedDistance();
} else if (res.cancel) {
console.log("用户点击了取消");
}
},
});
reject();
return;
}
this.jumpToOrderPage();
resolve(juli);
});
},
// 跳转点餐页面
jumpToOrderPage() {
// 是否免除桌位费 0否1是
if (this.shopInfo.isTableFee == 0) {
uni.reLaunch({
url: "/pages/product/choosetable",
});
} else {
uni.reLaunch({
url: "/pages/product/index",
});
}
},
}) // /通过桌码获取当前店铺信息
}, actionsproductqueryShop(tableCode) {
console.log("台桌码", tableCode);
return new Promise(async (resolve, reject) => {
// try {
try {
let res = await APIproductqueryShop({
tableCode: tableCode ? tableCode : uni.cache.get("tableCode"),
});
if (res) {
res.shopInfo.isVip = res.vip ? "1" : "0";
res.shopTable.shopExtendMap = res.shopExtendMap;
this.shopInfo = res.shopInfo;
// 店铺信息
uni.cache.set("shopTable", res.shopTable);
// 台桌信息
uni.cache.set("shopInfo", res.shopInfo);
uni.cache.set("shopId", res.shopTable.shopId, 30);
// 通过shopId 获取店铺会员信息 resolve(res);
actionsproductqueryProduct() { } else {
return new Promise(async (resolve, reject) => { uni.showToast({
try { title: "通过桌码获取当前店铺信息失败",
let res = await APIshopUserInfo() icon: "none",
uni.cache.set('shopUserInfo', res); });
uni.cache.set('orderVIP', res) console.error("通过桌码获取当前店铺信息失败", res);
uni.cache.set('ordershopUserInfo', res.shopInfo) reject();
resolve(res) }
} catch (e) { } catch (error) {
reject(false) console.log(error);
} reject();
//TODO handle the exception
}
}) // } catch (e) {
}, // reject(false)
// }
});
},
// 用户信息获取 // 通过shopId 获取店铺会员信息
actionsAPIuser() { actionsproductqueryProduct() {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
let res = null let res = await APIshopUserInfo();
// 获取店铺用户会员信息 uni.cache.set("shopUserInfo", res);
if (uni.cache.get('shopId')) { uni.cache.set("orderVIP", res);
res = await this.actionsproductqueryProduct() uni.cache.set("ordershopUserInfo", res.shopInfo);
} else { resolve(res);
res = await APIuser() } catch (e) {
uni.cache.set('userInfo', res); reject(false);
} }
console.log('actionsAPIuser res', res); });
resolve(res) },
} catch (e) {
reject(false)
}
}) // 用户信息获取
} actionsAPIuser() {
} return new Promise(async (resolve, reject) => {
}); try {
let res = null;
// 获取店铺用户会员信息
if (uni.cache.get("shopId")) {
res = await this.actionsproductqueryProduct();
} else {
res = await APIuser();
uni.cache.set("userInfo", res);
}
console.log("actionsAPIuser res", res);
resolve(res);
} catch (e) {
reject(false);
}
});
},
},
});

13
utils/address.js Normal file
View File

@@ -0,0 +1,13 @@
// 计算距离
export const getDistance = (la1, lo1, la2, lo2) => { // 当前的纬度,当前的经度,接口拿到的纬度,接口拿到的经度
let La1 = la1 * Math.PI / 180.0;
let La2 = la2 * Math.PI / 180.0;
let La3 = La1 - La2;
let Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
let distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) *
Math.pow(Math.sin(Lb3 / 2), 2)));
distance = distance * 6378.137;
distance = Math.round(distance * 10000) / 10000;
return distance;
}