const system = require("../../../system");
const Dao = require("../../dao.base");
class ProductDao extends Dao {
  constructor() {
    super(Dao.getModelName(ProductDao));
  }
  extraWhere(obj,w,qc,linkAttrs){
    if(obj.bizpath && obj.bizpath!=""){
      if(obj.bizpath.indexOf("productdef")>0){//说明是租户查询自己创建的应用
         w["company_id"]= obj.company_id;
      }
    }
    if(linkAttrs.length>0){
      var search=obj.search;
      var lnkKey=linkAttrs[0];
      var strq="$"+lnkKey.replace("~",".")+"$";
      w[strq]= {[this.db.Op.like]:"%"+search[lnkKey]+"%"};
    }
    return w;
 }
  extraModelFilter() {
    //return {"key":"include","value":[{model:this.db.models.app,},{model:this.db.models.role,as:"Roles",attributes:["id","name"],joinTableAttributes:['created_at']}]};
    return {
      "key": "include", "value": [
        { model: this.db.models.productprice, as: "skus", attributes: ["id", "pricestrategy_id"] }]
    }
  }
}
module.exports = ProductDao;