| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 | 'use strict';/** *  奖罚金 * * @author Mai * @date * @version */module.exports = app => {    class AuditAss extends app.BaseService {        /**         * 构造函数         *         * @param {Object} ctx - egg全局变量         * @return {void}         */        constructor(ctx) {            super(ctx);            this.tableName = 'audit_ass';        }        async getData(tid) {            return await this.getAllDataByCondition({ where: { tid } });        }        async getUserData(tid, user_id) {            return await this.getAllDataByCondition({ where: { tid, user_id } });        }        async _addData(data) {            if (!data.user_id || !data.ass_user_id) throw '新增协审错误';            const nd = {                pid: this.ctx.session.sessionProject.id,                tid: this.ctx.tender.id,                user_id: data.user_id,                ass_user_id: data.ass_user_id,                name: data.name,                company: data.company,                role: data.role,                ass_ledger_id: data.ass_ledger_id,            };            const result = await this.db.insert(this.tableName, nd);            nd.id = result.insertId;            return nd;        }        async _delData(data) {            await this.db.delete(this.tableName, {id: data.id});            return data;        }        async _updateData(data) {            if (!data) return;            const datas = data instanceof Array ? data : [datas];            const orgDatas = await this.getAllDataByCondition({                where: { id: this.ctx.helper._.map(datas, 'id') }            });            const uDatas = [];            for (const d of datas) {                const od = this.ctx.helper._.find(orgDatas, {id: d.id});                if (!od) continue;                const nd = {id: od.id};                if (d.ass_ledger_id !== undefined) nd.ass_ledger_id = d.ass_ledger_id;                uDatas.push(nd);            }            if (uDatas.length > 0) {                await this.db.updateRows(this.tableName, uDatas);                return uDatas;            } else {                return [];            }        }        async updateData(data) {            const result = { update: [] };            try {                if (data.add) {                    result.add = await this._addData(data.add);                }                if (data.update) {                    result.update = await this._updateData(data.update);                }                if (data.del) {                    result.del = await this._delData(data.del);                }                return result;            } catch (err) {                if (err) result.err = err;                return result;            }        }    }    return AuditAss;};
 |