var system = require("../../../system")
const settings = require("../../../../config/settings")
const CtlBase = require("../../ctlms.base");
const md5 = require("MD5");
const uuidv4 = require('uuid/v4');
const logCtl = system.getObject("web.common.oplogCtl");

class MerchantUserCtl extends CtlBase {
    constructor() {
        super();
        this.merchantSve = system.getObject("service.merchant.merchantSve");
        this.userSve = system.getObject("service.uc.userSve");
    }


    async merchantOfList(params, pobj2, req) {
        try {
            let res = await this.merchantSve.merchantOfList(params);
            if (res.data && res.data.rows) {
                await this.userSve.setRowsUser(res.data.rows, "bd_id", "bd");
            }
            return res;
        } catch (error) {
            return system.getResult(null, `系统错误 错误信息 ${error}`);
        }
    }

    async merchantOfInfo(params, pobj2, req) {
        try {
            params.id = params.id || params.merchant_id;
            let res = await this.merchantSve.merchantOfInfo(params);
            if (res.data) {
                await this.userSve.setRowsUser([res.data], "bd_id", "bd");
            }
            return res;
        } catch (error) {
            return system.getResult(null, `系统错误 错误信息 ${error}`);
        }
    }

    async addModifyMerchants(params, pobj2, req) {
        try {
            return await this.merchantSve.addModifyMerchants(params);
        } catch (error) {
            return system.getResult(null, `系统错误 错误信息 ${error}`);
        }
    }

    async merchantSuggest(params, pobj2, req) {
        try {
            return await this.merchantSve.merchantSuggest(params);
        } catch (error) {
            return system.getResult(null, `系统错误 错误信息 ${error}`);
        }
    }

    async auditMerchant(params, pobj2, req) {
        try {
            params.audit_user_id = req.loginUser.id;
            return await this.merchantSve.auditMerchant(params);
        } catch (error) {
            return system.getResult(null, `系统错误 错误信息 ${error}`);
        }
    }

}

module.exports = MerchantUserCtl;
