var system = require("../../system")
const md5 = require("MD5");
const logCtl = system.getObject("web.oplogCtl");
const moment = require("moment");
class ChannelApi {
    constructor() {
        this.channelSve = system.getObject("service.channelSve");
    }

    //渠道绑定
    async bindPlatform(queryobj, qobj, req) {
        if(!this.trim(queryobj.platform_id)){
            return system.getErrResult2("platform_id不能为空")
        }
        if(!this.trim(queryobj.channel_id)){
            return system.getErrResult2("channel_id不能为空")
        }
        if(!this.trim(queryobj.platform_channel_id)){
            return system.getErrResult2("platform_channel_id不能为空")
        }
        var result = await this.channelSve.bindPlatform(queryobj);
        return result;
    }

    //绑定渠道推送
    async pushbindingchannel(queryobj, qobj, req){

        queryobj.begin = moment().subtract(1, 'days').format('YYYY-MM-DD 00:00:00'); /*前一天的时间*/
        queryobj.end =  moment().subtract(1, 'days').format('YYYY-MM-DD 23:59:59'); /*前一天的时间*/
        console.log(queryobj);

        var result = await this.channelSve.pushbindingchannel(queryobj);
        return result;
    }


    trim(o) {
        if (!o) {
            return "";
        }
        return o.toString().trim();
    }
}
module.exports = ChannelApi;
