|
@@ -91,31 +91,38 @@ module.exports = app => {
|
|
|
|
|
|
}
|
|
|
|
|
|
- async getLastestStageData2(tid, sid, lid) {
|
|
|
- let lidSql = '',
|
|
|
- result;
|
|
|
- if (lid) {
|
|
|
- if (lid instanceof Array) {
|
|
|
- lidSql = lid.length > 0 ? ' And lid in (' + this.ctx.helper.getInArrStrSqlFilter(lid) + ')' : '';
|
|
|
- } else {
|
|
|
- lidSql = ' And lid in (' + this.db.escape(lid) + ')';
|
|
|
+ _getFilterSql(where, asTable = '') {
|
|
|
+ let whereSql = '';
|
|
|
+ if (!where) return whereSql;
|
|
|
+ if (where.lid) {
|
|
|
+ if (where.lid instanceof Array) {
|
|
|
+ whereSql += ' And ' + asTable + 'lid in (' + this.ctx.helper.getInArrStrSqlFilter(where.lid) + ')';
|
|
|
+ } else if (typeof where.lid === "string") {
|
|
|
+ whereSql += ' And ' + asTable + 'lid = ' + this.db.escape(where.lid);
|
|
|
}
|
|
|
}
|
|
|
- const sql = 'SELECT Bills.* FROM ' + this.tableName + ' As Bills ' +
|
|
|
- ' INNER JOIN ( ' +
|
|
|
- ' SELECT MAX(`times` * ' + timesLen + ' + `order`) As `progress`, `lid`, `sid` From ' + this.tableName +
|
|
|
- ' WHERE tid = ? And sid = ?' + lidSql +
|
|
|
- ' GROUP BY `lid`' +
|
|
|
- ' ) As MaxFilter ' +
|
|
|
- ' ON (Bills.times * ' + timesLen + ' + `order`) = MaxFilter.progress And Bills.lid = MaxFilter.lid And Bills.`sid` = MaxFilter.`sid`';
|
|
|
- const sqlParam = [tid, sid];
|
|
|
- if (!lid) {
|
|
|
- return await this.db.query(sql, sqlParam);
|
|
|
- } else if (lid instanceof Array) {
|
|
|
- return await this.db.query(sql, sqlParam);
|
|
|
- }
|
|
|
- return await this.db.queryOne(sql, sqlParam);
|
|
|
+ return whereSql;
|
|
|
+ }
|
|
|
+
|
|
|
+ async getLastestStageData2(tid, sid, lid) {
|
|
|
+ const condition = { tender_id: tid, sid, lid };
|
|
|
+ if (!lid) delete condition.lid;
|
|
|
+
|
|
|
+ const result = this.db.select(this.departTableName(tid), { where: condition });
|
|
|
+ const stageBills = this.ctx.helper.filterLastestData(result, 'lid');
|
|
|
+ if (!lid || lid instanceof Array) return stageBills;
|
|
|
+ return stageBills[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ async getLastestStageData2(tid, sid, times, order, where) {
|
|
|
+ const filterSql = this._getFilterSql(where);
|
|
|
+ const sql = 'Select * From ' + this.departTableName(tid) +
|
|
|
+ ' Where tender_id = ? and sid = ? And (`times` < ? OR (`times` = ? AND `order` <= ?)) ' + filterSql;
|
|
|
|
|
|
+ const result = this.db.query(sql, [tid, sid, times, times, order]);
|
|
|
+ const stageBills = this.ctx.helper.filterLastestData(result, 'lid');
|
|
|
+ if (!lid || lid instanceof Array) return stageBills;
|
|
|
+ return stageBills[0];
|
|
|
}
|
|
|
|
|
|
async getStageUsedBills(tid, sid) {
|