$model=M('Order');
$map['payordercode']=array('eq',$out_trade_no);
$paydata=$model->where($map)->find();
if($paydata['status']==0){
$model->where($map)->setField('status', 1);
//取会员信息
$hysjb=M('User');
$hytj['userid']=array('eq',$paydata['huserid']);
$hyxx=$hysjb->where($hytj)->find();
//测试开始
$paydata['huserid']=$_SESSION['userid'];
$uid = $paydata['huserid'];
$res = M()->table('f_agent_user a')->join("f_agent b on a.agent_id=b.id")->where("a.userid='$uid'")->field('b.*')->select();
if($res){
$agent_type = $res["agent_type"];
$agent_id = $res["id"];
$parent_id = $res["parent_id"];
$free_sum_money = !empty($res["free_sum_money"]) ? $res["free_sum_money"] : 0;
$curr_balance = !empty($res["curr_balance"]) ? $res["curr_balance"] : 0;
$paydata['orderprice'] = $orderprice;
// 添加代理商或业务员下付费用户数,付费总金额,当前余额
$thisFreeSumMoney = 0.0;
$thisBalance = 0.0;
$this_deduct_rate = 0.8;
$thisOrderprice = $paydata['orderprice'];
$thisDeductRateMoney = $paydata['orderprice'] * 0.8;
if ($res["agent_type"]==2){
$res2 = M()->table('f_agent_set_bussines_rule a')->join(" f_agent_rule b on a.rule_id=b.id")->where("agent_id='$parent_id' and b.id=5")->field('a.*,b.agent_rule,b.deduct_rate')->select();
$bussines_deduct_rate = $res2['bussines_deduct_rate'];
// 业务员的显示的付费总金额为代理商的80%
$thisOrderprice = $thisOrderprice * 0.8;
$thisDeductRateMoney = $thisOrderprice * $bussines_deduct_rate;
$thisFreeSumMoney = $free_sum_money + $thisOrderprice;
// 业务员本次的余额为代理商设置提成比例值
$thisBalance = $curr_balance + $thisOrderprice * $bussines_deduct_rate;
}else{
$thisDeductRateMoney = $thisOrderprice * 0.8;
$thisFreeSumMoney = $free_sum_money + $thisOrderprice;
$thisBalance = $curr_balance + $thisOrderprice * 0.8;
}
if ($hyxx['is_exist_free']==0){
$free_hair_style_num=$res["free_hair_style_num"]+1;
}else{
$free_hair_style_num=$res["free_hair_style_num"];
}
$Agent=D("Agent");
$data=array(
'free_hair_style_num'=>$free_hair_style_num,
'free_sum_money'=>$thisFreeSumMoney,
'curr_balance'=>$thisBalance
);
$result =$Agent->where(array('id'=>$agent_id))->save($data);
// 添加发型师消费明细记录
$Dao = M("Hairstyle_free_detail"); // 构建写入的数据数组
$data["hairstyle_id"] = $userid; //$paydata['huserid']=session('userid');
$data["agent_id"] = $agent_id;
$data["this_free_sum_money"] = $thisOrderprice;
$data["this_deduct_rate"] = $this_deduct_rate;
$data["this_deduct_money"] = $thisDeductRateMoney;
$data["free_time"] = time();
$Dao->add($data);
/*print_r($data);
exit;*/
// 业务员
if ($res["agent_type"]==2){
// 如果是业务员,则他上级的代理商付费用户数,付费总金额,当前余额也要进行累加
$dlsjb=M('Agent');
$dltj['id']=array('eq',$parent_id);
$dlxx=$dlsjb->where($dltj)->find();
$agent_free_sum_money = !empty($res["free_sum_money"]) ? $res["free_sum_money"] : 0;
$agent_curr_balance = !empty($res["curr_balance"]) ? $res["curr_balance"] : 0;
$agentThisFreeSumMoney = $agent_free_sum_money+$thisOrderprice;
$agentThisBalance = $agent_curr_balance+$thisOrderprice*0.8;
$Agent=D("Agent");
$data=array(
'free_hair_style_num'=>$free_hair_style_num,
'free_sum_money'=>$$agentThisFreeSumMoney,
'curr_balance'=>$agentThisBalance
);
$result =$Agent->where(array('id'=>$parent_id))->save($data);
}
}
//测试结束agent_id orderprice userid 这几个字段的值无法写入到表里面
最佳答案