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.merchanttradeSve = system.getObject("service.merchant.merchanttradeSve");
    }


    async merchanttradesOfList(params, pobj2, req) {
        try {
            let res = await this.merchanttradeSve.merchanttradesOfList(params);
            if (res.status != 0) {
                return res;
            }
            for (let item of res.data.rows) {
                item.amount = system.f2y(item.amount);
            }
            return res;
        } catch (error) {
            return system.getResult(null, `系统错误 错误信息 ${error}`);
        }
    }

    //调账添加
    async addMerchanttrades(params, pobj2, req) {
        try {
            if (params.amount) {
                params.amount= Number(params.amount || 0) * 100;
            }
            return await this.merchanttradeSve.addMerchanttrades(params);
        } catch (error) {
            return system.getResult(null, `系统错误 错误信息 ${error}`);
        }
    }

    //充值审核
    async auditMerchanttrade(params, pobj2, req) {
        try {
            return await this.merchanttradeSve.auditMerchanttrade(params);
        } catch (error) {
            return system.getResult(null, `系统错误 错误信息 ${error}`);
        }
    }

    //资金流水
    async merchanttradesOfListAll(params, pobj2, req) {
        try {
            let res = await this.merchanttradeSve.merchanttradesOfListAll(params);
            if (res.status != 0) {
                return res;
            }
            for (let item of res.data.rows) {
                item.amount = system.f2y(item.amount);
                item.available_amount = system.f2y(item.available_amount);
                item.balance_amount = system.f2y(item.balance_amount);
            }
            return res;
        } catch (error) {
            return system.getResult(null, `系统错误 错误信息 ${error}`);
        }
    }

    //代客下单流水
    async valetorder(params, pobj2, req) {
        try {
            return await this.merchanttradeSve.valetorder(params);
        } catch (error) {
            return system.getResult(null, `系统错误 错误信息 ${error}`);
        }
    }


}

module.exports = MerchantUserCtl;
