Bläddra i källkod

1. 补充lib的单元测试(sms,合同支付计算)
2. 根据1结果,修正合同支付错误代码

MaiXinRong 6 år sedan
förälder
incheckning
688adf606d
4 ändrade filer med 84 tillägg och 8 borttagningar
  1. 1 1
      app/const/deal_pay.js
  2. 9 7
      app/service/stage_pay.js
  3. 49 0
      test/app/lib/pay_calc.test.js
  4. 25 0
      test/app/lib/sms.test.js

+ 1 - 1
app/const/deal_pay.js

@@ -17,7 +17,7 @@ const payType = {
 const payTemplate = [
     {order: 1, name: '本期应付', ptype: payType.yf, minus: false, expr: null, sexpr: null, rexpr: null},
     {order: 2, name: '本期实付', ptype: payType.sf, minus: false},
-    {order: 3, name: '本期计量完成', ptype: payType.wc, minus: false, expr: 'bqwc'},
+    {order: 3, name: '本期完成计量', ptype: payType.wc, minus: false, expr: 'bqwc'},
     {order: 4, name: '质量保证金', ptype: payType.normal, minus: true},
     {order: 5, name: '扣回开工预付款', ptype: payType.normal, minus: true, expr: '(bqwc/htj)*2*kgyfk', sexpr: 'htj*30%', rexpr: 'kgyfk'},
 ];

+ 9 - 7
app/service/stage_pay.js

@@ -129,15 +129,17 @@ module.exports = app => {
          */
         async getStageLastestPays(sid) {
             const sql = 'SELECT SP.*, P.`order`, P.uid, P.name, 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, ( ' +
-                '    SELECT MAX(`times` * ' + timesLen + ' + `order`) As `sprogress` ' +
-                '      FROM ?? ' +
+                '  FROM ' + this.tableName + ' As SP' +
+                '  INNER JOIN ' + this.ctx.service.pay.tableName + ' As P ON SP.pid = P.id' +
+                '  INNER JOIN ( ' +
+                '    SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `sprogress` ' +
+                '      FROM ' + this.tableName +
                 '      WHERE `sid` = ? ' +
-                '      GROUP BY `sid`) As M' +
-                '  WHERE SP.`sid` = ? AND (SP.`stimes` * ' + timesLen + ' + `order`) = M.`sprogress` AND SP.`pid` = P.`id` AND P.`valid` = true' +
+                '      GROUP BY `sid`) As M ON (SP.`stimes` * ' + timesLen + ' + SP.`sorder`) = M.`sprogress`' +
+                '  WHERE SP.`sid` = ? AND P.`valid` = true' +
                 '  ORDER BY P.`order`';
-            const sqlParam = [this.tableName, this.ctx.service.pay.tableName, this.ctx.service.stageAudit.tableName,
-                sid, sid];
+            const sqlParam = [sid, sid];
+            console.log(this.db.format(sql, sqlParam));
             return await this.db.query(sql, sqlParam);
         }
 

+ 49 - 0
test/app/lib/pay_calc.test.js

@@ -0,0 +1,49 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const { app, assert } = require('egg-mock/bootstrap');
+const Calc = require('../../../app/lib/pay_calc');
+const PayConst = require('../../../app/const/deal_pay.js');
+
+describe('test/app/lib/pay_calc.test.js', () => {
+
+    it('test calculate Stage DealPay TotalPrice', function* () {
+        const ctx = app.mockContext();
+        // 模拟登录
+        const postData = {
+            account: '734406061@qq.com',
+            project: 'T201711273363',
+            project_password: 'mai654321',
+        };
+        ctx.session = {};
+        const loginResult = yield ctx.service.projectAccount.accountLogin(postData, 2);
+        assert(loginResult);
+        // 模拟打开标段
+        ctx.tender = {id: 244};
+        ctx.tender.data = yield ctx.service.tender.getTender(ctx.tender.id);
+        ctx.tender.info = yield ctx.service.tenderInfo.getTenderInfo(ctx.tender.id);
+        // 模拟打开期
+        ctx.stage = yield ctx.service.stage.getDataByCondition({
+            id: 43
+        });
+        ctx.stage.curTimes = ctx.stage.times;
+        ctx.stage.curOrder = 0;
+
+        const calc = new Calc(ctx, ctx.tender.info.decimal);
+        const dealPay = yield ctx.service.stagePay.getStageLastestPays(ctx.stage.id);
+        yield calc.calculateAll(dealPay);
+
+        const bqwc = app._.find(dealPay, {ptype: PayConst.payType.wc});
+        assert(bqwc.tp === 26220);
+        const bqyf = app._.find(dealPay, {ptype: PayConst.payType.yf});
+        assert(bqyf.tp === 26220);
+    });
+
+});

+ 25 - 0
test/app/lib/sms.test.js

@@ -0,0 +1,25 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const { app, assert } = require('egg-mock/bootstrap');
+const SMS = require('../../../app/lib/sms');
+
+describe('test/app/lib/sms.test.js', () => {
+
+    it('send message success', function* () {
+        const ctx = app.mockContext();
+        const sms = new SMS(ctx);
+
+        const result = sms.send('15916260139', '测试短信发送');
+        // 验证返回
+        assert(result);
+    });
+
+});