shenpi_audit.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. /**
  3. * 版本数据模型
  4. *
  5. * @author CaiAoLin
  6. * @date 2017/10/25
  7. * @version
  8. */
  9. module.exports = app => {
  10. class ShenpiAudit extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'shenpi_audit';
  20. }
  21. async getAudit(tid, type, status) {
  22. const sql = 'SELECT sp.audit_id, pa.name FROM ?? AS sp LEFT JOIN ?? AS pa ON sp.audit_id = pa.id' +
  23. ' WHERE sp.tid = ? AND sp.sp_type = ? AND sp.sp_status = ?';
  24. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid, type, status];
  25. return await this.db.queryOne(sql, sqlParam);
  26. }
  27. async getAuditList(tid, type, status) {
  28. const sql = 'SELECT sp.audit_id, pa.name FROM ?? AS sp LEFT JOIN ?? AS pa ON sp.audit_id = pa.id' +
  29. ' WHERE sp.tid = ? AND sp.sp_type = ? AND sp.sp_status = ? ORDER BY sp.id ASC';
  30. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid, type, status];
  31. return await this.db.query(sql, sqlParam);
  32. }
  33. async addAudit(data) {
  34. const insertData = {
  35. tid: this.ctx.tender.id,
  36. sp_type: data.code,
  37. sp_status: data.status,
  38. audit_id: data.audit_id,
  39. };
  40. const result = await this.db.insert(this.tableName, insertData);
  41. return result.effectRows === 1;
  42. }
  43. async removeAudit(data) {
  44. const delData = {
  45. tid: this.ctx.tender.id,
  46. sp_type: data.code,
  47. sp_status: data.status,
  48. audit_id: data.audit_id,
  49. };
  50. return await this.db.delete(this.tableName, delData);
  51. }
  52. }
  53. return ShenpiAudit;
  54. };