change_audit_list.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/8/14
  7. * @version
  8. */
  9. const audit = require('../const/audit');
  10. module.exports = app => {
  11. class ChangeAuditList extends app.BaseService {
  12. /**
  13. * 构造函数
  14. *
  15. * @param {Object} ctx - egg全局变量
  16. * @return {void}
  17. */
  18. constructor(ctx) {
  19. super(ctx);
  20. this.tableName = 'change_audit_list';
  21. }
  22. async gatherBgBills(tid) {
  23. const sql = 'SELECT cb.code, cb.name, cb.unit, cb.unit_price, Round(Sum(cb.samount + 0), 6) as quantity' +
  24. ' FROM ' + this.tableName + ' cb' +
  25. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON cb.cid = c.cid' +
  26. ' WHERE cb.tid = ? and c.status = ?' +
  27. ' GROUP BY code, name, unit, unit_price';
  28. const param = [tid, audit.flow.status.checked];
  29. const result = await this.db.query(sql, param);
  30. for (const b of result) {
  31. b.total_price = this.ctx.helper.mul(b.unit_price, b.quantity, this.ctx.tender.info.decimal.tp);
  32. }
  33. return result;
  34. }
  35. /**
  36. * 报表用
  37. * Tony Kang
  38. * @param {tid} tid - 标段id
  39. * @return {void}
  40. */
  41. async getChangeAuditBills(tid) {
  42. const sql = 'SELECT cb.*' +
  43. ' FROM ' + this.tableName + ' cb' +
  44. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON cb.cid = c.cid' +
  45. ' WHERE c.tid = ? and c.status = 3' +
  46. ' ORDER BY cb.cid, cb.code';
  47. const param = [tid];
  48. const result = await this.db.query(sql, param);
  49. return result;
  50. }
  51. }
  52. return ChangeAuditList;
  53. };