const system = require("../../../system");
const Dao = require("../../dao.base");
class MediaaggregationDao extends Dao {
  constructor() {
    super(Dao.getModelName(MediaaggregationDao));
  }

  /**
   * 服务列表
   */
  async productList(req) {
    var params = {
      product_type_code: req.actionBody.product_type_code,
      company_id: req.actionBody.company_id
    };
    var returnRes = {
      total: 0,//总记录条数
      rows: []
    };
    var dataCount = "select count(1) as dataCount from mc_product  where deleted_at is null and product_type_code = :product_type_code and company_id = :company_id ";
    var sql = "select * from mc_product  where deleted_at is null and product_type_code = :product_type_code and company_id = :company_id ";

    var list = await this.customQuery(sql,params);
    returnRes.rows = list;
    var tmpResultCount = await this.customQuery(dataCount,params);
    returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
    return returnRes;
  }

  /**
   * 轮播图
   */
  async rotationChartList(req){
    var params = {
      company_id: req.actionBody.company_id
    };
    var returnRes = {
      total: 0,//总记录条数
      rows: []
    };
    var dataCount = "select count(1) as dataCount from mc_rotation_chart where deleted_at is null and pic_type = 2  and company_id = :company_id ";
    var sql = "select * from mc_rotation_chart where deleted_at is null and pic_type = 2  and company_id = :company_id ";

    var list = await this.customQuery(sql,params);
    returnRes.rows = list;
    var tmpResultCount = await this.customQuery(dataCount,params);
    returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
    return returnRes;
  }
  

  /**
   * 留资表单产品
   */
  async needProductList(req){
    var params = {
      company_id: req.actionBody.company_id
    };
    var returnRes = {
      total: 0,//总记录条数
      rows: []
    };
    var dataCount = "select count(1) as dataCount from mc_second_level_need_config where deleted_at is null  and company_id = :company_id ";
    var sql = "select * from mc_second_level_need_config where deleted_at is null  and company_id = :company_id ";

    var list = await this.customQuery(sql,params);
    returnRes.rows = list;
    var tmpResultCount = await this.customQuery(dataCount,params);
    returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
    return returnRes;
  }

  /**
   * 热门推荐
   */
  async popularRecommendationList(req){
    var params = {
      company_id: req.actionBody.company_id
    };
    var returnRes = {
      total: 0,//总记录条数
      rows: []
    };
    var dataCount = "select count(1) as dataCount from mc_popular_recommendation where deleted_at is null  and company_id = :company_id ";
    var sql = "select * from mc_popular_recommendation where deleted_at is null  and company_id = :company_id ";

    var list = await this.customQuery(sql,params);
    returnRes.rows = list;
    var tmpResultCount = await this.customQuery(dataCount,params);
    returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
    return returnRes;
  }

  /**
   * 产品分类一类
   */
  async productTypeFirst(req){
    var params = {
      company_id: req.actionBody.company_id
    };
    var returnRes = {
      total: 0,//总记录条数
      rows: []
    };
    var dataCount = "select count(1) as dataCount from mc_product_type  where deleted_at is null and p_id = 0 and company_id = :company_id ";
    var sql = "select * from mc_product_type  where deleted_at is null and p_id = 0 and company_id = :company_id ";

    var list = await this.customQuery(sql,params);
    returnRes.rows = list;
    var tmpResultCount = await this.customQuery(dataCount,params);
    returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
    return returnRes;
  }

  /**
   * 产品分类二类
   */
  async productTypeSecend(req){
    var params = {
      product_type_code: req.actionBody.product_type_code,
      company_id: req.actionBody.company_id
    };
    var returnRes = {
      total: 0,//总记录条数
      rows: []
    };
    var dataCount = "select count(1) as dataCount from mc_product left join mc_product_type on mc_product.product_type_id = mc_product_type.id where mc_product.deleted_at is null and mc_product_type.deleted_at is null and product_type_code = :product_type_code and mc_product_type.company_id = :company_id ";
    var sql = "select *  from mc_product left join mc_product_type on mc_product.product_type_id = mc_product_type.id  where  mc_product.deleted_at is null and mc_product_type.deleted_at is null and  product_type_code = :product_type_code and mc_product_type.company_id = :company_id ";

    var list = await this.customQuery(sql,params);
    returnRes.rows = list;
    var tmpResultCount = await this.customQuery(dataCount,params);
    returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
    return returnRes;
  }
  /**
   * 获取产品详情
   */
  async productDetail(req) {
    var params = {
      code: req.actionBody.code,
      company_id: req.actionBody.company_id
      
    };
    var sql = "select * from mc_product where deleted_at is null and code = :code  and company_id = :company_id ";
    var list = await this.customQuery(sql, params);
    return list;
  }
  
   /**
   * 吸底菜单
   */
  async bottomMenuConfig(req) {
    var params = {
      company_id: req.actionBody.company_id
    };
    var returnRes = {
      total: 0,//总记录条数
      rows: []
    };
    var dataCount = "select count(1) as dataCount  from mc_bottom_menu_config  where deleted_at is null and company_id = :company_id ";
    var sql = "select * from mc_bottom_menu_config  where deleted_at is null and company_id = :company_id ";

    var list = await this.customQuery(sql,params);
    returnRes.rows = list;
    var tmpResultCount = await this.customQuery(dataCount,params);
    returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
    return returnRes;
  }

  /**
   * 周期产品
   */
  async cycleProduct(req) {
    var params = {
      company_id: 10
    };
    var returnRes = {
      total: 0,//总记录条数
      rows: []
    };
    var dataCount = "select count(1) as dataCount  from mc_cycle_product  where deleted_at is null and company_id = :company_id ";
    var sql = "select * from mc_cycle_product  where deleted_at is null and company_id = :company_id ";

    var list = await this.customQuery(sql,params);
    returnRes.rows = list;
    var tmpResultCount = await this.customQuery(dataCount,params);
    returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
    return returnRes;
  }

}
module.exports = MediaaggregationDao;