|
@@ -41,7 +41,7 @@ module.exports = app => {
|
|
|
' FROM ' + this.tableName + ' As SP ' +
|
|
|
' LEFT JOIN ' + this.ctx.service.pay.tableName + ' As P ' +
|
|
|
' ON SP.pid = P.id' +
|
|
|
- ' WHERE SP.`sid` = ? AND SP.`stimes` = ? AND SP.`sorder` = ? AND SP.`pid` = P.`id` AND P.`valid`' + pidSql +
|
|
|
+ ' WHERE SP.`sid` = ? AND SP.`stimes` = ? AND SP.`sorder` = ? AND SP.`pid` = P.`id` AND (P.`valid` || SP.porder > 0)' + pidSql +
|
|
|
' ORDER BY P.`order`';
|
|
|
const sqlParam = [sid, times, order, pid];
|
|
|
if (pid instanceof Array) {
|
|
@@ -66,7 +66,7 @@ module.exports = app => {
|
|
|
' FROM ' + this.tableName + ' As SP ' +
|
|
|
' LEFT JOIN ' + this.ctx.service.pay.tableName + ' As P ' +
|
|
|
' ON SP.pid = P.id' +
|
|
|
- ' WHERE SP.`sid` = ? AND SP.`stimes` = ? AND SP.`sorder` = ? AND SP.`pid` = P.`id` AND P.`valid`' +
|
|
|
+ ' WHERE SP.`sid` = ? AND SP.`stimes` = ? AND SP.`sorder` = ? AND SP.`pid` = P.`id` AND (P.`valid` || SP.porder > 0)' +
|
|
|
' ORDER BY P.`order`';
|
|
|
const sqlParam = [sid, times, order];
|
|
|
return await this.db.query(sql, sqlParam);
|
|
@@ -100,7 +100,7 @@ module.exports = app => {
|
|
|
if (!preStage) {
|
|
|
throw '标段数据有误';
|
|
|
}
|
|
|
- const prePays = await this.getStageLastestPays(preStage.id);
|
|
|
+ const prePays = await this.getStageLastestPays(preStage);
|
|
|
for (const pp of prePays) {
|
|
|
const p = this._.find(pays, {id: pp.pid});
|
|
|
stagePays.push({
|
|
@@ -158,10 +158,10 @@ module.exports = app => {
|
|
|
/**
|
|
|
* 获取某期最后数据(不限制该期是否已经审批通过)
|
|
|
*
|
|
|
- * @param {Number} sid - 期id
|
|
|
+ * @param {Number} stage - 期数据(通过StageController._getStageData()获取)
|
|
|
* @returns {Promise<*>}
|
|
|
*/
|
|
|
- async getStageLastestPays(sid) {
|
|
|
+ async getStageLastestPays(stage) {
|
|
|
const sql = 'SELECT SP.*, P.`order`, P.uid, P.minus, P.ptype, P.sprice, P.sexpr, P.rprice, P.rexpr, P.is_yf, P.dl_type, P.dl_count, P.dl_tp_type, P.dl_tp ' +
|
|
|
' FROM ' + this.tableName + ' As SP' +
|
|
|
' INNER JOIN ' + this.ctx.service.pay.tableName + ' As P ON SP.pid = P.id' +
|
|
@@ -170,10 +170,11 @@ module.exports = app => {
|
|
|
' FROM ' + this.tableName +
|
|
|
' WHERE `sid` = ? ' +
|
|
|
' GROUP BY `sid`) As M ON (SP.`stimes` * ' + timesLen + ' + SP.`sorder`) = M.`sprogress`' +
|
|
|
- ' WHERE SP.`sid` = ? AND P.`valid` = true' +
|
|
|
+ ' WHERE SP.`sid` = ? AND (P.`valid` || SP.porder > 0)' +
|
|
|
' ORDER BY P.`order`';
|
|
|
- const sqlParam = [sid, sid];
|
|
|
+ const sqlParam = [stage.id, stage.id];
|
|
|
const result = await this.db.query(sql, sqlParam);
|
|
|
+ this.resortStagePays(stage, result);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -279,7 +280,7 @@ module.exports = app => {
|
|
|
async getHistorySf(stage) {
|
|
|
if (!stage) return 0;
|
|
|
const stagePays = stage.status === auditConst.stage.status.checked
|
|
|
- ? await this.getStageLastestPays(stage.id)
|
|
|
+ ? await this.getStageLastestPays(stage)
|
|
|
: await this.getStagePays(stage);
|
|
|
const sf = this._.find(stagePays, {ptype: payConst.payType.sf});
|
|
|
return sf;
|
|
@@ -496,7 +497,7 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
async cacheOrder(stage, transaction) {
|
|
|
- const sql = `UPDATE ${this.tableName} sp LEFT JOIN ${this.ctx.service.pay.tableName} p ON sp.pid = p.id SET sp.porder = p.\`order\` Where sp.sid = ?`;
|
|
|
+ const sql = `UPDATE ${this.tableName} sp LEFT JOIN ${this.ctx.service.pay.tableName} p ON sp.pid = p.id SET sp.porder = p.\`order\` Where sp.sid = ? AND p.valid`;
|
|
|
await transaction.query(sql, [stage.id]);
|
|
|
}
|
|
|
}
|