|
@@ -144,6 +144,7 @@ module.exports = app => {
|
|
|
const stagePays = [];
|
|
|
const prePays = await this.getStageLastestPays(preStage);
|
|
|
for (const pp of prePays) {
|
|
|
+ console.log(pp);
|
|
|
const p = this._.find(pays, {id: pp.pid});
|
|
|
if (!p.valid) continue;
|
|
|
stagePays.push({
|
|
@@ -263,9 +264,8 @@ module.exports = app => {
|
|
|
* @return {Promise<Array>} 计算结果(应付和实付数据)
|
|
|
*/
|
|
|
async calcAllStagePays(stage, transaction) {
|
|
|
- if (!stage || !transaction) {
|
|
|
- throw '计算数据错误';
|
|
|
- }
|
|
|
+ if (!stage) throw '计算数据错误';
|
|
|
+
|
|
|
const stagePays = await this.getStagePays(stage);
|
|
|
const PayCalculator = require('../lib/pay_calc');
|
|
|
const payCalculator = new PayCalculator(this.ctx, stage, this.ctx.tender.info);
|
|
@@ -286,9 +286,16 @@ module.exports = app => {
|
|
|
rprice: sp.rprice,
|
|
|
});
|
|
|
}
|
|
|
- await transaction.updateRows(this.tableName, update);
|
|
|
- if (srUpdate.length > 0) {
|
|
|
- await transaction.updateRows(this.ctx.service.pay.tableName, srUpdate);
|
|
|
+ const conn = transaction || await this.db.beginTransaction();
|
|
|
+ try {
|
|
|
+ await conn.updateRows(this.tableName, update);
|
|
|
+ if (srUpdate.length > 0) {
|
|
|
+ await conn.updateRows(this.ctx.service.pay.tableName, srUpdate);
|
|
|
+ }
|
|
|
+ if (!transaction) await conn.commit();
|
|
|
+ } catch (err) {
|
|
|
+ if (!transaction) await conn.rollback();
|
|
|
+ throw '计算合同支付数据错误';
|
|
|
}
|
|
|
const yf = this._.find(stagePays, {ptype: payConst.payType.yf});
|
|
|
const sf = this._.find(stagePays, {ptype: payConst.payType.sf});
|