const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");

class MerchantService extends ServiceBase {
    constructor() {
        super("all", ServiceBase.getDaoName(MerchantService));
    }

    async signPage(params) {
        var currentPage = Number(params.currentPage || 0);
        var pageSize = Number(params.pageSize || 10);

        var where = {};
        if (params.company_name) {
            where.company_name = {
                [this.db.Op.like]: "%" + params.company_name + "%"
            };
        }
        where.sign_body = {
            [this.db.Op.eq]:  params.sign_body
        };
        this.addWhereTime(where, 'begin_time', params.signBegin, params.signEnd, true);
        var orderby = [
            ["id", 'desc']
        ];
        var attributes = [`id`, `company_name`, `type`, `link_man`, `link_no`, `link_email`, `bank_account_name`, `bank_no`, `open_bank`, `sign_body`, `begin_time`, `invalid_time`];
        var page = await this.getPageList(currentPage, pageSize, where, orderby, attributes);
        if (page && page.rows) {
            for (var row of page.rows) {
                this.handleDate(row, ["begin_time", "invalid_time"]);
            }
        }
        return page;
    }

}

module.exports = MerchantService;