fix: AI客服+合同审查回复格式化;review.js修复;积分充值流程完善

This commit is contained in:
2026-10-12 17:13:32 +08:00
parent edd53d5d2b
commit 904fd1f8f1
1732 changed files with 340840 additions and 1210 deletions
@@ -0,0 +1,39 @@
//创建积分充值订单
module.exports = {
main: async (event) => {
let { data = {}, userInfo, util } = event;
let { vk, db, _ } = util;
const { points, price } = data; // points=积分数量 price=价格(分→元)
const amount = price / 100; // 分转元
const offAmount = amount;
const orderId = await vk.baseDao.add({
dbName: "jjx-order",
dataJson: {
orderNo: vk.pubfn.createOrderNo("39XU", 20),
uid: userInfo.uid,
orderStatus: 0,
type: 20, // 20=积分充值
amount,
offAmount,
saveAmount: 0,
offRate: 100,
}
});
await vk.baseDao.add({
dbName: "jjx-order-goods",
dataJson: {
orderId,
goodsId: 'points_recharge',
num: 1,
goodsName: `积分充值_${points}积分`,
goodsPrice: amount,
goodsCover: null,
}
});
return { code: 0, msg: 'ok', data: orderId };
}
};
@@ -0,0 +1,47 @@
//扣积分(合同审查用)
module.exports = {
main: async (event) => {
let { data = {}, userInfo, util } = event;
let { db, _ } = util;
const { amount, reason, biz_type, biz_id } = data;
if (!amount || amount <= 0) {
return { code: -1, msg: '扣减数量无效' };
}
// 查余额
const userRes = await db.collection('jjx-user-points').doc(userInfo.uid).get();
if (!userRes.data.length) {
return { code: -1, msg: '积分账户不存在,请先获取积分' };
}
const currentBalance = userRes.data[0].balance;
if (currentBalance < amount) {
return { code: -1, msg: '积分不足', data: { balance: currentBalance, needed: amount } };
}
const newBalance = currentBalance - amount;
// 扣减余额
await db.collection('jjx-user-points').doc(userInfo.uid).update({
balance: newBalance,
total_spent: _.inc(amount),
update_time: new Date()
});
// 记录流水
await db.collection('jjx-points-log').add({
user_id: userInfo.uid,
type: 'spend',
amount: -amount,
balance_after: newBalance,
reason: reason || '积分消耗',
biz_type: biz_type || 'other',
biz_id: biz_id || '',
_add_time: new Date()
});
return { code: 0, msg: 'ok', data: { balance: newBalance } };
}
};
@@ -0,0 +1,37 @@
// 获取积分余额
module.exports = {
main: async (event) => {
let { data = {}, userInfo, util } = event;
let { db, _ } = util;
//默认积分500
let amount = 500;
const res = await db.collection('jjx-user-points').doc(userInfo.uid).get();
if (res.data.length === 0) {
// 新用户,自动赠送 500 积分
await db.collection('jjx-user-points').add({
_id: userInfo.uid,
balance: amount,
total_earned: amount,
total_spent: 0,
gift: amount,
update_time: new Date()
});
await db.collection('jjx-points-log').add({
user_id: userInfo.uid,
type: 'earn',
amount: amount,
balance_after: amount,
reason: '新用户注册赠送',
biz_type: 'gift',
_add_time: new Date()
});
return { code: 0, msg: 'ok', data: { balance: amount, total_earned: amount, total_spent: 0, gift: amount } };
}
return { code: 0, msg: 'ok', data: res.data[0] };
}
};
@@ -0,0 +1,30 @@
//查询积分流水
module.exports = {
main: async (event) => {
let { data = {}, userInfo, util } = event;
let { db, _ } = util;
const { pageIndex = 1, pageSize = 20, type } = data;
const where = { user_id: userInfo.uid };
if (type) where.type = type; // 可选筛选 earn/spend
const countRes = await db.collection('jjx-points-log').where(where).count();
const listRes = await db.collection('jjx-points-log')
.where(where)
.orderBy('_add_time', 'desc')
.skip((pageIndex - 1) * pageSize)
.limit(pageSize)
.get();
return {
code: 0,
msg: 'ok',
data: {
total: countRes.total,
rows: listRes.data
}
};
}
};
@@ -0,0 +1,55 @@
//积分充值
module.exports = {
main: async (event) => {
let { data = {}, userInfo, util } = event;
let { db, _ } = util;
const { order_id } = data;
if (!order_id) {
return { code: -1, msg: '缺少订单ID' };
}
// 查订单
const orderRes = await db.collection('vk-pay-orders').doc(order_id).get();
if (!orderRes.data.length) {
return { code: -1, msg: '订单不存在' };
}
const order = orderRes.data[0];
if (order.status !== 1) {
return { code: -1, msg: '订单未支付' };
}
// 解析充值积分数量
const attachedData = JSON.parse(order.attached_data || '{}');
const points = attachedData.points;
if (!points) {
return { code: -1, msg: '订单数据异常' };
}
// 增加余额
await db.collection('jjx-user-points').doc(userInfo.uid).update({
balance: _.inc(points),
total_earned: _.inc(points),
update_time: new Date()
});
// 查最新余额
const userRes = await db.collection('jjx-user-points').doc(userInfo.uid).get();
const balance = userRes.data[0].balance;
// 记录流水
await db.collection('jjx-points-log').add({
user_id: userInfo.uid,
type: 'earn',
amount: points,
balance_after: balance,
reason: '积分充值(' + (order.total_fee / 100) + '元)',
biz_type: 'recharge',
biz_id: order_id,
_add_time: new Date()
});
return { code: 0, msg: 'ok', data: { balance, points_added: points } };
}
};