 
const system=require("../../../system");
const Dao=require("../../dao.base");
class NeedinfoDao extends Dao{
  constructor(){
    super(Dao.getModelName(NeedinfoDao));
  }
  // extraWhere(obj,w,qc,linkAttrs){
  //   w["company_id"]=obj.company_id;
  //   return w;
  // }

  async getAllProductType(cid){
    var params = {
      company_id: cid
    };
    var returnRes = {
      total: 0,//总记录条数
      rows: []
    };
    var sql = "select id,p_id,p_code,p_name,code,name,pic_url,jump_link_type,jump_link,sequence from mc_product_type  where deleted_at is null and p_id = 0 order by sequence asc ";

    var list = await this.customQuery(sql, params);
    for(var i=0;i<list.length;i++){
      if(list[i] && list[i].id)
      var sql2 = "select id,p_id,p_code,p_name,code,name,pic_url,sequence from mc_product_type  where deleted_at is null and p_id = "+list[i].id+" order by sequence desc ";
      var childlist = await this.customQuery(sql2, params);
      list[i].children = childlist;
    }
    returnRes.rows = list;
    returnRes.total = list.length;
    return returnRes;
  }
  

}
module.exports=NeedinfoDao;