change_audit_list.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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, Sum(cb.samount + 0) 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. return ChangeAuditList;
  37. };