const system=require("../../system");
const Dao=require("../dao.base");
class ChannelmanageallotDao extends Dao{
  constructor(){
    super(Dao.getModelName(ChannelmanageallotDao));
  }
  extraModelFilter(){
    let v = [
      {model:this.db.models.channel,attributes:["id","channelName", "channelCode"]},
      {model:this.db.models.user,attributes:["id","userName"]}
    ]
    return {"key":"include","value": v};
  }

  async incrAllotCount(id, weight) {
    var cma = await this.findById(id);
    if(!cma) {
      return 0;
    }
    var tmpWeight = Number(cma.weight) + Number(weight);
    if(tmpWeight > 2) {
      cma.weight = 2;
    } else if(tmpWeight < 0.5) {
      cma.weight = 0.5;
    } else {
      cma.weight = tmpWeight;
    }
    cma.save();
    return cma;
  }
}
module.exports=ChannelmanageallotDao;
