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


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

    async transferList(params) {
        var currentPage = Number(params.currentPage || 1);
        var pageSize = Number(params.pageSize || 10);

        var where = {};

        if (params.merchant_name) {
            where.merchant_name = {
                [this.db.Op.like]: "%" + params.merchant_name + "%"
            };
        }
        if (params.sign_body_id) {
            where.sign_body_id = {
                [this.db.Op.eq]: params.sign_body_id
            };
        }

        this.addWhereTime(where, 'transfer_at', params.signBegin, params.signEnd, true);
        var orderby = [
            ["transfer_at", 'desc']
        ];

        var page = await this.getPageList(currentPage, pageSize, where, orderby);
        if (page && page.rows) {
            for (var row of page.rows) {
                this.handleDate(row, ["begin_time", "invalid_time"], "YYYY-MM-DD");
                this.handleDate(row, ["transfer_at"], "YYYY-MM-DD HH:mm:ss");
            }
        }
        return page;
    }

    async test() {
        return "service success"
    }
}

module.exports = MerchantTransferService;
