'use strict'; /** * 期计量 数据模型 * * @author Mai * @date 2018/8/13 * @version */ const audit = require('../const/audit'); module.exports = app => { class Stage extends app.BaseService { /** * 构造函数 * * @param {Object} ctx - egg全局变量 * @return {void} */ constructor(ctx) { super(ctx); this.tableName = 'stage'; } /** * * @param tenderId - 标段id * @param name - 期名称 * @param time - 计量时间 * @returns {Promise} */ async add(tenderId, name, time) { const stages = await this.getAllDataByCondition({ where: {tid: tenderId}, order: ['order'], }); const order = stages.length + 1; const newStage = { sid: this.uuid.v4(), tid: tenderId, order: order, name: name, in_time: new Date(), s_time: time, times: 1, status: audit.flow.status.uncheck, }; const result = await this.db.insert(this.tableName, newStage); console.log(result); return result.affectedRows === 1 ? newStage : null; } } return Stage; };