tiefen_space_h5/api/public.js

210 lines
4.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { get } from "@/utils/storeInfo";
import require from "@/utils/require";
import { Toast } from "antd-mobile";
//关注和取关功能
export const handleFollow = async (isFollowed, followedID, callback) => {
const account = get("account");
let body = {
[!isFollowed ? "account_relations" : "sentences"]: [
{ sub_mid: account.mid, obj_mid: followedID, predicate: 0 },
{ sub_mid: followedID, obj_mid: account.mid, predicate: 1 },
],
};
try {
const data = await require("POST", `/api/account_relation/${
!isFollowed ? "create" : "delete"
}`, {
body,
});
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
} else {
callback(!isFollowed);
}
} catch (error) {
console.error(error);
}
};
//点赞和取消点赞功能
export const thumbsUp = async (id, times, callback,isZone) => {
try {
const body = isZone?{
zone_moment_id: id,
times: times == 1 ? -1 : 1,
}:{
moment_id: id,
times: times == 1 ? -1 : 1,
};
console.log("body", body);
const data = await require("POST", `/api/${isZone?"zone_moment":"moment"}/thumbs_up`, {
body,
});
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
} else {
callback(times == 1 ? -1 : 1);
}
} catch (error) {
console.error(error);
}
};
//点赞和取消点赞功能
export const zoneThumbsUp = async (id, times = 1, callback) => {
console.log("times", times);
try {
const body = {
moment_id: id,
times: times == 1 ? -1 : 1,
};
const data = await require("POST", `/api/zone/thumbs_up`, {
body,
});
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
} else {
callback(times == 1 ? -1 : 1);
}
} catch (error) {
console.error(error);
}
};
// 查看关系
export async function checkRelation(subMid, objMid, predicate) {
try {
const data =
await require("POST", `/api/account_relation/list_by_sentence`, {
body: {
sub_mid: subMid,
obj_mid: objMid,
predicate: predicate,
},
});
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
}
return data.data.is_account_relation_existed;
} catch (error) {
console.error(error);
}
}
// 获取用户信息
export async function getUserInfo() {
try {
const data =
await require("POST", `/api/account/list_by_mid`, null, true);
if (data.ret === -1) {
Toast.show({
icon: "fail",
content: data.msg,
position: "top",
});
return;
}
return data.data.account;
} catch (error) {
console.error(error);
}
}
// 创建订单
export const createOrder = async (type = "alipay_h5") => {
if (!selectedPrice.id && !customCoin.selected) {
Toast.show({
content: "请选择充值档位",
});
return;
}
if (customCoin.selected && customCoin.num < 10) {
Toast.show({
content: "最低充值1元哦",
});
return;
}
const base = webviewBaseRequest();
const body = {
...base,
product_id: customCoin.selected ? "h5_custom_coin" : selectedPrice.id,
custom_coins: customCoin.selected ? customCoin.num : 0,
pay_type: type,
redirect_url: type === "yeepay_wxpay_h5" ? window.location.href : "",
from: "app",
};
//如果是微信jsapi支付直接跳转到中间页
if (type === "wxpay_jsapi") {
router.push(`/pay/${encodeURIComponent(JSON.stringify(body))}`);
return;
}
setIsLoading(true);
const signature = generateSignature(body);
try {
const response = await fetch(
`/api/vas/create_order?signature=${signature}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
}
);
const data = await response.json();
if (data.ret === -1) {
Toast.show({
content: data.msg,
});
return;
}
switch (type) {
case "yeepay_alipay_h5":
router.push(`${data.data.yeepay_alipay_h5_param_str}`);
break;
case "yeepay_wxpay_h5":
router.push(`${data.data.yeepay_wxpay_h5_param_str}`);
break;
case "alipay_h5":
router.push(`${data.data.alipay_h5_param_str}`);
break;
case "wxpay_h5":
router.push(
`https://shop.tiefen.fun/pay/wxpay_h5/${encodeURIComponent(
data.data.wxpay_h5_param_str
)}`
);
break;
default:
router.push(`${data.data.alipay_h5_param_str}`);
break;
}
} catch (error) {
console.error(error);
} finally {
setIsLoading(false);
}
};