|
@@ -384,9 +384,9 @@ module.exports = app => {
|
|
|
case 4: // 终止(所有的)
|
|
|
sql =
|
|
|
'SELECT a.* FROM ?? AS a WHERE ' +
|
|
|
- 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid) AND ' +
|
|
|
- 'a.status = ? AND a.tid = ?' + stateSql;
|
|
|
- sqlParam = [this.tableName, this.ctx.service.changeAudit.tableName, this.ctx.session.sessionUser.accountId, status, tenderId];
|
|
|
+ 'a.status = ? AND a.tid = ?' + stateSql +
|
|
|
+ (this.ctx.session.sessionUser.is_admin ? '' : ' AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid)');
|
|
|
+ sqlParam = [this.tableName, status, tenderId, this.ctx.service.changeAudit.tableName, this.ctx.session.sessionUser.accountId];
|
|
|
break;
|
|
|
case 3: // 已完成(所有的)
|
|
|
sql = 'SELECT a.* FROM ?? AS a WHERE a.status = ? AND a.tid = ?' + stateSql;
|
|
@@ -485,8 +485,9 @@ module.exports = app => {
|
|
|
case 4: // 终止(所有的)
|
|
|
const sql3 =
|
|
|
'SELECT count(*) AS count FROM ?? AS a WHERE ' +
|
|
|
- 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid) AND a.status = ? AND a.tid = ?' + stateSql;
|
|
|
- const sqlParam3 = [this.tableName, this.ctx.service.changeAudit.tableName, this.ctx.session.sessionUser.accountId, status, tenderId];
|
|
|
+ 'a.status = ? AND a.tid = ?' + stateSql +
|
|
|
+ (this.ctx.session.sessionUser.is_admin ? '' : ' AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid)');
|
|
|
+ const sqlParam3 = [this.tableName, status, tenderId, this.ctx.service.changeAudit.tableName, this.ctx.session.sessionUser.accountId];
|
|
|
const result3 = await this.db.query(sql3, sqlParam3);
|
|
|
return result3[0].count;
|
|
|
case 3: // 已完成(所有的)
|
|
@@ -499,9 +500,10 @@ module.exports = app => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async getTp(tenderId, status) {
|
|
|
+ async getTp(tenderId, status, state) {
|
|
|
+ const stateSql = state ? ' AND a.state = ' + state : '';
|
|
|
if ((this.ctx.tender.isTourist || this.ctx.session.sessionUser.is_admin) && status === 0) {
|
|
|
- const sql5 = 'SELECT SUM(cast (total_price as decimal(18,6))) AS total_price FROM ?? WHERE tid = ?';
|
|
|
+ const sql5 = 'SELECT SUM(cast (total_price as decimal(18,6))) AS total_price FROM ?? AS a WHERE a.tid = ?' + stateSql;
|
|
|
const sqlParam5 = [this.tableName, tenderId];
|
|
|
const result5 = await this.db.query(sql5, sqlParam5);
|
|
|
return result5[0].total_price ? result5[0].total_price : 0;
|
|
@@ -512,7 +514,7 @@ module.exports = app => {
|
|
|
'SELECT SUM(cast (a.total_price as decimal(18,6))) AS total_price FROM ?? AS a WHERE a.tid = ? AND ' +
|
|
|
'(a.uid = ? OR (a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid))' +
|
|
|
' OR (a.status = ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times - 1 = b.times GROUP BY b.cid))' +
|
|
|
- ' OR a.status = ? )';
|
|
|
+ ' OR a.status = ? )' + stateSql;
|
|
|
const sqlParam = [
|
|
|
this.tableName,
|
|
|
tenderId,
|
|
@@ -528,29 +530,28 @@ module.exports = app => {
|
|
|
const result = await this.db.query(sql, sqlParam);
|
|
|
return result[0].total_price ? result[0].total_price : 0;
|
|
|
case 1: // 待处理(你的)
|
|
|
- const sql6 = 'SELECT SUM(cast (a.total_price as decimal(18,6))) AS total_price FROM ?? as a WHERE cid in(SELECT b.cid FROM ?? as b WHERE tid = ? AND uid = ? AND status = ?)';
|
|
|
+ const sql6 = 'SELECT SUM(cast (a.total_price as decimal(18,6))) AS total_price FROM ?? as a WHERE cid in(SELECT b.cid FROM ?? as b WHERE tid = ? AND uid = ? AND status = ?)' + stateSql;
|
|
|
const sqlParam6 = [this.tableName, this.ctx.service.changeAudit.tableName, tenderId, this.ctx.session.sessionUser.accountId, audit.change.status.checking];
|
|
|
const result6 = await this.db.query(sql6, sqlParam6);
|
|
|
return result6[0].total_price ? result6[0].total_price : 0;
|
|
|
case 5: // 待上报(所有的)PS:取未上报,退回,修订的变更令
|
|
|
const sql2 =
|
|
|
'SELECT SUM(cast (a.total_price as decimal(18,6))) AS total_price FROM ?? AS a WHERE' +
|
|
|
- ' ((a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid))' +
|
|
|
- ' OR (a.status = ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times - 1 = b.times GROUP BY b.cid)))' +
|
|
|
- // 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid) ' +
|
|
|
- ' AND (a.status = ? OR a.status = ? OR a.status = ?) AND a.tid = ?';
|
|
|
+ ' (a.status = ? OR a.status = ? OR a.status = ?) AND a.tid = ?' + stateSql +
|
|
|
+ (this.ctx.session.sessionUser.is_admin ? '' : ' AND ((a.status != ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid))' +
|
|
|
+ ' OR (a.status = ? AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times - 1 = b.times GROUP BY b.cid)))');
|
|
|
const sqlParam2 = [
|
|
|
this.tableName,
|
|
|
audit.change.status.uncheck,
|
|
|
+ audit.change.status.checkNo,
|
|
|
+ audit.change.status.revise,
|
|
|
+ tenderId,
|
|
|
+ audit.change.status.uncheck,
|
|
|
this.ctx.service.changeAudit.tableName,
|
|
|
this.ctx.session.sessionUser.accountId,
|
|
|
audit.change.status.checkNo,
|
|
|
this.ctx.service.changeAudit.tableName,
|
|
|
this.ctx.session.sessionUser.accountId,
|
|
|
- audit.change.status.uncheck,
|
|
|
- audit.change.status.checkNo,
|
|
|
- audit.change.status.revise,
|
|
|
- tenderId,
|
|
|
];
|
|
|
const result2 = await this.db.query(sql2, sqlParam2);
|
|
|
return result2[0].total_price ? result2[0].total_price : 0;
|
|
@@ -558,12 +559,13 @@ module.exports = app => {
|
|
|
case 4: // 终止(所有的)
|
|
|
const sql3 =
|
|
|
'SELECT SUM(cast (a.total_price as decimal(18,6))) AS total_price FROM ?? AS a WHERE ' +
|
|
|
- 'a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid) AND a.status = ? AND a.tid = ?';
|
|
|
- const sqlParam3 = [this.tableName, this.ctx.service.changeAudit.tableName, this.ctx.session.sessionUser.accountId, status, tenderId];
|
|
|
+ 'a.status = ? AND a.tid = ?' + stateSql +
|
|
|
+ (this.ctx.session.sessionUser.is_admin ? '' : ' AND a.cid IN (SELECT b.cid FROM ?? AS b WHERE b.uid = ? AND a.times = b.times GROUP BY b.cid)');
|
|
|
+ const sqlParam3 = [this.tableName, status, tenderId, this.ctx.service.changeAudit.tableName, this.ctx.session.sessionUser.accountId];
|
|
|
const result3 = await this.db.query(sql3, sqlParam3);
|
|
|
return result3[0].total_price ? result3[0].total_price : 0;
|
|
|
case 3: // 已完成(所有的)
|
|
|
- const sql4 = 'SELECT SUM(cast (total_price as decimal(18,6))) AS total_price FROM ?? WHERE status = ? AND tid = ?';
|
|
|
+ const sql4 = 'SELECT SUM(cast (total_price as decimal(18,6))) AS total_price FROM ?? AS a WHERE a.status = ? AND a.tid = ?' + stateSql;
|
|
|
const sqlParam4 = [this.tableName, status, tenderId];
|
|
|
const result4 = await this.db.query(sql4, sqlParam4);
|
|
|
return result4[0].total_price ? result4[0].total_price : 0;
|