import BaseService from "../baseService";
|
import { FinanceBankBiz } from "../../entity/finance/biz/financeBankBiz";
|
import { ResultInfo } from "../../public/commonInterface";
|
import { FinanceBankAccount } from "../../entity/finance/base/financeBankAccount";
|
import { FinanceFlow } from "../../entity/finance/base/financeFlow";
|
|
/**
|
*账户间存取款
|
*/
|
export default class BankBizService extends BaseService {
|
//#region 批量审核和编辑页面中审核都是执行此方法
|
public async batchAuditing(): Promise<ResultInfo> {
|
let { ctx } = this;
|
let body = ctx.request.body;
|
let userInfo = await ctx.helper.userInfo();
|
try {
|
let idValues = body.idValues;
|
if (!Array.isArray(idValues)) {
|
this.info.result = false;
|
this.info.msg = "没有可执行的数据";
|
return this.info;
|
}
|
for (var idValue of idValues) {
|
let dataInfo = await this.dbRead.findOne(FinanceBankBiz, idValue);
|
if (!dataInfo) {
|
this.info.result = false;
|
this.info.msg = "单据不存在";
|
return this.info;
|
}
|
if (dataInfo.banStatus != "新建") {
|
this.info.result = false;
|
this.info.msg = "只有新建的单子才允许审核";
|
return this.info;
|
}
|
if (dataInfo.auditing !== 0) {
|
this.info.result = false;
|
this.info.msg = "只有新建的单子才允许审核";
|
return this.info;
|
}
|
await this.dbWrite.update(
|
FinanceBankBiz,
|
{
|
bankBiz_Id: dataInfo.bankBiz_Id,
|
userProduct_Id: userInfo.userProduct_Id
|
},
|
{
|
banStatus: "审核成功",
|
auditing: 2,
|
auditor: userInfo.userTrueName,
|
auditDate: new Date()
|
}
|
);
|
// 账户流水
|
await this.dbRead.findOne(FinanceFlow, {
|
where: {
|
bankAccount_Id: dataInfo.bankAccount_Id || dataInfo.bankAccount_Id_In
|
},
|
order: {
|
bankAccount_Id: "DESC"
|
}
|
});
|
//转入账户
|
if (dataInfo.moneyRMB) {
|
let bankAccountList_In = await this.dbRead.findOne(FinanceBankAccount, {
|
where: {
|
//转入id_In
|
bankAccount_Id: dataInfo.bankAccount_Id_In
|
}
|
});
|
const currentRMB_In = (bankAccountList_In.currentRMB += dataInfo.moneyRMB);
|
await this.dbWrite.update(
|
FinanceBankAccount,
|
{
|
//转入id_In
|
bankAccount_Id: dataInfo.bankAccount_Id_In
|
},
|
{
|
currentRMB: currentRMB_In
|
}
|
);
|
//生成转入账户流水
|
let newFlow = new FinanceFlow();
|
newFlow.flowCode = await this.ctx.service.common.getCodeRegular(1698);
|
newFlow.flowName = "转入账户";
|
newFlow.bankAccountCode = bankAccountList_In.bankAccountCode;
|
newFlow.bankAccountName = bankAccountList_In.bankAccountName;
|
newFlow.billCode = bankAccountList_In.bankAccount;
|
newFlow.incomeRMB = dataInfo.moneyRMB;
|
newFlow.outcomeRMB = 0;
|
newFlow.balanceRMB = bankAccountList_In.currentRMB;
|
newFlow.sourceType = "转入金额";
|
|
newFlow.userTrueName = userInfo.userTrueName;
|
newFlow.deptName = userInfo.deptName;
|
await this.setAccountInfo(newFlow);
|
await this.dbWrite.save(newFlow);
|
}
|
//转出账户
|
let bankAccountList = await this.dbRead.findOne(FinanceBankAccount, {
|
where: {
|
bankAccount_Id: dataInfo.bankAccount_Id
|
}
|
});
|
if (dataInfo.moneyRMB <= bankAccountList.currentRMB) {
|
const currentRMB = (bankAccountList.currentRMB -= dataInfo.moneyRMB);
|
await this.dbWrite.update(
|
FinanceBankAccount,
|
{
|
bankAccount_Id: dataInfo.bankAccount_Id
|
},
|
{
|
currentRMB: currentRMB
|
}
|
);
|
// 生成转出流水
|
let newFlow = new FinanceFlow();
|
newFlow.flowCode = await this.ctx.service.common.getCodeRegular(1698);
|
newFlow.flowName = "转出账户";
|
newFlow.bankAccountCode = bankAccountList.bankAccountCode;
|
newFlow.bankAccountName = bankAccountList.bankAccountName;
|
newFlow.billCode = bankAccountList.bankAccount;
|
newFlow.incomeRMB = 0;
|
newFlow.outcomeRMB = dataInfo.moneyRMB;
|
newFlow.balanceRMB = bankAccountList.currentRMB;
|
newFlow.sourceType = "转出金额";
|
|
newFlow.userTrueName = userInfo.userTrueName;
|
newFlow.deptName = userInfo.deptName;
|
await this.setAccountInfo(newFlow);
|
await this.dbWrite.save(newFlow);
|
} else {
|
this.info.result = false;
|
this.info.msg = "余额不足无法进行转出";
|
return this.info;
|
}
|
}
|
this.info.result = true;
|
this.info.msg = "审核成功";
|
} catch (error) {
|
this.info.result = false;
|
this.info.msg = "审核失败" + error.message;
|
}
|
return this.info;
|
}
|
//#endregion
|
}
|