'use strict';

/**
 *
 *
 * @author Mai
 * @date 2018/6/1
 * @version
 */

module.exports = app => {
    class LedgerAuditContent extends app.BaseService {
        /**
         * 构造函数
         *
         * @param {Object} ctx - egg全局变量
         * @return {void}
         */
        constructor(ctx) {
            super(ctx);
            this.tableName = 'ledger_audit_content';
        }

        async add(tender, auditId, data) {
            const newContent = {
                tender_id: tender.id,
                audit_id: auditId,
                times: tender.times,
                in_time: new Date(),
                content: data.opinion,
            };
            const relaBills = await this.ctx.service.ledger.getDataByNodeIds(tender.id, data.bills);
            newContent.rela_bills = JSON.stringify(relaBills);
            const result = await this.db.insert(this.tableName, newContent);
            return result.effectRows = 1;
        }
    }

    return LedgerAuditContent;
};