| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 | 'use strict';/** * 期计量 数据模型 * * @author Mai * @date 2018/8/13 * @version */const auditConst = require('../const/audit').material;module.exports = app => {    class MaterialBills extends app.BaseService {        /**         * 构造函数         *         * @param {Object} ctx - egg全局变量         * @return {void}         */        constructor(ctx) {            super(ctx);            this.tableName = 'material_bills';        }        /**         * 添加工料         * @return {void}         */        async add() {            if (!this.ctx.tender || !this.ctx.material) {                throw '数据错误';            }            const newBills = {                tid: this.ctx.tender.id,                mid: this.ctx.material.id,                in_time: new Date(),            };            // 新增工料            const result = await this.db.insert(this.tableName, newBills);            if (result.affectedRows !== 1) {                throw '新增工料数据失败';            }            return await this.getDataById(result.insertId);        }        /**         * 删除工料         * @param {int} id 工料id         * @return {void}         */        async del(id) {            if (!this.ctx.tender || !this.ctx.material) {                throw '数据错误';            }            // 判断是否可删            return await this.deleteById(id);        }        /**         * 修改工料信息         * @param {Object} data 工料内容         * @return {void}         */        async save(data) {            if (!this.ctx.tender || !this.ctx.material) {                throw '数据错误';            }            delete data.in_time;            // 判断是否可修改            return await this.db.update(this.tableName, data);        }    }    return MaterialBills;};
 |