|
@@ -178,35 +178,22 @@ module.exports = app => {
|
|
|
* @returns {Promise<void>}
|
|
|
*/
|
|
|
async save(saveData) {
|
|
|
- const datas = saveData instanceof Array ? saveData : [saveData];
|
|
|
- const transaction = await this.db.beginTransaction();
|
|
|
- try {
|
|
|
- // 更新数据
|
|
|
- for (const data of datas) {
|
|
|
- const stagePay = await this.getStagePay(this.ctx.stage, data.pid);
|
|
|
- const updateData = { id: stagePay.id };
|
|
|
- if (data.name !== undefined) { updateData.name = data.name }
|
|
|
- if (data.expr !== undefined) { updateData.expr = data.expr }
|
|
|
- if (data.tp !== undefined) { updateData.tp = data.tp }
|
|
|
- if (data.pause !== undefined) { updateData.pause = data.pause }
|
|
|
- const result = await transaction.update(this.tableName, updateData);
|
|
|
- if (result.affectedRows !== 1) {
|
|
|
- throw '保存数据失败';
|
|
|
- }
|
|
|
- // 缓存至pay
|
|
|
- // if (data.expr !== undefined) {
|
|
|
- // const pr = await transaction.update(this.ctx.service.pay.tableName, {
|
|
|
- // id: data.pid, expr: data.expr
|
|
|
- // });
|
|
|
- // if (pr.affectedRows !== 1) {
|
|
|
- // throw '保存数据失败';
|
|
|
- // }
|
|
|
- // }
|
|
|
- }
|
|
|
- await transaction.commit();
|
|
|
- } catch(err) {
|
|
|
- await transaction.rollback();
|
|
|
- throw err;
|
|
|
+ const datas = saveData instanceof Array ? saveData : [saveData], updateDatas = [];
|
|
|
+ const stagePays = await this.getStagePay(this.ctx.stage, this._.map(datas, 'pid'));
|
|
|
+ for (const data of datas) {
|
|
|
+ const stagePay = stagePays.find(function (x) {
|
|
|
+ return x.pid === data.pid;
|
|
|
+ });
|
|
|
+ const updateData = {id: stagePay.id};
|
|
|
+ if (data.name !== undefined) { updateData.name = data.name }
|
|
|
+ if (data.expr !== undefined) { updateData.expr = data.expr }
|
|
|
+ if (data.tp !== undefined) { updateData.tp = data.tp }
|
|
|
+ if (data.pause !== undefined) { updateData.pause = data.pause }
|
|
|
+ updateDatas.push(updateData);
|
|
|
+ }
|
|
|
+ const result = await this.db.updateRows(this.tableName, updateDatas);
|
|
|
+ if (result.affectedRows !== updateDatas.length) {
|
|
|
+ throw '保存数据失败';
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -224,12 +211,24 @@ module.exports = app => {
|
|
|
const PayCalculator = require('../lib/pay_calc');
|
|
|
const payCalculator = new PayCalculator(this.ctx, this.ctx.tender.info.decimal);
|
|
|
await payCalculator.calculateAll(stagePays);
|
|
|
+ const srUpdate = [], update = [];
|
|
|
for (const sp of stagePays) {
|
|
|
- await transaction.update(this.tableName, {
|
|
|
+ update.push({
|
|
|
id: sp.id,
|
|
|
tp: sp.tp,
|
|
|
end_tp: sp.end_tp
|
|
|
});
|
|
|
+ if (stage.order === 1 || sp.csorder >= stage.order) {
|
|
|
+ srUpdate.push({
|
|
|
+ id: sp.pid,
|
|
|
+ sprice: sp.sprice,
|
|
|
+ rprice: sp.rprice,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await transaction.updateRows(this.tableName, update);
|
|
|
+ if (srUpdate.length > 0) {
|
|
|
+ await transaction.updateRows(this.ctx.service.pay.tableName, srUpdate);
|
|
|
}
|
|
|
}
|
|
|
|