stage.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. /**
  3. * 期计量 数据模型
  4. *
  5. * @author Mai
  6. * @date 2018/8/13
  7. * @version
  8. */
  9. const audit = require('../const/audit');
  10. module.exports = app => {
  11. class Stage extends app.BaseService {
  12. /**
  13. * 构造函数
  14. *
  15. * @param {Object} ctx - egg全局变量
  16. * @return {void}
  17. */
  18. constructor(ctx) {
  19. super(ctx);
  20. this.tableName = 'stage';
  21. }
  22. /**
  23. *
  24. * @param tenderId - 标段id
  25. * @param name - 期名称
  26. * @param time - 计量时间
  27. * @returns {Promise<void>}
  28. */
  29. async add(tenderId, name, time) {
  30. const stages = await this.getAllDataByCondition({
  31. where: {tid: tenderId},
  32. order: ['order'],
  33. });
  34. const order = stages.length + 1;
  35. const newStage = {
  36. sid: this.uuid.v4(),
  37. tid: tenderId,
  38. order: order,
  39. name: name,
  40. in_time: new Date(),
  41. s_time: time,
  42. times: 1,
  43. status: audit.flow.status.uncheck,
  44. };
  45. const result = await this.db.insert(this.tableName, newStage);
  46. console.log(result);
  47. return result.affectedRows === 1 ? newStage : null;
  48. }
  49. }
  50. return Stage;
  51. };