insert(['data'=>'user._______'.json_encode($order)]); $mer_id=$order['mer_id']; // Db::name('log')->insert(['data'=>'商户id0'.$mer_id]); if($mer_id=='290'){ return $this->pay_orrder_290($order,$type); }elseif($mer_id=='236'){ // Db::name('log')->insert(['data'=>'商户id1'.$mer_id]); try { $order_236=new Order_236(); // Db::name('log')->insert(['data'=>'商户id2'.json_encode($order_236)]); return $order_236-> order($order, $type); }catch (\Exception $e) { Db::name('log')->insert(['data'=>'地宝订单支付出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']); } } }catch (\Exception $e) { Db::name('log')->insert(['data'=>'地宝订单支付出错lll:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']); } $user=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$order['uid'])->find(); $update=[]; $update_config=[]; //增加消费总额/积分 $weizhi=strpos($order['money'],'.'); if($weizhi){ $money=substr($order['money'],'0',$weizhi); }else{ $money=$order['money']; } $update_user=[ 'cumulative_money'=>bcadd($order['money'],$user['cumulative_money'],2), ]; // if($mer_id=='276'||$mer_id=='236'){ // if($order['money']>=1){ // if($user['first_consumption_one']==1){ // if($type==2){ // // $bill=[ // 'from_id'=>'0', // 'number'=>100, // 'to_id'=>$user['eb_id'], // 'type'=>'1', // 'order_no'=>$order['order_no'], // 'remarks'=>'首次消费满1元赠送100积分', // 'pm'=>1, // 'status'=>2, // 'on_line'=>2, // 'mer_id'=>$mer_id // ]; // $this->eb_user_bill($bill); // Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['eb_id'])->inc('integral',100)->update(); // Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['eb_id'])->inc('first_consumption_one',1)->update(); // // }else{ // // $bill=[ // 'from_id'=>'0', // 'number'=>100, // 'to_id'=>$user['eb_id'], // 'type'=>'1', // 'order_no'=>$order['order_no'], // 'remarks'=>'首次消费满1元赠送100积分', // 'pm'=>1, // 'status'=>1, // 'on_line'=>1, // 'mer_id'=>$mer_id // ]; // $this->eb_user_bill($bill); // Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['eb_id'])->inc('first_consumption_one',1)->update(); // } // // } // } // } if($user['type']==1){ if($update_user['cumulative_money']>=6000){ $update['integral']='6000'; } } $reward_one=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_one')->find(); if($update_user['cumulative_money']>=$reward_one||$mer_id=='236'){ if($type==2){ Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['eb_id'])->update($update_user); $bill=[ 'from_id'=>'0', 'number'=>$money, 'to_id'=>$user['eb_id'], 'type'=>'1', 'order_no'=>$order['order_no'], 'remarks'=>'消费得积分', 'pm'=>1, 'status'=>2, 'on_line'=>2, 'mer_id'=>$mer_id ]; $this->eb_user_bill($bill); }else{ $bill=[ 'from_id'=>'0', 'number'=>$money, 'to_id'=>$user['eb_id'], 'type'=>'1', 'order_no'=>$order['order_no'], 'remarks'=>'消费得积分', 'pm'=>1, 'status'=>1, 'on_line'=>1, 'mer_id'=>$mer_id ]; $this->eb_user_bill($bill); } } $eb_user=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$order['uid'])->find(); $reward_two=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_two')->find(); $reward_three=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_three')->find(); $reward_four=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_four')->find(); // Db::name('log')->insert(['data'=>'这是我总共的消费'.$eb_user['cumulative_money']]); // Db::name('log')->insert(['data'=>'1'.json_encode($reward_one)]); // Db::name('log')->insert(['data'=>'2'.json_encode($reward_two)]); // Db::name('log')->insert(['data'=>'3'.json_encode($reward_three)]); // Db::name('log')->insert(['data'=>'4'.json_encode($reward_four)]); if($eb_user['cumulative_money']>=$reward_one['value'] and $eb_user['cumulative_money']<$reward_two['value']){ $update['type']=2; $update_config['value']=$reward_one['id']; }elseif ($eb_user['cumulative_money']>=$reward_two['value'] and $eb_user['cumulative_money']<$reward_three['value']){ $update['type']=3; $update_config['value']=$reward_two['id']; }elseif ($eb_user['cumulative_money']>=$reward_three['value'] and $eb_user['cumulative_money']<$reward_four['value']){ $update['type']=4; $update_config['value']=$reward_three['id']; }elseif ($eb_user['cumulative_money']>=$reward_four['value']){ $update['type']=5; $update_config['value']=$reward_four['id']; } //修改此用户佣金比例 if($type==2){ Db::name('entropy_barter_config_user_'.$mer_id)->where('eb_id',$user['eb_id'])->update($update_config); //修改此用户类型 2 会员 3经理 4 总监 5 总裁 Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['eb_id'])->update($update); } //是否有上级 if($user['top_eb_id']){ $top_user=Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$user['top_eb_id'])->find(); $wallet=bcmul($order['money'],bcmul(30,0.01,2),2); if($top_user['integral']>=$wallet){ if($type==2){ $bill=[ 'from_id'=>'0', 'number'=>$wallet, 'to_id'=>$top_user['eb_id'], 'type'=>'2', 'order_no'=>$order['order_no'], 'remarks'=>'直推佣金', 'pm'=>1, 'status'=>2, 'on_line'=>2, 'mer_id'=>$mer_id ]; $this->eb_user_bill($bill); Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$top_user['eb_id'])->inc('wallet',$wallet)->update(); Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$top_user['eb_id'])->dec('integral',$wallet)->update(); }else{ $bill=[ 'from_id'=>'0', 'number'=>$wallet, 'to_id'=>$top_user['eb_id'], 'type'=>'2', 'order_no'=>$order['order_no'], 'remarks'=>'直推佣金', 'pm'=>1, 'status'=>1, 'on_line'=>1, 'mer_id'=>$mer_id ]; $this->eb_user_bill($bill); } } $top_level=Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$top_user['top_eb_id'])->find(); if($top_level){ $table_name='entropy_barter_config_'.$mer_id; $cproportion=Db::name('entropy_barter_config_user_'.$mer_id) ->alias('ebcu') ->leftJoin($table_name .' ebc','ebcu.value=ebc.id') ->where('eb_id',$top_level['eb_id']) ->field('ebc.proportion') ->find(); $integral=bcmul($money,bcmul($cproportion['proportion'],'0.01',2),2); if($integral>0){ if($type==2) { Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$top_level['eb_id'])->inc('integral',$integral)->update(); $bill=[ 'from_id'=>'0', 'number'=>$integral, 'to_id'=>$top_level['eb_id'], 'type'=>'2', 'order_no'=>$order['order_no'], 'remarks'=>'团队积分奖励', 'pm'=>1, 'status'=>2, 'on_line'=>2, 'mer_id'=>$mer_id ]; $this->eb_user_bill($bill); }else{ $bill=[ 'from_id'=>'0', 'number'=>$integral, 'to_id'=>$top_level['eb_id'], 'type'=>'1', 'order_no'=>$order['order_no'], 'remarks'=>'团队积分奖励', 'pm'=>1, 'status'=>1, 'on_line'=>1, 'mer_id'=>$mer_id ]; $this->eb_user_bill($bill); } } } } } //账单记录 public function eb_user_bill($bill) { $insert=[ 'from_id'=>$bill['from_id'], 'number'=>$bill['number'], 'to_id'=>$bill['to_id'], 'type'=>$bill['type'], 'order_no'=>$bill['order_no'], 'remarks'=>$bill['remarks'], 'pm'=>$bill['pm'], 'ctime'=>time(), 'on_line'=>$bill['on_line'], 'status'=>$bill['status'], 'pm2_msg'=>$bill['pm2_msg']??'', 'mer_id'=>$bill['mer_id'], 'commission_scale'=>$bill['commission_scale']??0, 'commission_type'=>$bill['commission_type']??0, 'to_user_type'=>$bill['to_user_type']??'', 'to_user_type_1'=>$bill['to_user_type_1']??'', ]; // Db::name('log')->insert(['data'=>json_encode($insert)]); Db::name('entropy_barter_bill')->insert($insert); } //确认收货 public function take($order_no) { // Db::name('log')->insert(['data'=>'易熵易物我走进来了']); try { $mer_id=Db::name('store_order')->where('order_sn',$order_no)->value('mer_id'); if($mer_id=='290'){ $this->take_290($order_no); return ''; } $data=Db::name('entropy_barter_bill')->where('mer_id',$mer_id)->where('order_no',$order_no)->select(); $order_data=Db::name('store_order')->where('order_sn',$order_no)->find(); if($order_data['pay_price']>=1){ $true=true; }else{ $true=false; } // Db::name('log')->insert(['data'=>'数据---'.json_encode($data)]); if($data->isEmpty()){ return '12'; } $data=$data->toArray(); foreach ($data as $k=>$v){ // if($true){ // Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$v['to_id'])->inc('integral',100)->update(); // } $true=false; if($v['status']=='1'){ if($v['type']==2){ Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$v['to_id'])->inc('wallet',$v['number'])->update(); Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$v['to_id'])->dec('integral',$v['number'])->update(); Db::name('entropy_barter_bill')->where('id',$v['id'])->update(['status'=>2]); }elseif ($v['type']==1){ Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$v['to_id'])->inc('integral',$v['number'])->update(); Db::name('entropy_barter_bill')->where('id',$v['id'])->update(['status'=>2]); } } } $uid=Db::name('store_order')->where('order_sn',$order_no)->value('uid'); $eb_user=Db::name('entropy_barter_user_'.$mer_id)->where('uid',$uid)->find(); $reward_one=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_one')->find(); $reward_two=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_two')->find(); $reward_three=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_three')->find(); $reward_four=Db::name('entropy_barter_config_'.$mer_id)->where('key','reward_four')->find(); // Db::name('log')->insert(['data'=>'这是我总共的消费'.$eb_user['cumulative_money']]); // Db::name('log')->insert(['data'=>'1'.json_encode($reward_one)]); // Db::name('log')->insert(['data'=>'2'.json_encode($reward_two)]); // Db::name('log')->insert(['data'=>'3'.json_encode($reward_three)]); // Db::name('log')->insert(['data'=>'4'.json_encode($reward_four)]); $update_config=[]; $update=[]; if($eb_user['cumulative_money']>=$reward_one['value'] and $eb_user['cumulative_money']<$reward_two['value']){ $update['type']=2; $update_config['value']=$reward_one['id']; }elseif ($eb_user['cumulative_money']>=$reward_two['value'] and $eb_user['cumulative_money']<$reward_three['value']){ $update['type']=3; $update_config['value']=$reward_two['id']; }elseif ($eb_user['cumulative_money']>=$reward_three['value'] and $eb_user['cumulative_money']<$reward_four['value']){ $update['type']=4; $update_config['value']=$reward_three['id']; }elseif ($eb_user['cumulative_money']>=$reward_four['value']){ $update['type']=5; $update_config['value']=$reward_four['id']; } Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$eb_user['eb_id'])->update(['cumulative_money'=>bcadd($eb_user['cumulative_money'],$order_data['pay_price'],2)]); //修改此用户佣金比例 Db::name('entropy_barter_config_user_'.$mer_id)->where('eb_id',$eb_user['eb_id'])->update($update_config); //修改此用户类型 2 会员 3经理 4 总监 5 总裁 Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$eb_user['eb_id'])->update($update); }catch (Exception $exception){ Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录 } } //国腾名医单独处理 public function pay_orrder_290($order,$type) { $uid=$order['uid']; $table_name='entropy_barter_user_290'; $order=Db::name('store_order')->where('order_sn',$order['order_no'])->find(); $order['order_no']=$order['order_sn']; $product=DB::name('store_cart')->where('cart_id',$order['cart_id'])->value('product_id'); $imUserData=Db::name($table_name)->where('uid',$uid)->find(); $top_data=Db::name($table_name)->where('eb_id',$imUserData['top_eb_id'])->find(); if ($product=='362'||$product=='364'||$product=='363') { Db::name('store_order')->where('order_sn',$order['order_no'])->update(['is_split_to_tomorrow'=>1,'status'=>3]); if ($product == '362') { Db::name($table_name)->where('eb_id', $imUserData['eb_id'])->update(['type' => 1, 'pay_goods_type' => 1,'pay_status'=>1]); } else { Db::name($table_name)->where('eb_id', $imUserData['eb_id'])->update(['type' => 2, 'pay_goods_type' => 2,'pay_status'=>1]); } } /** * 奖励模式开始 */ Db::name('user_bill')->where('order_sn',$order['order_no'])->where('uid',$order['uid'])->where('source',0)->update(['status'=>1]); $order['money']=$order['pay_price']; $eb_one=$this->one_jiangli($top_data,$order,$table_name,$type); if(!$eb_one){ if($imUserData['pay_status']!=1){ $this->take_290($order['order_no'],1); }else{ // Db::name('log')->insert(['data'=>'已购买过合伙人商品或者创始人商品']); } return false; } //one_jiangli 推荐奖给了"它" $eb_two=$this->two_jiangli($top_data,$order,$table_name,$type); if(!$eb_two){ if($imUserData['pay_status']!=1){ $this->take_290($order['order_no'],1); }else{ // Db::name('log')->insert(['data'=>'已购买过合伙人商品或者创始人商品']); } return false; } //two_jiangli 推荐奖给了"它" $eb_three=$this->three_jiangli($eb_two,$order,$table_name,$type); if(!$eb_three){ if($imUserData['pay_status']!=1){ $this->take_290($order['order_no'],1); }else{ // Db::name('log')->insert(['data'=>'已购买过合伙人商品或者创始人商品']); } return false; } //three_jiangli 推荐奖给了"它" if($eb_one['eb_id']==$eb_two['eb_id']){ $eb_four=$this->four_jiangli($eb_three,$order,$table_name,$type); } /** * 奖励模式结束 */ } //推荐奖 public function one_jiangli($top_data,$order,$table_name,$type) { // dd($top_data['pay_status']==1&&$top_data['type']>2); if($top_data['pay_status']==1&&$top_data['type']>2){ $proportion=$this->reward_proportion($top_data['type']); $money=bcmul($order['money'],"0.3",2); $msg=$proportion['msg'].':推荐奖励'; $bill_data=[ 'from_id'=>0, 'to_id'=>$top_data['eb_id'], 'type'=>2, 'order_no'=>$order['order_no'], 'remarks'=>$msg, 'ctime'=>time(), 'number'=>$money,//商业合伙人或联合创始人奖励为30% 'pm'=>1, 'status'=>'2', 'on_line'=>$type, 'mer_id'=>290, 'commission_type'=>1, 'commission_scale'=>30, 'to_user_type'=>1, 'to_user_type_1'=>$proportion['type'], ]; //增加账单记录 $this->eb_user_bill($bill_data); Db::name($table_name)->where('eb_id',$top_data['eb_id'])->inc('wallet',$money)->update(); Db::name($table_name)->where('eb_id',$top_data['eb_id'])->inc('ranking_money',$money)->update(); $data=[ 'type'=>$top_data['type'], 'eb_id'=>$top_data['eb_id'] ]; } else{ // if($top_data['type']>=1){ // $money=bcmul($order['money'],"0.3",2); // Db::name($table_name)->where('eb_id',$top_data['eb_id'])->inc('precipitate',$money)->update(); // $data=[ // 'type'=>$top_data['type'], // 'eb_id'=>$top_data['eb_id'] // ]; // } $data=[12313]; } return $data; } //一级奖励 public function two_jiangli($top_data,$order,$table_name,$type) { // dd($top_data['type']>2); if($top_data['type']>2){ $proportion=$this->reward_proportion($top_data['type']); $money=bcmul($order['money'],$proportion['proportion'],2); $msg=$proportion['msg'].':管理奖励'; $bill_data=[ 'from_id'=>0, 'to_id'=>$top_data['eb_id'], 'type'=>2, 'order_no'=>$order['order_no'], 'remarks'=>$msg, 'ctime'=>time(), 'number'=>$money,//商业合伙人或联合创始人奖励为30% 'pm'=>1, 'status'=>'2', 'on_line'=>$type, 'mer_id'=>290, 'commission_type'=>1, 'commission_scale'=>$proportion['proportion']*100, 'to_user_type'=>2, 'to_user_type_1'=>$proportion['type'], ]; //增加账单记录 $this->eb_user_bill($bill_data); Db::name($table_name)->where('eb_id',$top_data['eb_id'])->inc('wallet',$money)->update(); Db::name($table_name)->where('eb_id',$top_data['eb_id'])->inc('ranking_money',$money)->update(); $data=[ 'eb_id'=>$top_data['eb_id'], 'type'=>$top_data['type'] ]; }else{ $top_1_id=$this->recursion_top($top_data['top_eb_id'],'0'); if($top_1_id==0){ return false; } $top_1_data=Db::name($table_name)->where('eb_id',$top_1_id)->find(); $proportion=$this->reward_proportion($top_1_data['type']); $money=bcmul($order['money'],$proportion['proportion'],2); $msg=$proportion['msg'].':管理奖励'; $bill_data=[ 'from_id'=>0, 'to_id'=>$top_1_data['eb_id'], 'type'=>2, 'order_no'=>$order['order_no'], 'remarks'=>$msg, 'ctime'=>time(), 'number'=>$money,//商业合伙人或联合创始人奖励为30% 'pm'=>1, 'status'=>'2', 'on_line'=>$type, 'mer_id'=>290, 'commission_type'=>1, 'commission_scale'=>$proportion['proportion']*100, 'to_user_type'=>2, 'to_user_type_1'=>$proportion['type'], ]; //增加账单记录 $this->eb_user_bill($bill_data); Db::name($table_name)->where('eb_id',$top_1_data['eb_id'])->inc('wallet',$money)->update(); Db::name($table_name)->where('eb_id',$top_1_data['eb_id'])->inc('ranking_money',$money)->update(); $data=[ 'type'=>$top_1_data['type'], 'eb_id'=>$top_1_data['eb_id'] ]; } return $data; } //二级奖励 public function three_jiangli($top_data,$order,$table_name,$type) { $top=$top_data; $top_data=Db::name($table_name)->where('eb_id',$top['eb_id'])->find(); $top_top_data=Db::name($table_name)->where('eb_id',$top_data['top_eb_id'])->find(); //// dd($top_top_data>2); // dd($top['type']==$top_top_data['type']||$top['type']>$top_top_data['type']); if($top_top_data['type']>2){ if($top['type']==$top_top_data['type']||$top['type']>$top_top_data['type']){ $proportion=$this->reward_proportion($top_top_data['type']); $proportion['proportion']='0.02'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3); }elseif($top['type']<$top_top_data['type']){ if($top_top_data['type']==4){ $proportion=$this->reward_proportion($top_top_data['type']); $proportion['proportion']='0.06'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3); }elseif($top_top_data['type']==5){ if($top['type']==3){ $proportion=$this->reward_proportion($top_top_data['type']); $proportion['proportion']='15'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3); return false; }else{ $proportion=$this->reward_proportion($top_top_data['type']); $proportion['proportion']='0.09'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3); } }elseif($top_top_data['type']==3){ $proportion=$this->reward_proportion($top_top_data['type']); $proportion['proportion']='0.03'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3); } } $data=[ 'eb_id'=>$top_top_data['eb_id'], 'type'=>$top_top_data['type'] ]; }else{ $top_1_id=$this->recursion_top($top_data['top_eb_id'],'0'); if($top_1_id==0){ return false; } $top_1_data=Db::name($table_name)->where('eb_id',$top_1_id)->find(); if($top['type']==$top_1_data['type']||$top['type']>$top_1_data['type']){ $proportion=$this->reward_proportion($top_1_data['type']); $proportion['proportion']='0.02'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_1_data['eb_id'],$table_name,$proportion,3); }elseif($top['type']<$top_1_data['type']){ if($top_1_data['type']==4){ $proportion=$this->reward_proportion($top_1_data['type']); $proportion['proportion']='0.06'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_1_data['eb_id'],$table_name,$proportion,3); }elseif($top_1_data['type']==5){ $proportion=$this->reward_proportion($top_1_data['type']); $proportion['proportion']='0.09'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_1_data['eb_id'],$table_name,$proportion,3); }elseif($top_1_data['type']==3){ $proportion=$this->reward_proportion($top_1_data['type']); $proportion['proportion']='0.02'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,3); } } $data=[ 'eb_id'=>$top_1_data['eb_id'], 'type'=>$top_1_data['type'] ]; } return $data; } //三级奖励 public function four_jiangli($top_data,$order,$table_name,$type) { $top=$top_data; $top_data=Db::name($table_name)->where('eb_id',$top['eb_id'])->find(); $top_top_data=Db::name($table_name)->where('eb_id',$top_data['top_eb_id'])->find(); if(!$top_top_data){ return false; } if($top_top_data['type']>2){ if($top['type']<$top_top_data['type']){ if($top_top_data['type']==4){ $proportion=$this->reward_proportion($type); $proportion['proportion']='0.06'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,4); }elseif($top_top_data['type']==5){ $proportion=$this->reward_proportion($type); $proportion['proportion']='0.09'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,4); }elseif($top_top_data['type']==3){ $proportion=$this->reward_proportion($type); $proportion['proportion']='0.03'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_top_data['eb_id'],$table_name,$proportion,4); } } $data=[ 'eb_id'=>$top_top_data['eb_id'], 'type'=>$top_top_data['type'] ]; }else{ $top_1_id=$this->recursion_top($top_data['top_eb_id'],'0'); if($top_1_id==0){ return false; } $top_1_data=Db::name($table_name)->where('eb_id',$top_1_id)->find(); if($top['type']<$top_1_data['type']){ if($top_1_data['type']==4){ $proportion=$this->reward_proportion($top_1_data['type']); $proportion['proportion']='0.06'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_1_data['eb_id'],$table_name,$proportion,4); $data=[ 'eb_id'=>$top_1_data['eb_id'], 'type'=>$top_1_data['type'] ]; }elseif($top_1_data['type']==5){ $proportion=$this->reward_proportion($top_1_data['type']); $proportion['proportion']='0.09'; $this->jiangli_cl($type,$order['money'],$order['order_no'],$top_1_data['eb_id'],$table_name,$proportion,4); $data=[ 'eb_id'=>$top_1_data['eb_id'], 'type'=>$top_1_data['type'] ]; }else{ return false; } }else{ return false; } } return $data; } public function jiangli_cl($type,$money,$order_no,$eb_id,$table_name,$proportion,$to_user_type) { $money=bcmul($money,$proportion['proportion'],2); $msg=$proportion['msg'].':管理奖励'; $bill_data=[ 'from_id'=>0, 'to_id'=>$eb_id, 'type'=>2, 'order_no'=>$order_no, 'remarks'=>$msg, 'ctime'=>time(), 'number'=>$money,//商业合伙人或联合创始人奖励为30% 'pm'=>1, 'status'=>'2', 'on_line'=>$type, 'mer_id'=>290, 'commission_type'=>1, 'commission_scale'=>$proportion['proportion']*100, 'to_user_type'=>$to_user_type, 'to_user_type_1'=>$proportion['type'], ]; // dd($bill_data); //增加账单记录 $this->eb_user_bill($bill_data); Db::name($table_name)->where('eb_id',$eb_id)->inc('wallet',$money)->update(); Db::name($table_name)->where('eb_id',$eb_id)->inc('ranking_money',$money)->update(); } //获取奖励比例 public function reward_proportion($type) { switch ($type){ case '3': $proportion=[ "proportion"=>'0.03', 'msg'=>'经理', 'type'=>3, ]; break; case '4': $proportion=[ "proportion"=>'0.09', 'msg'=>'总监', 'type'=>4, ]; break; case '5': $proportion=[ "proportion"=>'0.18', 'msg'=>'总裁', 'type'=>5, ]; break; default: case '2': case '1': $proportion=[ "proportion"=>'0', 'msg'=>'其它', 'type'=>0, ]; } return $proportion; } //国腾名医确认收货单独处理 public function take_290($order_no,$type=2) { Db::name('log')->insert(['data'=>'290进来了5']); if($type==1){ $store_table_name='store_order'; $eb_table_name='entropy_barter_user_290'; $orde_data=Db::name($store_table_name)->where('order_sn',$order_no)->find(); $eb_data=Db::name($eb_table_name)->where('uid',$orde_data['uid'])->find(); // Db::name('user_bill')->where('order_sn',$order_no)->where('uid',$orde_data['uid'])->where('source',0)->update(['status'=>1]); // $mer_id=Db::name('store_order')->where('order_sn',$order_no)->value('mer_id'); // $data=Db::name('entropy_barter_bill')->where('mer_id',$mer_id)->where('order_no',$order_no)->select(); // foreach ($data as $k=>$v){ // if($v['status']=='1'){ // if($v['type']==2){ // Db::name($eb_table_name)->where('eb_id',$v['to_id'])->inc('wallet',$v['number'])->update(); // Db::name($eb_table_name)->where('eb_id',$v['to_id'])->dec('integral',$v['number'])->update(); // Db::name('entropy_barter_bill')->where('id',$v['id'])->update(['status'=>2]); // }elseif ($v['type']==1){ // Db::name($eb_table_name)->where('eb_id',$v['to_id'])->inc('integral',$v['number'])->update(); // Db::name('entropy_barter_bill')->where('id',$v['id'])->update(['status'=>2]); // } // } // } //特殊的地方开始处理了 //如果是特殊商品可以接着执行 $product_id=Db::name('store_cart')->where('cart_id',$orde_data['cart_id'])->value('product_id'); if($product_id==''){ return ''; }elseif ($product_id=='362'||$product_id=='364'||$product_id=='363'){ // Db::name('store_order')->where('order_sn',$order_no)->update(['is_split_to_tomorrow'=>1,'status'=>3]); //查找上级是否可升级 $eb_data['top_eb_id']--上级ID // if($product_id=='362'){ // Db::name($eb_table_name)->where('eb_id',$eb_data['eb_id'])->update(['type'=>2,'pay_goods_type'=>2]); // }else{ // Db::name($eb_table_name)->where('eb_id',$eb_data['eb_id'])->update(['type'=>1]); // // } $top_data=Db::name($eb_table_name)->where('eb_id',$eb_data['top_eb_id'])->find(); if($top_data['type']!=0){ Db::name('log')->insert(['data'=>'上级是会员']); $this->recursion($top_data['eb_id']); }else{ Db::name('log')->insert(['data'=>'上级不是会员'.$top_data['eb_id']]); } } } } public function recursion($eb_id) { try { $eb_table_name='entropy_barter_user_290';//1111 $eb_data=Db::name($eb_table_name)->where('eb_id',$eb_id)->find(); if($eb_data['type']==1){//一和二是同级别 $eb_data['type']=2; } if($eb_data['type']==0){ return ''; } Db::name('guoteng_famous_doctor_relation')->insert(['uid'=>$eb_data['uid'],'type'=>$eb_data['type'],'create_time'=>date('Y-m-d H:i:s')]); $top_upgrade_num=Db::name('guoteng_famous_doctor_relation')->where('type',$eb_data['type'])->where('uid',$eb_data['uid'])->count('id'); if($top_upgrade_num>=3){//如果该等级的数量大于3则升级 if($eb_data['type']==5){ return '已达到最高级别'; } Db::name($eb_table_name)->where('uid',$eb_data['uid'])->update(['type'=>$eb_data['type']+1]); if($eb_data['type']+1==3){ // $money=Db::name($eb_table_name)->where('uid',$eb_data['uid'])->value('precipitate'); $money=systemConfig('manager_reward'); $bill_data=[ 'from_id'=>0, 'to_id'=>$eb_data['eb_id'], 'type'=>2, 'order_no'=>'0000000000000000', 'remarks'=>'升级经理奖励', 'ctime'=>time(), 'number'=>$money,//商业合伙人或联合创始人奖励为30% 'pm'=>1, 'status'=>'2', 'on_line'=>1, 'mer_id'=>290, 'commission_type'=>1, 'commission_scale'=>0, ]; //增加账单记录 $this->eb_user_bill($bill_data); Db::name($eb_table_name)->where('eb_id',$eb_data['eb_id'])->inc('wallet',$money)->update(); Db::name($eb_table_name)->where('eb_id',$eb_data['eb_id'])->inc('ranking_money',$money)->update(); } if($eb_data['top_eb_id']!=0){ $this->recursion($eb_data['top_eb_id']); }else{ return '成功1'; } }else{ return '小于3'; } return '成功2'; }catch (\Exception $e) { Db::name('log')->insert(['data'=>'订单支付出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']); } } //查找上级递归循环 public function recursion_top($eb_id,$my_type) { $data=Db::name('entropy_barter_user_290')->where('eb_id',$eb_id)->field('top_eb_id,eb_id,type,pay_status')->find(); if(!$data){ return 0; } if($data['pay_status']==1&&$data['type']>2){ // return $data['eb_id']; return $data['eb_id']; }elseif($data['pay_status']!=1||$data['type']<2){ return $this->recursion_top($data['top_eb_id'],$my_type); } } }