| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 | 'use strict';/** * * * @author Mai * @date 2018/6/1 * @version */module.exports = app => {    class LedgerCooperation extends app.BaseService {        /**         * 构造函数         *         * @param {Object} ctx - egg全局变量         * @return {void}         */        constructor(ctx) {            super(ctx);            this.tableName = 'ledger_cooperation';        }        async save(data) {            delete data.type;            data.tid = this.ctx.tender.id;            const info = await this.getDataByCondition({ tid: this.ctx.tender.id, ledger_id: data.ledger_id, user_id: data.user_id });            if (data.pwd === '' && info) {                await this.deleteById(info.id);            } else if (data.pwd !== '' && !info) {                // const ledgerInfo = await this.ctx.service.ledger.getDataByCondition({ ledger_id: data.ledger_id });                // if (ledgerInfo) {                //     data.lid = ledgerInfo.id;                const result = await this.db.insert(this.tableName, data);                data.id = result.insertId;                data.sign_path = null;                data.company = '';                data.status = 1;                // }            } else if (data.pwd !== '' && info) {                data.id = info.id;                await this.db.update(this.tableName, data);                data.sign_path = info.sign_path;                data.company = info.company;            }            return data;        }        async changeAllStatus(status) {            const options = {                where: {                    tid: this.ctx.tender.id,                },            };            const updateData = {                status,            };            return await this.db.update(this.ctx.service.ledgerCooperation.tableName, updateData, options);        }        async saveSign(id, path) {            const updateData = {                id,                sign_path: path,            };            return await this.db.update(this.tableName, updateData);        }        async saveCompany(data) {            const updateData = {                id: data.id,                company: data.company,            };            return await this.db.update(this.tableName, updateData);        }        async getValidData(tid, uid) {            const condition = { where: { tid, status: 1 } };            if (uid) {                condition.where.user_id = uid;                condition.colums = ['ledger_id', 'pwd'];            }            return await this.getAllDataByCondition(condition);        }    }    return LedgerCooperation;};
 |