You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
4.4 KiB
131 lines
4.4 KiB
'use strict';
|
|
|
|
module.exports.getBalance = async (ctx) => {
|
|
try {
|
|
const service = ctx?.app?.fs?.aideductService;
|
|
if (!service?.getBalance) throw '飞尚扣费服务未初始化';
|
|
|
|
const payload = { ...(ctx?.request?.query || {}), ...(ctx?.request?.body || {}) };
|
|
const { userId, user_id: userIdSnake } = payload;
|
|
const result = await service.getBalance({ userId: userId || userIdSnake });
|
|
ctx.status = 200;
|
|
ctx.body = result;
|
|
} catch (error) {
|
|
ctx.logger.log(error);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: typeof error === 'string' ? error : (error?.message || '余额查询失败'),
|
|
};
|
|
}
|
|
};
|
|
|
|
module.exports.getUserInfo = async (ctx) => {
|
|
try {
|
|
const service = ctx?.app?.fs?.aideductService;
|
|
if (!service?.getUserInfo) throw '飞尚扣费服务未初始化';
|
|
|
|
const payload = { ...(ctx?.request?.query || {}), ...(ctx?.request?.body || {}) };
|
|
const { userId, user_id: userIdSnake } = payload;
|
|
const result = await service.getUserInfo({ userId: userId || userIdSnake });
|
|
ctx.status = 200;
|
|
ctx.body = result;
|
|
} catch (error) {
|
|
ctx.logger.log(error);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: typeof error === 'string' ? error : (error?.message || '用户信息查询失败'),
|
|
};
|
|
}
|
|
};
|
|
|
|
module.exports.preDeduct = async (ctx) => {
|
|
try {
|
|
const service = ctx?.app?.fs?.aideductService;
|
|
if (!service?.preDeduct) throw '飞尚扣费服务未初始化';
|
|
|
|
const payload = { ...(ctx?.request?.query || {}), ...(ctx?.request?.body || {}) };
|
|
const { userId, user_id: userIdSnake, amount, requestId, request_id: requestIdSnake } = payload;
|
|
const result = await service.preDeduct({
|
|
userId: userId || userIdSnake,
|
|
amount,
|
|
requestId: requestId || requestIdSnake,
|
|
});
|
|
ctx.status = 200;
|
|
ctx.body = result;
|
|
} catch (error) {
|
|
ctx.logger.log(error);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: typeof error === 'string' ? error : (error?.message || '预扣费失败'),
|
|
};
|
|
}
|
|
};
|
|
|
|
module.exports.confirmDeduct = async (ctx) => {
|
|
try {
|
|
const service = ctx?.app?.fs?.aideductService;
|
|
if (!service?.confirmDeduct) throw '飞尚扣费服务未初始化';
|
|
|
|
const payload = { ...(ctx?.request?.query || {}), ...(ctx?.request?.body || {}) };
|
|
const { userId, user_id: userIdSnake, amount, requestId, request_id: requestIdSnake } = payload;
|
|
const result = await service.confirmDeduct({
|
|
userId: userId || userIdSnake,
|
|
amount,
|
|
requestId: requestId || requestIdSnake,
|
|
});
|
|
ctx.status = 200;
|
|
ctx.body = result;
|
|
} catch (error) {
|
|
ctx.logger.log(error);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: typeof error === 'string' ? error : (error?.message || '确认扣费失败'),
|
|
};
|
|
}
|
|
};
|
|
|
|
module.exports.rollbackDeduct = async (ctx) => {
|
|
try {
|
|
const service = ctx?.app?.fs?.aideductService;
|
|
if (!service?.rollbackDeduct) throw '飞尚扣费服务未初始化';
|
|
|
|
const payload = { ...(ctx?.request?.query || {}), ...(ctx?.request?.body || {}) };
|
|
const { userId, user_id: userIdSnake, amount, requestId, request_id: requestIdSnake } = payload;
|
|
const result = await service.rollbackDeduct({
|
|
userId: userId || userIdSnake,
|
|
amount,
|
|
requestId: requestId || requestIdSnake,
|
|
});
|
|
ctx.status = 200;
|
|
ctx.body = result;
|
|
} catch (error) {
|
|
ctx.logger.log(error);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: typeof error === 'string' ? error : (error?.message || '回退扣费失败'),
|
|
};
|
|
}
|
|
};
|
|
|
|
module.exports.rechargeBalance = async (ctx) => {
|
|
try {
|
|
const service = ctx?.app?.fs?.aideductService;
|
|
if (!service?.rechargeBalance) throw '飞尚扣费服务未初始化';
|
|
|
|
const payload = { ...(ctx?.request?.query || {}), ...(ctx?.request?.body || {}) };
|
|
const { userId, user_id: userIdSnake, amount, requestId, request_id: requestIdSnake } = payload;
|
|
const result = await service.rechargeBalance({
|
|
userId: userId || userIdSnake,
|
|
amount,
|
|
requestId: requestId || requestIdSnake,
|
|
});
|
|
ctx.status = 200;
|
|
ctx.body = result;
|
|
} catch (error) {
|
|
ctx.logger.log(error);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: typeof error === 'string' ? error : (error?.message || '余额充值失败'),
|
|
};
|
|
}
|
|
};
|
|
|