material_stage.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. /**
  3. * 调差表(多期独立单价使用) 数据模型
  4. *
  5. * @author Mai
  6. * @date 2018/8/13
  7. * @version
  8. */
  9. module.exports = app => {
  10. class MaterialStage extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'material_stage';
  20. }
  21. async updateMtp(transaction, id) {
  22. const sql = 'SELECT SUM(`m_tp`) as total_price, SUM(IF(`m_tax_tp` is null, `m_tp`, `m_tax_tp`)) as tax_total_price FROM ' + this.ctx.service.materialStageBills.tableName + ' WHERE `tid` = ? AND `ms_id` = ? AND `is_summary` = 1';
  23. const sqlParam = [this.ctx.tender.id, id];
  24. const tp = await transaction.queryOne(sql, sqlParam);
  25. const updateData2 = {
  26. id,
  27. m_tp: tp.total_price,
  28. m_tax_tp: tp.tax_total_price,
  29. };
  30. return await transaction.update(this.tableName, updateData2);
  31. }
  32. }
  33. return MaterialStage;
  34. };