Browse Source

变更金额更新判断

laiguoran 3 năm trước cách đây
mục cha
commit
b52bdea0fd
3 tập tin đã thay đổi với 23 bổ sung2 xóa
  1. 4 1
      app/middleware/change_check.js
  2. 15 0
      app/service/change.js
  3. 4 1
      app/service/change_audit_list.js

+ 4 - 1
app/middleware/change_check.js

@@ -61,8 +61,11 @@ module.exports = options => {
             } else { // 其他不可见
                 throw '您无权查看该数据';
             }
-
             this.change = change;
+            if ((change.status === status.uncheck || change.status === status.back || change.status === status.revise) && change.tp_decimal !== this.tender.info.decimal.tp) {
+                this.change.tp_decimal = this.tender.info.decimal.tp;
+                yield this.service.change.updateDecimalAndTp();
+            }
             yield next;
         } catch (err) {
             console.log(err);

+ 15 - 0
app/service/change.js

@@ -105,6 +105,7 @@ module.exports = app => {
                     in_time: new Date(),
                     code,
                     name,
+                    tp_decimal: this.ctx.tender.info.decimal.tp,
                 };
                 const operate = await this.transaction.insert(this.tableName, change);
 
@@ -1623,6 +1624,20 @@ module.exports = app => {
                 cid,
             });
         }
+
+        async updateDecimalAndTp() {
+            // 判断是否可修改
+            // 判断t_type是否为费用
+            const transaction = await this.db.beginTransaction();
+            try {
+                await this.ctx.service.changeAuditList.calcCamountSum(transaction, true);
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
     }
 
     return Change;

+ 4 - 1
app/service/change_audit_list.js

@@ -297,7 +297,7 @@ module.exports = app => {
             }
         }
 
-        async calcCamountSum(transaction) {
+        async calcCamountSum(transaction, updateTpDecimal = false) {
             // const sql = 'SELECT SUM(ROUND(`camount`*`unit_price`, )) as total_price FROM ?? WHERE cid = ?';
             // const sqlParam = [this.tableName, this.change.cid];
             // const tp = await transaction.queryOne(sql, sqlParam);
@@ -313,6 +313,9 @@ module.exports = app => {
             const updateData = {
                 total_price,
             };
+            if (updateTpDecimal) {
+                updateData.tp_decimal = tp_decimal;
+            }
             const options = {
                 where: {
                     cid: this.ctx.change.cid,