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

class OriginService extends ServiceBase {
  constructor() {
    super("channel", ServiceBase.getDaoName(OriginService));
  }

  async dics() {
    var list = await this.dao.dicList(1);
    return system.getResultSuccess(list);
  }

  async info(params) {
    let origin = await this.dao.getById(params.id);
    return system.getResultSuccess(origin);
  }

  async merchants(params) {
    let id = Number(params.id || 0);
    let name = this.trim(params.name);
    if(!id || !name) {
      return system.getResultSuccess([]);
    }
    let origin = await this.dao.findById(id);
    if(!origin) {
      return system.getResultSuccess([]);
    }
    if(!origin) {
      return system.getResultSuccess([]);
    }
    if(!origin.is_api || !origin.api_url) {
      return system.getResultSuccess([]);
    }
    let rs = await axios({
      method: 'post',
      url: origin.api_url,
      data: {name: name}
    });
    return rs.data;
  }
}

module.exports = OriginService;
