1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 'use strict';
- /**
- * 清单设置 数据模型
- * @author LanJianRong
- * @date 2020/6/30
- * @version
- */
- module.exports = app => {
- class MaterialChecklist extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'material_checklist';
- }
- async resetData(pushData, removeData) {
- if (!this.ctx.tender || !this.ctx.material) {
- throw '数据错误';
- }
- const transaction = await this.db.beginTransaction();
- try {
- if (pushData.length > 0) {
- const insertDatas = [];
- for (const p of pushData) {
- p.mid = this.ctx.material.id;
- p.tid = this.ctx.tender.id;
- insertDatas.push(p);
- }
- await transaction.insert(this.tableName, insertDatas);
- }
- if (removeData.length > 0) {
- for (const r of removeData) {
- await transaction.delete(this.tableName, { id: r });
- }
- }
- await transaction.commit();
- return await this.getAllDataByCondition({ where: { tid: this.ctx.tender.id }, orders: [['order', 'asc']] });
- } catch (err) {
- await transaction.rollback();
- throw err;
- }
- }
- async updateHadBills(transaction, id, had_bills) {
- if (!this.ctx.tender || !this.ctx.material) {
- throw '数据错误';
- }
- return await transaction.update(this.tableName, { id, had_bills });
- }
- }
- return MaterialChecklist;
- };
|