!61 【新增】接入微信订阅消息

Merge pull request !61 from puhui999/master
pull/52/MERGE
芋道源码 2024-07-24 11:36:54 +00:00 committed by Gitee
commit 3d7f63868f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 42 additions and 30 deletions

View File

@ -130,6 +130,7 @@
import TradeConfigApi from '@/sheep/api/trade/config';
import { fen2yuan } from '@/sheep/hooks/useGoods';
import AfterSaleApi from '@/sheep/api/trade/afterSale';
import { SubscribeTemplate } from '@/sheep/util/const';
const form = ref(null);
const state = reactive({
@ -165,7 +166,7 @@
//
async function submit() {
// #ifdef MP
sheep.$platform.useProvider('wechat').subscribeMessage('order_aftersale_change');
sheep.$platform.useProvider('wechat').subscribeMessage(SubscribeTemplate.ORDER_AFTERSALE_CHANGE);
// #endif
let data = {
orderItemId: state.itemId,

View File

@ -47,6 +47,7 @@
import { onLoad } from '@dcloudio/uni-app';
import { fen2yuan } from '@/sheep/hooks/useGoods';
import PayWalletApi from '@/sheep/api/pay/wallet';
import { SubscribeTemplate } from '@/sheep/util/const';
const userWallet = computed(() => sheep.$store('user').userWallet);
const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
@ -73,20 +74,20 @@
//
async function onConfirm() {
const { code, data } = await PayWalletApi.createWalletRecharge({
packageId: state.packageList.find((item) => fen2yuan(item.payPrice) === state.recharge_money)?.id,
payPrice: state.recharge_money * 100
});
if (code !== 0) {
return;
}
// const { code, data } = await PayWalletApi.createWalletRecharge({
// packageId: state.packageList.find((item) => fen2yuan(item.payPrice) === state.recharge_money)?.id,
// payPrice: state.recharge_money * 100
// });
// if (code !== 0) {
// return;
// }
// #ifdef MP
sheep.$platform.useProvider('wechat').subscribeMessage('money_change');
sheep.$platform.useProvider('wechat').subscribeMessage(SubscribeTemplate.MONEY_CHANGE);
// #endif
sheep.$router.go('/pages/pay/index', {
id: data.payOrderId,
orderType: 'recharge'
});
// sheep.$router.go('/pages/pay/index', {
// id: data.payOrderId,
// orderType: 'recharge'
// });
}
onLoad(() => {

View File

@ -4,13 +4,10 @@ export default {
// 微信相关
wechat: {
// 小程序订阅消息
subscribeTemplate: (params) =>
subscribeTemplate: () =>
request({
url: 'third/wechat/subscribeTemplate',
url: '/member/social-user/get-subscribe-template',
method: 'GET',
params: {
platform: 'miniProgram',
},
custom: {
showError: false,
showLoading: false,

View File

@ -1,4 +1,4 @@
import third from '@/sheep/api/migration/third'
import third from '@/sheep/api/migration/third';
import AuthUtil from '@/sheep/api/member/auth';
import SocialApi from '@/sheep/api/member/social';
import UserApi from '@/sheep/api/member/user';
@ -164,8 +164,8 @@ const checkUpdate = async (silence = true) => {
// 获取订阅消息模板
async function getSubscribeTemplate() {
const { error, data } = await third.wechat.subscribeTemplate();
if (error === 0) {
const { code, data } = await third.wechat.subscribeTemplate();
if (code === 0) {
subscribeEventList = data;
}
}
@ -174,11 +174,17 @@ async function getSubscribeTemplate() {
function subscribeMessage(event) {
let tmplIds = [];
if (typeof event === 'string') {
tmplIds.push(subscribeEventList[event]);
const temp = subscribeEventList.find(item => item.title.includes(event));
if (temp) {
tmplIds.push(temp.priTmplId);
}
}
if (typeof event === 'object') {
event.forEach((item) => {
if (typeof subscribeEventList[item] !== 'undefined') tmplIds.push(subscribeEventList[item]);
event.forEach((e) => {
const temp = subscribeEventList.find(item => item.title.includes(e));
if (temp) {
tmplIds.push(temp.priTmplId);
}
});
}
if (tmplIds.length === 0) return;
@ -201,5 +207,5 @@ export default {
getInfo,
getOpenid,
subscribeMessage,
checkUpdate
checkUpdate,
};

View File

@ -56,6 +56,13 @@ export const TimeStatusEnum = {
END: '已结束',
}
// TODO 订阅模版枚举
export const SubscribeTemplate = {
ORDER_AFTERSALE_CHANGE: "售后进度通知",
MONEY_CHANGE: "充值成功通知"
}
export const getTimeStatusEnum = (startTime, endTime) => {
const now = dayjs();
if (now.isBefore(startTime)) {