|
@@ -106,6 +106,9 @@ module.exports = app => {
|
|
|
if (!cpInfo) {
|
|
|
throw '合同' + contractConst.typeName[cpInfo.contract_type] + '不存在';
|
|
|
}
|
|
|
+ if (cpInfo.fpcid) {
|
|
|
+ throw '该合同' + contractConst.typeName[cpInfo.contract_type] + '关联了资金支付明细,不能删除';
|
|
|
+ }
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
|
await transaction.delete(this.tableName, { id: cpid });
|
|
@@ -141,6 +144,49 @@ module.exports = app => {
|
|
|
node.exist_pay = paysList.length === 0 ? 0 : 1;
|
|
|
await transaction.update(this.ctx.service.contract.tableName, node);
|
|
|
}
|
|
|
+
|
|
|
+ async createContractPays(transaction, fpid, uid, times, pays) {
|
|
|
+ const addPays = [];
|
|
|
+ const contracts = await transaction.select(this.ctx.service.contract.tableName, { where: { id: this._.uniq(this._.map(pays, 'cid')) } });
|
|
|
+ for (const p of pays) {
|
|
|
+ const contract = contracts.find(c => c.id === p.cid);
|
|
|
+ if (contract) {
|
|
|
+ addPays.push({
|
|
|
+ spid: contract.spid || null,
|
|
|
+ tid: contract.tid || null,
|
|
|
+ contract_type: contract.contract_type,
|
|
|
+ cid: p.cid,
|
|
|
+ uid,
|
|
|
+ fpid,
|
|
|
+ fpcid: p.id,
|
|
|
+ pay_time: times,
|
|
|
+ pay_price: p.pay_price || 0,
|
|
|
+ debit_price: 0,
|
|
|
+ yf_price: p.pay_price || 0,
|
|
|
+ sf_price: p.settle_price || 0,
|
|
|
+ pay_type: p.pay_type || '',
|
|
|
+ remark: '',
|
|
|
+ create_time: times,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (addPays.length > 0) {
|
|
|
+ await transaction.insert(this.tableName, addPays);
|
|
|
+ for (const c of contracts) {
|
|
|
+ await this.calcContract(transaction, c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async removeContractPays(transaction, fpid, pays) {
|
|
|
+ await transaction.delete(this.tableName, { fpid });
|
|
|
+ const contracts = await transaction.select(this.ctx.service.contract.tableName, { where: { id: this._.uniq(this._.map(pays, 'cid')) } });
|
|
|
+ if (contracts.length > 0) {
|
|
|
+ for (const c of contracts) {
|
|
|
+ await this.calcContract(transaction, c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return ContractPay;
|
|
|
};
|