$pay 订单支付金额
$user_id 购买商品的人id
$order_id 订单id
$zhi1 $zhi2 $zhi3 的分佣比例
此函数在支付时候触发使用
注册的时候确定上下级关系 pid1 pid2 pid3
…
public function fen_yong($pay,$user_id,$order_id){
$zhi1=M('parameter')->where(array('id'=>1))->getField('zhi');
$zhi2=M('parameter')->where(array('id'=>2))->getField('zhi');
$zhi3=M('parameter')->where(array('id'=>3))->getField('zhi');
$user = M('user')->where(array('user_id'=>$user_id))->find();
$data=array($user['pid1']=>$zhi1,$user['pid2']=>$zhi2,$user['pid3']=>$zhi3);
foreach($data as $p=>$rate){
if($p==0){
break;//跳出本次循环
}else{
$data1['order_id']=$order_id;
$data1['user_id']=$user_id;
$data1['uid']=$p;
$data1['yongjin']=$rate*$pay;
$data1['time']=time();
$data1['user_name']=M('user')->where(array('user_id'=>$user_id))->getField('name');
$brokerage =$rate*$pay;
M('rebate')->add($data1);
M('user')->where(array('user_id'=>$p))->setInc('brokerage',$brokerage);
}
}
}