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

  /**
   * 获取产品列表
   */
  async productList() {
    var returnRes = {
      total: 0,//总记录条数
      rows: []
    };
    var dataCount = "select count(1) as dataCount from mc_product  where deleted_at is null ";
    var sql = "select count(1) as dataCount from mc_product  where deleted_at is null ";

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

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

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

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

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

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

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

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

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

  /**
   * 产品分类二类
   */
  async productTypeSecend(req){
    var params = {
      product_type_code: req.actionBody.product_type_code
    };
    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 ";
    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";

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

  //   var list = await this.customQuery(sql);
  //   returnRes.rows = list;
  //   // var result = system.getResultSuccess(list);
  //   var tmpResultCount = await this.customQuery(dataCount);
  //   returnRes.total = tmpResultCount && tmpResultCount.length > 0 ? tmpResultCount[0].dataCount : 0;
  //   var result = system.getResultSuccess(returnRes);
  //   return result;
  // }
  /**
   *方案一 
   */
  // async firstAction(){

  // }



}
module.exports = MediaaggregationDao;