change.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Change 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';
  21. }
  22. async add(tenderId, userId, code, name) {
  23. const count = await this.count({tid: tenderId, code: code});
  24. if (count > 0) {
  25. throw '变更令号重复';
  26. }
  27. const change = {
  28. cid: this.uuid.v4(),
  29. tid: tenderId,
  30. uid: userId,
  31. status: audit.flow.status.uncheck,
  32. times: 1,
  33. valid: true,
  34. in_time: new Date(),
  35. code: code,
  36. name: name,
  37. };
  38. await this.db.insert(this.tableName, change);
  39. return change;
  40. }
  41. async pendingDatas(tenderId, userId) {
  42. return await this.getAllDataByCondition({
  43. tid: tenderId,
  44. uid: userId,
  45. status: audit.flow.status.checking,
  46. });
  47. }
  48. async uncheckDatas(tenderId, userId) {
  49. return await this.getAllDataByCondition({
  50. tid: tenderId,
  51. uid: userId,
  52. status: audit.flow.status.uncheck,
  53. });
  54. }
  55. async checkingDatas(tenderId, userId) {
  56. return await this.getAllDataByCondition({
  57. tid: tenderId,
  58. uid: userId,
  59. status: audit.flow.status.checking,
  60. });
  61. }
  62. async checkedDatas(tenderId, userId) {
  63. return await this.getAllDataByCondition({
  64. tid: tenderId,
  65. uid: userId,
  66. status: audit.flow.status.checked,
  67. });
  68. }
  69. async checkNoDatas(tenderId, userId) {
  70. return await this.getAllDataByCondition({
  71. tid: tenderId,
  72. uid: userId,
  73. status: audit.flow.status.checkNo,
  74. });
  75. }
  76. async checkNoCount(tenderId, userId) {
  77. return await this.count({
  78. tid: tenderId,
  79. uid: userId,
  80. status: audit.flow.status.checkNo,
  81. });
  82. }
  83. }
  84. return Change;
  85. };