浏览代码

优化查询

MaiXinRong 3 年之前
父节点
当前提交
4411c87ca4
共有 1 个文件被更改,包括 8 次插入4 次删除
  1. 8 4
      app/service/stage_pay.js

+ 8 - 4
app/service/stage_pay.js

@@ -38,10 +38,12 @@ module.exports = app => {
         async getAuditorStagePay(pid, sid, times, order) {
             const pidSql = pid instanceof Array ? ' And SP.`pid` in (' + pid.join(',') + ')' : 'And SP.`pid` = ' + pid;
             const sql = 'SELECT SP.*, P.`csorder`, P.`cstimes`, P.`csaorder`, 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 ?? As SP, ?? As P ' +
+                '  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 +
                 '  ORDER BY P.`order`';
-            const sqlParam = [this.tableName, this.ctx.service.pay.tableName, sid, times, order, pid];
+            const sqlParam = [sid, times, order, pid];
             if (pid instanceof Array) {
                 return await this.db.query(sql, sqlParam);
             } else {
@@ -61,10 +63,12 @@ module.exports = app => {
             const sql = 'SELECT SP.*,' +
                 '    P.`csorder`, P.`cstimes`, P.`csaorder`, 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, P.name as pName ' +
-                '  FROM ?? As SP, ?? As P ' +
+                '  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`' +
                 '  ORDER BY P.`order`';
-            const sqlParam = [this.tableName, this.ctx.service.pay.tableName, sid, times, order];
+            const sqlParam = [sid, times, order];
             return await this.db.query(sql, sqlParam);
         }