tablePrefix ='tab_'; /* 执行构造方法 */ parent::__construct($name, $tablePrefix, $connection); } public function sw_add($add_data=array()){ $data = array( 'account' => $add_data['account'], 'password' => $add_data['password'], 'sw_name' => $add_data['sw_name'], 'phone' => $add_data['phone'], 'qq' => $add_data['qq'], 'inferiors' => $add_data['inferiors'], 'status' => $add_data['status'], 'create_time' => NOW_TIME, ); /* 添加用户 */ $result = $this->create($data); if($result){ $uid = $this->add(); return $uid ? $uid : 0; //0-未知错误,大于0-注册成功 } else { return $this->getError(); //错误详情见自动验证注释 } } public function add_child($id,$promote_id){ $data = $this->field("promote_id")->find($id); if($data['promote_id'] == 0 || $data['promote_id']=="" || $data["promote_id"] == null){ $field = $promote_id; }else{ $field = $data['promote_id'].",".$promote_id; $this->where("id=".$id)->setInc("inferiors",1); } $this->where("id=".$id)->setField('promote_id',$field); } /** *修改商务专员旗下推广员数量 */ public function update_child($id=0,$new_id=null,$promote_id=null){ $p_ids = array(); $childMap['parent_id'] = $promote_id; $childMap['grand_id'] = $promote_id; $childMap['_logic'] = 'or'; $data_child = D('Promote')->where($childMap)->getField('id',true); if(empty($data_child)){ $p_ids[0] = $promote_id; }else{ array_unshift($data_child,$promote_id); $p_ids = $data_child; } if($id != 0){ $ba_old_ids = $this->where('id='.$id)->getField('promote_id'); $ba_old_ids = explode(",",$ba_old_ids); $ba_old_ids = array_diff($ba_old_ids,$p_ids); if(empty($ba_old_ids)){ $ba_old_ids[0] = 0; } $this->where("id=".$id)->setField('promote_id', implode(",", $ba_old_ids)); $this->where("id=".$id)->setDec("inferiors",count($p_ids)); } $ba_new_ids = $this->where("id=".$new_id)->getField('promote_id'); if(empty($ba_new_ids)){ $ba_new_ids = $p_ids; }else{ $ba_new_ids = explode(",", $ba_new_ids); array_push($ba_new_ids,$p_ids); } D('Promote')->where('parent_id='.$promote_id.' or grand_id='.$promote_id)->setField('ba_id',$new_id); $this->where("id=".$new_id)->setField('promote_id', implode(",", $ba_new_ids)); $this->where("id=".$new_id)->setInc("inferiors",count($p_ids)); } /** *删除商务专员旗下推广员 */ public function del_child($ba_id = 0,$promote_ids = 0){ //查找所有父级和子级id array_unique $pMap['parent_id'] = array("IN",$promote_ids); $data_child = D('Promote')->where($pMap)->getField('id',true); if(empty($data_child)){ $p_ids = $promote_ids; }else{ $p_ids = array_merge($data_child,$promote_ids); $p_ids = array_unique($p_ids); } $num = count($p_ids); $ba_promote_id_new = $this->where('id = '.$ba_id)->getField('promote_id'); $ba_promote_id_new = explode(",", $ba_promote_id_new); $ba_promote_id_new = array_diff($ba_promote_id_new,$p_ids); if(empty($ba_promote_id_new)){ $ba_promote_id_new[0] = 0; } $setPromoteMap['id'] = array('IN',$p_ids); $promote = D('Promote')->where($setPromoteMap)->setField(array('ba_id'=>0)); $baMap['id'] = $ba_id; if($ba_promote_id_new[0] == 0){ $ba = $this->where($baMap)->setField('inferiors',0); }else{ $ba = $this->where($baMap)->setDec('inferiors',$num); } $ba_p = $this->where($baMap)->setField(array('promote_id'=>implode(",", $ba_promote_id_new))); } /** * 创建时间不写则取当前时间 * @return int 时间戳 * @author huajie */ protected function getCreateTime(){ $create_time = I('post.create_time'); return $create_time?strtotime($create_time):NOW_TIME; } }