切换汇邦云用户借呗

This commit is contained in:
dzq 2025-11-25 11:46:55 +08:00
parent 6203c2746e
commit e16966f31c
5 changed files with 25 additions and 16 deletions

View File

@ -66,6 +66,9 @@ export async function getBalanceApi(corpid: string, openid: string) {
export async function getBalanceByQyUserid(corpid: string, userid: string) {
return await http.get<GetBalanceResponse>("payment/getBalanceByQyUserid", { corpid, userid });
}
export async function getUserBalance(corpid: string, ab98UserId: number) {
return await http.get<GetBalanceResponse>("payment/getUserBalance", { corpid, ab98UserId });
}
export async function getShopListApi(corpid: string, mode?: number) {
const params: any = {

View File

@ -56,6 +56,8 @@ export interface SubmitOrderRequestData {
openid: string;
/** 系统用户ID */
userid: string;
/** 汇邦云用户ID */
ab98UserId: number;
/** 企业ID */
corpid: string;
/** 支付类型 wechat:微信 balance:余额 */

View File

@ -24,10 +24,10 @@ const rentingCabinetStore = useRentingCabinetStore();
const { rentingCartItems, rentingCartTotalPrice } = storeToRefs(rentingCabinetStore);
const wxStore = useWxStore();
const { openid, balance, corpidLogin, userid: qyUserid, name: qyName } = storeToRefs(wxStore);
const { openid, balance, corpidLogin, userid: qyUserid, name: qyName, ab98UserId } = storeToRefs(wxStore);
const ab98UserStore = useAb98UserStore();
const { tel, userid: ab98Userid, name } = storeToRefs(ab98UserStore);
const { tel, name } = storeToRefs(ab98UserStore);
const productStore = useProductStore();
@ -135,7 +135,7 @@ async function handleSubmit() {
// 2 -
// 1 -
// 0 -
const isInternal = corpidLogin.value ? 2 : ab98Userid.value ? 1 : 0;
const isInternal = corpidLogin.value ? 2 : ab98UserId.value ? 1 : 0;
// goodsList
let goodsListToSend;
@ -157,6 +157,7 @@ async function handleSubmit() {
const requestData: SubmitOrderRequestData = {
openid: openid.value,
userid: wxStore.userid,
ab98UserId: ab98UserId.value,
corpid: wxStore.corpid,
goodsList: goodsListToSend,
// value

View File

@ -30,7 +30,6 @@ const shopId = ref<number>(0)
//
onMounted(async () => {
// await wxStore.fakeQyLogin();
uni.login({
provider: 'weixin', //使
success: function (loginRes) {

View File

@ -1,5 +1,5 @@
import { pinia } from "@/pinia"
import { getOpenIdApi, getBalanceApi, qyLogin, getBalanceByQyUserid, fakeQyLoginApi } from "@/api/shop"
import { getOpenIdApi, getBalanceApi, qyLogin, getBalanceByQyUserid, fakeQyLoginApi, getUserBalance } from "@/api/shop"
import { ab98UserDTO, GetBalanceResponse } from "@/api/shop/types"
import { useAb98UserStore } from "./ab98-user"
import { defineStore } from "pinia"
@ -34,6 +34,8 @@ export const useWxStore = defineStore("wx", () => {
// 汇邦云用户信息
const ab98User = ref<ab98UserDTO | null>(null);
const ab98UserId = ref<number | null>(null);
const isFakeQyLogin = ref<boolean>(false);
// handleWxCallback 是否完成
const isHandleWxCallbackComplete = ref<boolean>(true);
@ -53,6 +55,10 @@ export const useWxStore = defineStore("wx", () => {
isCabinetAdmin.value = isAdmin;
}
const setAb98UserId = (id: number) => {
ab98UserId.value = id;
}
const setAb98User = (user: ab98UserDTO) => {
ab98User.value = user;
const ab98UserStore = useAb98UserStore();
@ -68,8 +74,8 @@ export const useWxStore = defineStore("wx", () => {
}
const refreshBalance = async () => {
if (corpid.value && userid.value) {
const res = await getBalanceByQyUserid(corpid.value, userid.value);
if (corpid.value && ab98UserId.value) {
const res = await getUserBalance(corpid.value, ab98UserId.value);
if (res && res.code == 0) {
balance.value = res.data.balance;
useBalance.value = res.data.useBalance;
@ -82,7 +88,7 @@ export const useWxStore = defineStore("wx", () => {
}
}
const handleWxCallback = async (params: { corpid?: string; code?: string; state?: string; }) => {
/* const handleWxCallback = async (params: { corpid?: string; code?: string; state?: string; }) => {
console.log('handleWxCallback:', params)
isHandleWxCallbackComplete.value = false; // 开始处理,标记为未完成
if (params.code) {
@ -134,9 +140,6 @@ export const useWxStore = defineStore("wx", () => {
if (!ab98User.value && balanceRes.data.ab98User) {
setAb98User(balanceRes.data.ab98User);
}
/* if (!corpid.value) {
corpid.value = balanceRes.data.corpid;
} */
}
}
} catch (err) {
@ -148,9 +151,9 @@ export const useWxStore = defineStore("wx", () => {
} else {
isHandleWxCallbackComplete.value = true; // 没有code参数直接标记为已完成
}
}
} */
const fakeQyLogin = async () => {
/* const fakeQyLogin = async () => {
isFakeQyLogin.value = true;
corpid.value = "wpZ1ZrEgAA2QTxIRcB4cMtY7hQbTcPAw";
corpidLogin.value = true;
@ -167,7 +170,7 @@ export const useWxStore = defineStore("wx", () => {
}
}
isHandleWxCallbackComplete.value = true
}
} */
// 检测 handleWxCallback 是否完成的异步函数
const waitForHandleWxCallbackComplete = async (timeout = 30000): Promise<boolean> => {
@ -186,6 +189,7 @@ export const useWxStore = defineStore("wx", () => {
corpid.value = "wpZ1ZrEgAA2QTxIRcB4cMtY7hQbTcPAw";
openid.value = userDTO.openid || openid.value;
wxUserDTO.value = userDTO;
ab98UserId.value = userDTO.ab98UserId || ab98UserId.value;
if (userDTO.qyUserId) {
qyUserId.value = userDTO.qyUserId;
}
@ -197,8 +201,8 @@ export const useWxStore = defineStore("wx", () => {
return { code, state, openid, corpid, userid, balance, useBalance,
balanceLimit, isCabinetAdmin, corpidLogin, name, ab98User, qyUserId, isFakeQyLogin,
isHandleWxCallbackComplete, wxUserDTO, setOpenid, setBalance, handleWxCallback, setIsCabinetAdmin,
refreshBalance, setAb98User, fakeQyLogin, waitForHandleWxCallbackComplete, wxMpCallback }
isHandleWxCallbackComplete, wxUserDTO, ab98UserId, setOpenid, setBalance, setIsCabinetAdmin,
refreshBalance, setAb98User, waitForHandleWxCallbackComplete, wxMpCallback, setAb98UserId }
})
/**