whereIn('status', [0, 1, 2, 3]) ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440]) ->whereBetween("pay_time", [$startTime, $endTime]) ->whereNotNull("pay_time") // 排除 pay_time 为 NULL 的订单 ->select(); // 计算总业绩 $totalPv = 0; foreach ($orders as $order) { switch ($order['total_price']) { case 1180: $totalPv += 700; break; case 11800: $totalPv += 7000; break; case 10620: $totalPv += 6300; break; case 2360: $totalPv += 1400; break; case 9440: $totalPv += 5600; break; } } return $totalPv; } public function lst1() { return; // $user_datas = Db::name("user")->select();//星级等级 // foreach($user_datas as $k=>$v){ // if($v['user_level_id_old']==2){ // Db::name("user")->where("uid",$v['uid'])->update(["user_group"=>2]); // }else if($v['user_level_id_old']==4){ // Db::name("user")->where("uid",$v['uid'])->update(["user_group"=>3]); // } // } // 查询当前用户及其子级的所有订单 //$totalPv = $this->getTeamPvByTime('this_week'); // var_dump($totalPv);return; // $sf = $this->getStarLevel(221); //$ss = $this->getbig_samll_datas(17);//222 //var_dump($ss); //$ff = $this->getPerformanceOf(221); // var_dump($ff); //var_dump($ss); // return; // $store_product_datas = Db::name('old_user_of_goods_old')->select(); //$week_record = 45500 + 1400 + 60000; //20250218 //$week_record =23800 + 60000; //20250222 // $week_record = 64400; //20250301 } //添加复购金 public function fugou_user_log($uid,$num,$order_id,$type_inc_des,$status=-1){ $fugou_data = Db::name('user')->where("uid",$uid)->find(); $bill = [ 'uid'=>$uid, 'number'=>$num,//数量 'status'=>$status,//复购金状态1-有效 0-失效 -1待确认 'mark'=>"复购金",//备注 'desc'=>"10%复购金",//描述 'order_id'=>$order_id,//订单id 'surplus'=>0,//剩余 'order_type'=>11,//关联订单ID 'type'=>$type_inc_des,//复购金类型 :1赠送,2消耗 'settlement_time'=>date('Y-m-d H:i:s'),//添加时间, 'addtime'=>time(), ]; Db::name('user_sign_fugou')->insert($bill); } //添加平台分佣2.0系统收益明细日志(养老金金额) public function bill_user_log111111($uid,$name,$num,$mark,$comm){ $con_data = Db::name('user')->where("uid",$uid)->find(); //如果是会员专区就即刻到账 // Db::name('user')->where("uid",$con_data['uid'])->update(['brokerage_price'=> $con_data['brokerage_price'] + $num]); $bill = [ 'uid'=>$uid, 'link_id'=>0,//关联订单id 'pm'=>1,//0:支出,1:获得 'title'=>$name,//账单标题 'category'=>'now_money',//明细种类 'type'=>'commission',//明细类型 'number'=>$num,//明细数字 'balance'=>0,//剩余 'mark'=>$mark,//备注 'create_time'=>date('Y-m-d H:i:s'),//添加时间 'status'=>1,//0待确定,1有效,-1无效 'commission_type'=>$comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费 //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金 //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’ 'order_sn'=>0,//订单号 'tripartite'=>0,// 'type_shop'=>0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上 'mer_id'=>0,//商户id 'source'=>0,//1线下 0线上 'order_type'=>1,//1自营 2 第三方 订单类型 'is_red_brokerage'=>0,//1红积分对冲佣金 0正常佣金 'gzc'=>3,//养老金是否已进入公证处log表0:未进入。1:已进入 'take_time'=>'',//结算时间 'district_id'=>'',// 'street_id'=>'',// 'month'=>'',//月份 ]; Db::name('user_bill')->insert($bill); } // //上周 public function getWeekStartEnd() { $now = time(); // 计算上周日 00:00 的时间戳 $last_sunday_start = strtotime('last Sunday', $now); // 计算这周一 00:00 的时间戳 $this_monday_start = strtotime('this Monday', $last_sunday_start); // 上周日 23:59:59 的时间戳,即这周一 00:00 $last_sunday_end = $this_monday_start - 1; // 上周一 00:00 的时间戳,即上周日 24:00 $last_monday_start = $this_monday_start - 604800; return [$last_monday_start, $last_sunday_end]; } //本周 // public function getWeekStartEnd() // { // $now = time(); // // 计算本周一 00:00 的时间戳 // $monday_start = strtotime('last Monday', $now); // if (date('w', $now) == 1) { // // 如果今天是周一,直接取今天的 00:00 // $monday_start = strtotime('today', $now); // } // // 计算本周日 23:59:59 的时间戳 // $sunday_end = strtotime('next Sunday', $now) + 86399; // return [$monday_start,$sunday_end]; // } /** * 获取用户星级 */ public function getStarLevel($user_id,$team_money=0,$person_money=0) { if(empty($team_money)) { $common_nums = $this->getCommonNums($user_id);//获取共建联盟(当前userid下面所属的所有的共建联盟的userid集合),例子:传入的uerid=12,数据格式就是 array(49,52,54,...)这些都是他的团队id集合 $team_money = 0; //return $common_nums; foreach ($common_nums as $key => $value) { //return $value; # code... $amount = $this->getPerformance1($value);//获取流水信息($user_id下面的团队id,团队id中,每个id,获取自己和自己是推荐人(node_id是自己id)的所有消费金额) $team_money += $amount; } //计算自己的共建联盟流水 $user_team_amount = $this->getperteamcomm($common_nums,$user_id); $team_money += $user_team_amount; }else{ $common_nums = $this->getCommonNums($user_id); } if(empty($person_money)) { $person_nums = $this->getPersonageNums($user_id);//获取个人联盟(当前userid下面所属的所有的个人联盟的userid集合) $person_amount = 0; foreach ($person_nums as $key => $value) { # code... $amount = $this->getPerformance1($value); $person_amount += $amount; } $person_money = $person_amount; //计算自己的个人联盟总流水 //$user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->sum("money"); //$user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2); $user_person_amount = $this->getperteamcomm($person_nums,$user_id); $person_money += $user_person_amount; }else{ $person_nums = $this->getPersonageNums($user_id); } //计算个人在2.0新表中的业绩 start $team_small_big_amount = $this->getbig_samll_datas($user_id);//下标0是大部门,下标1是小部门 $person_money += $team_small_big_amount[1]; $team_money += $team_small_big_amount[0]; //end //默认是小联盟,如果大联盟业绩比小联盟低,那就谁选业绩低的 $slow = $person_money; if($team_money < $person_money) { $slow = $team_money; } $sum_money = $team_money + $person_money; // var_dump($sum_money); // var_dump($slow); $star_list = Db::name("old_user_starlevel")->order("statement_all_num desc")->select(); $start_level = ""; foreach ($star_list as $key => $value) { # code... //星级列表中 statement_all_num是共建联盟,person_statement是个人联盟 if( $sum_money>=$value['statement_all_num'] && $slow >= $value['person_statement']) { return $value; } } return $start_level; } /** * 获取该用户共建联盟 */ public function getCommonNums($user_id){ //先获取共建联盟下用户的id //$son_ids = Db::name("user")->where("spread_old",$user_id)->where("is_team_old",1)->select()->toArray(); //先获取共建联盟下用户的id $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray(); $new_array_ids =[]; foreach ($son_ids as $key => $value) { # code... $son_id = $value['id']; $new_array_ids = array_merge($new_array_ids,[$son_id]); $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray(); if(count($son_value_ids) > 0) { $son_value_ids = array_column($son_value_ids,"id"); $new_array_ids = array_merge($new_array_ids,$son_value_ids); } } return $new_array_ids; } /** * 获取流水信息 */ public function getPerformance1($user_id) { // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money"); // $amount = isset($amount) ? round($amount*0.7,2) : 0; // return $amount; $user_team_amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->where('money', 1180)->select(); // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后) $money1180Sum = 0; foreach ($user_team_amount as $record) { $money1180Sum += $record['money'] - 300 - 180; } // 获取 status 为 1 且 money 为 11800 的记录集合 $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->where('money', 11800)->select(); // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后) $money11800Sum = 0; foreach ($money11800Records as $record) { $money11800Sum += $record['money'] - 3000 - 1800; } $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->where('money', 10620)->select(); // 计算 status 为 1 且 money 为 10620 的记录总和(减去相应值后) $money10620Sum = 0; foreach ($money10620Records as $record) { $money10620Sum += $record['money'] - 2700 - 1620; } $money9440Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->where('money', 9440)->select(); // 计算 status 为 1 且 money 为 9440 的记录总和(减去相应值后) $money9440Sum = 0; foreach ($money9440Records as $record) { $money9440Sum += $record['money'] - 2400 - 1440; } $money2360Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->where('money', 2360)->select(); // 计算 status 为 1 且 money 为 2360 的记录总和(减去相应值后) $money2360Sum = 0; foreach ($money2360Records as $record) { $money2360Sum += $record['money'] - 600 - 360; } // 计算除去特定值后的总和 //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select(); $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->whereNotIn('money', [1180, 11800 , 10620 , 9440 ,2360])->select(); $otherMoneySum = 0; foreach ($otherMoneyRecords as $record) { $otherMoneySum += $record['money']; } // 分别处理特定值的情况并加上其他值的总和 $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + $money9440Sum + $money2360Sum + round($otherMoneySum * 0.7,2); //end return $all_record_nums; } /** * 获取该用户个人联盟 */ public function getPersonageNums($user_id){ $son_ids = Db::name("user")->where("spread_old",$user_id)->where("is_team_old",0)->field("uid")->select(); $new_array_ids =[]; foreach ($son_ids as $key => $value) { # code... $son_id = $value['uid']; $new_array_ids = array_merge($new_array_ids,[$son_id]); $son_value_ids = Db::name("user")->whereRaw("FIND_IN_SET('$son_id',parent_ids_old)")->field("uid")->select()->toArray(); if(count($son_value_ids) > 0) { $son_value_ids = array_column($son_value_ids,"uid"); $new_array_ids = array_merge($new_array_ids,$son_value_ids); } } return $new_array_ids; } /** * 获取指定用户业绩 */ public function getPerformanceOf($user_id) { //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv $common_nums = $this->getCommonNums($user_id); $person_nums = $this->getPersonageNums($user_id); $team_amount = 0; $person_amount = 0; // $common_nums[] = $user_id; foreach ($common_nums as $key => $value) { # code... $amount = $this->getPerformance1($value); $team_amount += $amount; } foreach ($person_nums as $key => $value) { # code... $amount = $this->getPerformance1($value); $person_amount += $amount; } //添加自己共建联盟的流水 //$user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money"); //$user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2); $user_team_amount = $this->getperteamcomm($common_nums,$user_id); $team_amount += $user_team_amount; // //计算自己的个人联盟总流水 //$user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->sum("money"); // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2); $user_person_amount = $this->getperteamcomm($person_nums,$user_id); // var_dump("|||"); // var_dump($person_amount); // var_dump($user_person_amount); $person_amount += $user_person_amount; // var_dump($person_amount); // var_dump("|||"); //var_dump($team_amount); //var_dump($person_amount); $sum_nums_pv = $team_amount + $person_amount; $sum_nums_pv = isset($sum_nums_pv) ? $sum_nums_pv :0; //计算个人在2.0新表中的业绩 start $team_small_big_amount = $this->getbig_samll_datas($user_id);//下标0是大部门,下标1是小部门 $total_team_amount3 = $team_small_big_amount[0] + $team_small_big_amount[1]; $sum_nums_pv += $total_team_amount3; //end return $sum_nums_pv; } //计算自己和自己团队下面的业绩。新表 public function calculatePerformance($uid) { // 初始化业绩数组 $performance = [ 'personal_performance' => 0, // 个人业绩 'team_performance' => 0, // 团队业绩 'total_performance' => 0, // 总业绩 'team_count' => 0, // 加上自己的团队数量 ]; // 定义业绩换算规则 $performanceMapping = [ 1180 => 700, 10620 => 6300, 11800 => 7000, 9440 => 5600, 2360 => 1400 ]; // 计算个人业绩 $personalOrder = Db::name('store_order')->where("uid", $uid)->find(); if ($personalOrder) { // 将浮点数转换为整数 $totalPrice = (int)$personalOrder['total_price']; if (isset($performanceMapping[$totalPrice])) { $performance['personal_performance'] = $performanceMapping[$totalPrice]; } } // 计算旗下团队成员的业绩 $teamOrders = Db::name('user') ->alias('u') ->join('store_order so', 'u.uid = so.uid', 'LEFT') ->where("u.spread_uid", $uid) // 查询旗下会员 ->where("so.mer_id", 496) // ->where("so.douhuomall", 1) // ->where("so.douhuomall_status", 9) // ->where("so.status", 0) ->select(); $teamOrders_count = Db::name('user') ->alias('u') ->join('store_order so', 'u.uid = so.uid', 'LEFT') ->where("u.spread_uid", $uid) // 查询旗下会员 ->where("so.mer_id", 496) // ->where("so.douhuomall", 1) // ->where("so.douhuomall_status", 9) // ->where("so.status", 0) ->count(); $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量 foreach ($teamOrders as $order) { if ($order['total_price']) { // 将浮点数转换为整数 $totalPrice = (int)$order['total_price']; if (isset($performanceMapping[$totalPrice])) { $performance['team_performance'] += $performanceMapping[$totalPrice]; } } } // 计算总业绩 $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance']; // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false return $performance; } //只获取数组中的业绩 public function getteampv($common_nums) { // 查询当前用户及其子级的所有订单 $orders = Db::name("store_order") ->whereIn('status', [0, 1, 2, 3]) ->whereIn("uid", $common_nums) ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440]) ->select(); // 计算总业绩 $totalPv = 0; foreach ($orders as $order) { // var_dump($order['uid']."订单:".$order['total_price']); if ($order['total_price'] == 1180) { $totalPv += 700; } else if ($order['total_price'] == 11800) { $totalPv += 7000; } else if ($order['total_price'] == 10620) { $totalPv += 6300; } else if ($order['total_price'] == 2360) { $totalPv += 1400; } else if ($order['total_price'] == 9440) { $totalPv += 5600; } } return $totalPv; } // 2.0 根据父级uid,找到当前用户下面的UID public function getChildren($parentUid) { $result = []; // 用于存储所有子级的 uid $children = Db::name("user") ->where("spread_uid", $parentUid) ->column("uid"); // 获取子级的 uid 列表 return $children; // 返回结果数组,并去重 } //根据传递的父级数组,返回他的对应子级的个数 public function getTeamSize($parentUids) { // 初始化结果数组 $result = []; // 遍历每个父级ID foreach ($parentUids as $parentUid) { // 递归获取所有子级 UID $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) { $children = Db::name("user") ->where("spread_uid", $parentUid) ->column("uid"); // 确保返回的是数组 if (!is_array($children)) { return []; } $allChildren = []; foreach ($children as $childUid) { $allChildren[] = $childUid; $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid)); } return $allChildren; }; // 获取当前父级及其所有子级的 UID $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid)); // 计算总个数(包括父级自身) $totalUids = count($allUids); // 将结果存入数组 $result[] = [ 'parent_uid' => $parentUid, 'total_count' => $totalUids ]; } return $result; } // 递归获取所有子级 UID 的业绩 public function getTeamPv11($parentUid) { $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) { $children = Db::name("user") ->where("spread_uid", $parentUid) ->column("uid"); $allChildren = []; foreach ($children as $childUid) { $allChildren[] = $childUid; $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid)); } return $allChildren; }; // 获取当前用户及其所有子级的 UID $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid)); // 查询当前用户及其子级的所有订单 $orders = Db::name("store_order") ->whereIn('status', [0, 1, 2, 3]) ->whereIn("uid", $allUids) ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440]) ->select(); // 计算总业绩 $totalPv = 0; foreach ($orders as $order) { switch ($order['total_price']) { case 1180: $totalPv += 700; break; case 11800: $totalPv += 7000; break; case 10620: $totalPv += 6300; break; case 2360: $totalPv += 1400; break; case 9440: $totalPv += 5600; break; } } return $totalPv; } public function getTeamPv22($parentUid) { // 定义递归函数,用于获取所有子级 UID 的业绩 $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) { $children = Db::name("user") ->where("spread_uid", $parentUid) ->column("uid"); $allChildren = []; foreach ($children as $childUid) { $allChildren[] = $childUid; $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid)); } return $allChildren; }; // 获取当前用户及其所有子级的 UID $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid)); // 查询当前用户及其子级的所有订单 $orders = Db::name("store_order") ->whereIn('status', [0, 1, 2, 3]) ->whereIn("uid", $allUids) ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440]) ->select(); // 计算总业绩 $totalPv = 0; foreach ($orders as $order) { switch ($order['total_price']) { case 1180: $totalPv += 700; break; case 11800: $totalPv += 7000; break; case 10620: $totalPv += 6300; break; case 2360: $totalPv += 1400; break; case 9440: $totalPv += 5600; break; } } return $totalPv; } public function processArray($array) { // 初始化结果数组 $result = [ 'max_value' => null, // 最大值 'max_index' => null, // 最大值的下标 'remaining_sum' => 0 // 剩余值的总和 ]; // 检查数组是否为空 if (empty($array)) { return $result; } // 找出最大值及其下标 $maxValue = $array[0]; $maxIndex = 0; for ($i = 1; $i < count($array); $i++) { if ($array[$i] > $maxValue) { $maxValue = $array[$i]; $maxIndex = $i; } } // 计算剩余值的总和 $remainingSum = 0; for ($i = 0; $i < count($array); $i++) { if ($i != $maxIndex) { $remainingSum += $array[$i]; } } // 将结果存入数组 $result['max_value'] = $maxValue; $result['max_index'] = $maxIndex; $result['remaining_sum'] = $remainingSum; return $result; } // 根据父级uid,递归获取所有子级UID数组 // function getRecursiveChildren($parentUid) { // $result = []; // 用于存储所有子级的 uid // // 定义递归函数 // $recursion = function ($parentUid) use (&$result, &$recursion) { // // 查询当前父级的所有直接子级 // $children = Db::name("user") // ->where("spread_uid", $parentUid) // ->column("uid"); // 获取子级的 uid 列表 // // 如果没有子级,直接返回 // if (empty($children)) { // return; // } // // 遍历每个子级 // foreach ($children as $childUid) { // $result[] = $childUid; // 将子级的 uid 添加到结果数组 // $recursion($childUid); // 递归查询子级的子级 // } // }; // // 从初始父级开始递归查询 // $recursion($parentUid); // return array_unique($result); // 返回结果数组,并去重 // } // 根据父级uid,递归获取所有子级UID数组 public function getRecursiveChildren($parentUid) { $result = []; // 用于存储符合条件的子级 uid // 定义递归函数 $recursion = function ($parentUid) use (&$result, &$recursion) { // 查询当前父级的所有直接子级 $children = Db::name("user") ->where("spread_uid", $parentUid) ->column("uid"); // 获取子级的 uid 列表 // 如果没有子级,直接返回 if (empty($children)) { return; } // 遍历每个子级 foreach ($children as $childUid) { // 如果子级的 uid 小于或等于 611,跳过该子级及其所有子级 if ($childUid <= 611) { continue; } // 将符合条件的子级 uid 添加到结果数组 $result[] = $childUid; // 递归查询子级的子级 $recursion($childUid); } }; // 从初始父级开始递归查询 $recursion($parentUid); return array_unique($result); // 返回结果数组,并去重 } //挑出大小值 function getMaxAndSumRest($array) { // 检查数组是否为空 if (empty($array)) { return null; // 如果数组为空,返回 null 或其他默认值 } // 找出数组中的最大值 $maxValue = max($array); // 找到第一个最大值的键 $maxKey = array_search($maxValue, $array); // 移除第一个最大值 unset($array[$maxKey]); // 将剩下的值相加 $sumRest = array_sum($array); // 返回结果 return [ 'maxValue' => $maxValue, 'sumRest' => $sumRest ]; } //获取大小部门业绩(新表小标0是大部门,下标1是小部门) public function getbig_samll_datas($user_id) { //$user_id = 593; $common_nums = $this->getCommonNums($user_id); //var_dump( $common_nums); $child_nums = []; $result_big_team_arr = []; $get_teams_per_pv = 0;//获取当前用户在2.0中小部门的总业绩 $get_teams_comm_pv=0; //1.0系统中有下级,需要在2.0中再加下级数据 if($user_id < 611){ //var_dump($common_nums); //用户三峡所有在2.0系统下面的业绩和人数 start $child_nums = []; //再加上当前用户直属的子级 // $common_ns = $common_nums; // $common_ns[] = $user_id; //获取当前用户 foreach($common_nums as $v){ $child_nums[] = $this->getRecursiveChildren($v); } // var_dump($child_nums); //去除空数组,并重新组合有数据的数组 $filteredData = array_filter($child_nums, function($array) { return !empty($array); // 如果数组不为空,则保留 }); // 合并所有非空数组 foreach ($filteredData as $array) { $result_big_team_arr = array_merge($result_big_team_arr, $array); } // var_dump($result_big_team_arr); //获取当前用户下面在2.0中的下级所有PV $get_teams_comm_pv = $this->getteampv($result_big_team_arr); //var_dump("大区业绩:" . $get_teams_comm_pv ); //获取当前用户在2.0中小区的业绩 $person_nums = $this->getPersonageNums($user_id); //var_dump($person_nums); $result_small_team_arr = []; //用户三峡所有在2.0系统下面的业绩和人数 start $child_nums_mix = []; //获取当前用户 foreach($person_nums as $v){ $child_nums_mix[] = $this->getRecursiveChildren($v); } //去除空数组,并重新组合有数据的数组 $filteredData_1 = array_filter($child_nums_mix, function($array) { return !empty($array); // 如果数组不为空,则保留 }); // 合并所有非空数组 $result_small_team_arr = []; foreach ($filteredData_1 as $array) { $result_small_team_arr = array_merge($result_small_team_arr, $array); } //var_dump($result_small_team_arr); //获取当前用户下面在2.0中的下级所有PV $get_teams_per_pv = $this->getteampv($result_small_team_arr); // var_dump("小区业绩:" . $get_teams_per_pv); //获取当前用户在2.0中小区的业绩 end }else{ $get_teams_comm_datas = []; //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门 $child_nums = $this->getChildren($user_id); if(count($child_nums) > 0){ if(count($child_nums)==1){ //var_dump($child_nums); //获取父级子级下面的个人 $get_teams_comm_pv = $this->getTeamPv11($child_nums[0]);//如果有只有个父级ID,默认为大部门,小部门为0 // var_dump($get_teams_comm_pv); }else if(count($child_nums) > 1){ foreach($child_nums as $v){ $get_teams_comm_datas[] = $this->getTeamPv11($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行 } $get_big_small_pv = $this->getMaxAndSumRest($get_teams_comm_datas);//区分大小部门业绩 // var_dump($get_big_small_pv ); //var_dump($get_big_small_pv); $get_teams_comm_pv = $get_big_small_pv['maxValue']; $get_teams_per_pv = $get_big_small_pv['sumRest']; } } //如果当前用户只有一个子级,那么就是默认一个大部门 } // $team_amount = 0; // $person_amount = 0; if($user_id < 611){ //如果当前用户直推,在2.0没有下级就不用再调用这个方法了 $getchild = db::name("user")->where("spread_uid",$user_id)->select(); if(count($getchild) > 0){ //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门) //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中 $b_s = $this->getparents_child_pv11($user_id,$get_teams_comm_pv, $get_teams_per_pv); //var_dump( $b_s);echo "yyyyyyyyyyyyy"; $get_teams_comm_pv = $b_s[0]; $get_teams_per_pv = $b_s[1]; } } if($user_id == 523){ $get_teams_per_pv += 7000; } // 计算大部门和小部门的汇总信息 $majorDepartmentSummary = [ "total_performance" => $get_teams_comm_pv, ]; $minorDepartmentSummary = [ "total_performance" => $get_teams_per_pv, ]; // 返回所需的结果 return [ $majorDepartmentSummary['total_performance'], $minorDepartmentSummary['total_performance'] ]; } //1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据 public function getparents_child_pv11($user_id, $bigamount, $smallamount) { // 获取直接下级的 UID 列表 $get_childs = Db::name("user") ->where("spread_uid", $user_id) ->column("uid"); // 如果没有直属下级,直接返回 [0, 0] if (empty($get_childs)) { return [0, 0]; } // 初始化数组存储直属下级的业绩 $all_departments = []; // 遍历每个直属下级 foreach ($get_childs as $child) { // 获取当前下级及其子级 $child_group = [$child]; $recursive_children = $this->getRecursiveChildren($child); $child_group = array_merge($child_group, $recursive_children); // 获取当前分组的业绩 $result = $this->getteampv($child_group); //var_dump( $result); // 如果返回的业绩为 null 或 0,直接返回 [0, 0] // if ($result === null || $result == 0) { // return [0, 0]; // } // 将直属下级的业绩加入数组 $all_departments[] = $result; } if(count( $all_departments) > 0 ){ //var_dump($all_departments); // 将传入的 $bigamount 和 $smallamount 也加入数组 $all_departments[] = $bigamount; $all_departments[] = $smallamount; // 找出最大业绩 $max_department = max($all_departments); // 计算小部门业绩:总和 - 最大值 $small_department = array_sum($all_departments) - $max_department; // 返回结果 return [$max_department, $small_department]; }else{ return [0, 0]; } } //获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门 public function getparents_child_pv($user_id){ // 获取直接下级的 UID 列表 //$user_id = 593; // $get_childs = $this->getRecursiveChildren($user_id); $get_childs = Db::name("user") ->where("spread_uid", $user_id) ->column("uid"); // 获取子级的 uid 列表 //根据获得的直接推荐下级2.0,来获取他们和她伞下的子级PV。对比拿一个最大的值,设为大部门,其余的是小部门 //获取直接下级 $children_group = []; // 用于存储每个直接下级及其子级的分组 // 遍历每个直接下级 foreach ($get_childs as $child) { $child_group = [$child]; // 将直接下级加入分组 $recursive_children = $this->getRecursiveChildren($child); // 获取直接下级的所有子级 $child_group = array_merge($child_group, $recursive_children); // 将子级加入分组 $children_group[] = $child_group; // 将分组加入最终结果 } $get_teams_comm_datas = []; foreach($children_group as $v){ $get_teams_comm_datas[] = $this->getteampv($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行 } if(count($get_teams_comm_datas) > 0){ // 找到最大值作为大部门 $max_value = max($get_teams_comm_datas); $total_sum = array_sum($get_teams_comm_datas); // 计算数组的总和 // 小部门为总和减去最大值 $small_department = $total_sum - $max_value; //返回大部门和小部门 return [ $max_value, $small_department ]; }else{ return [ 0, 0 ]; } } //获取大小部门业绩(新表小标0是大部门,下标1是小部门) public function getbig_samll_datas_copy($user_id) { $subordinate_members = Db::name('user') // ->alias('u') // ->join('store_order so', 'u.uid = so.uid', 'LEFT') ->where("spread_uid", $user_id) // ->where("so.mer_id", 496) // ->group('u.uid') ->select(); //var_dump($subordinate_members); // 单独写一个方法获取大小部门的数据 $arr_team = []; foreach ($subordinate_members as $k => $v) { // 计算自己和旗下的业绩 $arr_team[] = $this->calculatePerformance($v['uid']); } // 初始化变量 $maxPerformance = 0; $maxIndex = -1; // 找出 total_performance 最高的记录 foreach ($arr_team as $index => $item) { if ($item['total_performance'] > $maxPerformance) { $maxPerformance = $item['total_performance']; $maxIndex = $index; } } // 如果找到了最高记录 if ($maxIndex !== -1) { // 提取最高记录 $maxRecord = $arr_team[$maxIndex]; // 从原数组中移除该记录 unset($arr_team[$maxIndex]); // 重新索引数组 $arr_team = array_values($arr_team); } else { // 如果没有找到记录,可以设置一个默认值 $maxRecord = null; } // 计算大部门和小部门的汇总信息 $majorDepartmentSummary = [ "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0, ]; $minorDepartmentSummary = [ "total_performance" => array_sum(array_column($arr_team, 'total_performance')), ]; // 返回所需的结果 return [ $majorDepartmentSummary['total_performance'], $minorDepartmentSummary['total_performance'] ]; } /** * 释放待发放佣金 */ public function releaseTobeAmount1($user_id,$amount,$output) { $userInfo = Db::name("user")->find($user_id); if(empty($userInfo)) { return false; } $withdraw_quota = empty($userInfo['withdraw_quota_old']) ? 0 : $userInfo['withdraw_quota_old']; //用户的提现额度 $old_amount = empty($userInfo['tobe_amount_old']) ? 0 : $userInfo['tobe_amount_old']; //用户的冻结额度 Db::name("user")->where("uid",$user_id)->save(['tobe_amount_old'=>0]); $amount += $old_amount;//冻结的金额和分佣的总额 $inc_amount = 0; $inc_tobe_amount = 0; $dec_withdraw_quota = 0; if(($amount - $withdraw_quota) > 0) { //冻结的金额和待发放的佣金减去提现的金额大于0的情况 $diff_money = $amount - $withdraw_quota; $inc_amount = $withdraw_quota; $dec_withdraw_quota = $withdraw_quota; $inc_tobe_amount = $diff_money; }elseif(($amount - $withdraw_quota)==0){ $inc_amount = $withdraw_quota; $dec_withdraw_quota = $withdraw_quota; }else { // <0的情况 $diff_money = $withdraw_quota - $amount; $inc_amount = $amount; $dec_withdraw_quota = $amount; } if($inc_tobe_amount != 0 ) { $res = Db::name("user")->where("uid",$user_id)->inc("tobe_amount_old",$inc_tobe_amount)->fetchSql()->inc("amount_old",$inc_amount)->dec("withdraw_quota_old",$dec_withdraw_quota)->save(); //$output->writeln("执行星级分红-额度不足进入冻结-sql语句"); //$output->writeln($res); Db::execute($res); // if($res == 0) { // $output->writeln($res); // return false; // } }else { $res = Db::name("user")->where("uid",$user_id)->inc("amount_old",$inc_amount)->fetchSql()->dec("withdraw_quota_old",$dec_withdraw_quota)->save(); // $output->writeln("执行星级分红-额度充足-sql语句"); // $output->writeln($res); // Db::execute($res); } //记录日志 提现额度消费 if($dec_withdraw_quota > 0) { $this->change_user_log($user_id,'withdraw_quota_old',2,$dec_withdraw_quota,"conversion_tobe_amount","佣金额度兑换佣金"); } } //发放佣金 示例: $this->change_user_log($v,'amount',1,$all_award,"member_award","星级分红入账"."-".$value['title']);//释放佣金 function change_user_log($user_id,$type,$change_status,$money,$routine,$remark="",$is_admin=1,$appoint_money = 0) { $transition = [ 'pv'=>1, "gb"=>2, "df"=>3, "vr"=>4, "bt"=>5, "withdraw_quota_old"=>6,//提现 "unsettled_pension"=>7, "amount_old"=>8//发放佣金 ]; $routineInfo = Db::name("old_routine_log_of_key")->where("key",$routine)->find(); if(empty($routineInfo)) { return false; } $key_id = isset($routineInfo['id']) ? $routineInfo['id'] : 0; if($appoint_money > 0) { $alter_money = $appoint_money; }else{ //再去查询变更前的 金额 $alter_money = Db::name("user")->where('uid',$user_id)->value($type); } if($change_status == 1) { //新增前 $alter_money = $alter_money-$money; }else if($change_status == 2){ //减少前 $alter_money = $alter_money + $money; } if($alter_money < 0) { $alter_money =0; } $inser_data = []; $inser_data['user_id'] = $user_id; $inser_data['type'] = $transition[$type]; $inser_data['change_status'] = $change_status; $inser_data['money'] = $money; $inser_data['routine_log_of_key_id'] = $key_id; $inser_data['remark'] = $remark; $inser_data['is_admin'] = $is_admin; $inser_data['create_time'] = time(); $inser_data['alter_money'] = isset($alter_money) ? $alter_money : 0; Db::name("old_user_log")->insert($inser_data); } /** * 获取大小区中业绩小的业绩 */ public function getpersamllcomm($user_id,$team_money=0,$person_money=0) { //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv $common_nums = $this->getCommonNums($user_id); $person_nums = $this->getPersonageNums($user_id); $team_amount = 0; $person_amount = 0; // $common_nums[] = $user_id; foreach ($common_nums as $key => $value) { # code... $amount = $this->getPerformance1($value); $team_amount += $amount; } foreach ($person_nums as $key => $value) { # code... $amount = $this->getPerformance1($value); $person_amount += $amount; } //添加自己共建联盟的流水 $user_team_amount = $this->getperteamcomm($common_nums,$user_id); $team_amount += $user_team_amount; // //计算自己的个人联盟总流水 $user_person_amount = $this->getperteamcomm($person_nums,$user_id); $person_amount += $user_person_amount; //计算个人在2.0新表中的业绩 start $team_small_big_amount = $this->getbig_samll_datas($user_id);//下标0是大部门,下标1是小部门 $team_amount += $team_small_big_amount[0]; $person_amount += $team_small_big_amount[1]; //end //默认是小联盟,如果大联盟业绩比小联盟低,那就谁选业绩低的 // 确定最小值和最大值 $minValue = min($person_amount, $team_amount); $maxValue = max($person_amount, $team_amount); // 返回包含最小值和最大值的数组 return array($minValue, $maxValue); } //封装个人大小联盟流水($state_type=1不传status) public function getperteamcomm($common_nums,$user_id,$state_type=1){ // $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money"); // $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2); // 基础查询构建器 $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select(); //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select(); // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后) $money1180Sum = 0; foreach ($user_team_amount as $record) { $money1180Sum += $record['money'] - 300 - 180; } // 获取 status 为 1 且 money 为 11800 的记录集合 $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select(); // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后) $money11800Sum = 0; foreach ($money11800Records as $record) { $money11800Sum += $record['money'] - 3000 - 1800; } $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select(); // 计算 status 为 1 且 money 为 10620 的记录总和(减去相应值后) $money10620Sum = 0; foreach ($money10620Records as $record) { $money10620Sum += $record['money'] - 2700 - 1620; } $money9440Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 9440)->select(); // 计算 status 为 1 且 money 为 9440 的记录总和(减去相应值后) $money9440Sum = 0; foreach ($money9440Records as $record) { $money9440Sum += $record['money'] - 2400 - 1440; } $money2360Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 2360)->select(); // 计算 status 为 1 且 money 为 2360 的记录总和(减去相应值后) $money2360Sum = 0; foreach ($money2360Records as $record) { $money2360Sum += $record['money'] - 600 - 360; } // 计算除去特定值后的总和 //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select(); $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 , 10620 , 9440 ,2360])->select(); $otherMoneySum = 0; foreach ($otherMoneyRecords as $record) { $otherMoneySum += $record['money']; } $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + $money9440Sum + $money2360Sum + round($otherMoneySum * 0.7,2); return $all_record_nums; } //合伙人分佣结束 //利润分配 public function dis_of($group_order_id,$sn){ //利润分配开始 $group_order = Db::name('store_group_order')->where('group_order_sn',$sn)->find(); //var_dump( $group_order); $store_order_data = Db::name('store_order')->where('group_order_id',$group_order_id)->find(); //找到对应的商品id(product_id) $store_order_product_data = Db::name('store_order_product')->where('order_id',$store_order_data['order_id'])->find(); //找到对应的商品让利金额或比例 $store_product_data = Db::name('store_product')->where('product_id',$store_order_product_data['product_id'])->find(); //下单用户 $user_data = Db::name('user')->where('uid',$store_order_data['uid'])->find(); //var_dump($user_data['spread_uid']); $concession_pri = $store_product_data['concession_pri'];//商家让利金额 $spread_uid = 0;//下单用户上级uid $fgj_pri=0;//推广者的佣金抽10%到个人复购金 $pv = 0; //待分配的PV //var_dump($store_product_data['concession_pri']);return; //精彩生活 if($store_order_data['mer_id'] == 439){ //分配参数 $job_par = []; if(!empty($store_order_data)){ $job_par = json_decode($store_order_data['fzone_paytype'], true); //if($job_par['note'] == "现金"){ //普通消费者 $ylj_pri = round($concession_pri * 0.3,2); $pv = round($concession_pri * 0.35,2); //分配养老金给消费者 $ylj_amount_mine = $user_data['annuity'] + $ylj_pri; //分配积分和贡献值给消费者 $con = $user_data['contribute'] + $pv; $score = $user_data['score'] + $pv; Db::name('user')->where('uid',$user_data['uid'])->update(['annuity'=>$ylj_amount_mine,"contribute"=>$con,"score"=>$score]); $this->bill_user_log($user_data['uid'],$ylj_pri,$store_order_data['order_id'],5,$group_order['group_order_sn'],'消费获得养老金'.$ylj_pri,$store_order_data['mer_id'],0); $this->con_log($user_data['uid'],$pv,$store_order_data['order_id'],11,"购买精彩生活商品赠送贡献值"); var_dump($pv); var_dump(111111111111); return; $this->score_log($user_data['uid'],$pv,$store_order_data['order_id'],11,"购买精彩生活商品赠送积分"); //给推广者分配养老金 //给推广者分配佣金 if($user_data['spread_uid'] != 0){ //查询下单用户上级身份 $spread_data = Db::name('user')->where('uid',$user_data['spread_uid'])->find(); //业务员或以上的推荐人等级 //user_group=1是消费者 3%,2:业务员 5%,3:业务经理7%,4:初级合伙人9%,5:中级合伙人11%,6:高级合伙人13%,7:董事15% if($spread_data['user_group'] > 1){ // //给推广者分配佣金 $yj_amount = 0; $ylj_amount = $spread_data['annuity'] + round($pv * 0.05,2); $ssf = 0;//变量 $yj_amount_90 = 0;//90%的佣金 if($spread_data['user_group'] == 2){ $ssf =round($pv * 0.07,2); $con = $spread_data['contribute'] + round($pv * 0.07,2); $score = $spread_data['score'] + round($pv * 0.07,2); //$yj_amount = $spread_data['brokerage_price'] + round($pv * 0.07,2); $yj_amount_90 = round($pv * 0.07,2) * 0.9; $fgj_amount_10 = round($pv * 0.07,2) * 0.1;//推广者的佣金抽10%到个人复购金 $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90; $fgj_amount = $spread_data['fugou'] + $fgj_amount_10; $this->fugou_user_log($spread_data['uid'],$fgj_amount_10,$store_order_data['order_id'],1); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]); }else if($spread_data['user_group'] == 3){ $ssf =round($pv * 0.09,2); $con = $spread_data['contribute'] + round($pv * 0.09,2); $score = $spread_data['score'] + round($pv * 0.09,2); //$yj_amount = $spread_data['brokerage_price'] + round($pv * 0.09,2); $yj_amount_90 = round($pv * 0.09,2) * 0.9; $fgj_amount_10 = round($pv * 0.09,2) * 0.1;//推广者的佣金抽10%到个人复购金 $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90; $fgj_amount = $spread_data['fugou'] + $fgj_amount_10; $this->fugou_user_log($spread_data['uid'],$fgj_amount_10,$store_order_data['order_id'],1); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]); }else if($spread_data['user_group'] == 4){ $ssf =round($pv * 0.11,2); $con = $spread_data['contribute'] + round($pv * 0.11,2); $score = $spread_data['score'] + round($pv * 0.11,2); //$yj_amount = $spread_data['brokerage_price'] + round($pv * 0.11,2); $yj_amount_90 = round($pv * 0.11,2) * 0.9; $fgj_amount_10 = round($pv * 0.11,2) * 0.1;//推广者的佣金抽10%到个人复购金 $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90; $fgj_amount = $spread_data['fugou'] + $fgj_amount_10; $this->fugou_user_log($spread_data['uid'],$fgj_amount_10,$store_order_data['order_id'],1); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]); }else if($spread_data['user_group'] == 5){ $ssf =round($pv * 0.13,2); $con = $spread_data['contribute'] + round($pv * 0.13,2); $score = $spread_data['score'] + round($pv * 0.13,2); // $yj_amount = $spread_data['brokerage_price'] + round($pv * 0.13,2); $yj_amount_90 = round($pv * 0.13,2) * 0.9; $fgj_amount_10 = round($pv * 0.13,2) * 0.1;//推广者的佣金抽10%到个人复购金 $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90; $fgj_amount = $spread_data['fugou'] + $fgj_amount_10; $this->fugou_user_log($spread_data['uid'],$fgj_amount_10,$store_order_data['order_id'],1); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]); }else if($spread_data['user_group'] == 6){ $ssf =round($pv * 0.15,2); $con = $spread_data['contribute'] + round($pv * 0.15,2); $score = $spread_data['score'] + round($pv * 0.15,2); // $yj_amount = $spread_data['brokerage_price'] + round($pv * 0.15,2); $yj_amount_90 = round($pv * 0.15,2) * 0.9; $fgj_amount_10 = round($pv * 0.15,2) * 0.1;//推广者的佣金抽10%到个人复购金 $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90; $fgj_amount = $spread_data['fugou'] + $fgj_amount_10; $this->fugou_user_log($spread_data['uid'],$fgj_amount_10,$store_order_data['order_id'],1); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]); }else if($spread_data['user_group'] == 7){ $ssf =round($pv * 0.17,2); $con = $spread_data['contribute'] + round($pv * 0.17,2); $score = $spread_data['score'] + round($pv * 0.17,2); // $yj_amount = $spread_data['brokerage_price'] + round($pv * 0.17,2); $yj_amount_90 = round($pv * 0.17,2) * 0.9; $fgj_amount_10 = round($pv * 0.17,2) * 0.1;//推广者的佣金抽10%到个人复购金 $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90; $fgj_amount = $spread_data['fugou'] + $fgj_amount_10; $this->fugou_user_log($spread_data['uid'],$fgj_amount_10,$store_order_data['order_id'],1); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yj_amount,'annuity'=>$ylj_amount,'fugou'=>$fgj_amount]); } //贡献值 $this->con_log($spread_data['uid'],$ssf,$store_order_data['order_id'],11,"精彩生活区商品赠送贡献值"); //积分 $this->score_log($spread_data['uid'],$ssf,$store_order_data['order_id'],11,"精彩生活区商品赠送积分"); // //推广佣金 $this->bill_user_log($spread_data['uid'],$yj_amount_90,$store_order_data['order_id'],3,$group_order['group_order_sn'],'推广获得佣金',$store_order_data['mer_id'],0); //养老金 $this->bill_user_log($spread_data['uid'],round($pv * 0.05,2),$store_order_data['order_id'],5,$group_order['group_order_sn'],'推广获得养老金'.round($pv * 0.05,2),$store_order_data['mer_id'],0); } //普通用户推广人 if($spread_data['user_group'] == 1){ //给推广者分配佣金 // $ylj_amount = $spread_data['annuity'] + round($pv * 0.3,2); $yj_amount_90 = round($pv * 0.03,2) * 0.9; $fgj_amount_10 = round($pv * 0.03,2) * 0.1;//推广者的佣金抽10%到个人复购金 $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90; $fgj_amount = $spread_data['fugou'] + $fgj_amount_10; $this->fugou_user_log($spread_data['uid'],$fgj_amount_10,$store_order_data['order_id'],1); Db::name('user')->where('uid',$spread_data['uid'])->update(['brokerage_price'=>$yj_amount,'fugou'=>$fgj_amount]); $con = $spread_data['contribute'] + round($pv * 0.03,2); $score = $spread_data['score'] + round($pv * 0.03,2); //贡献值和积分 Db::name('user')->where('uid',$spread_data['uid'])->update(["contribute"=>$con,"score"=>$score]); //推广养老金 // $this->bill_user_log($spread_data['uid'],round($pv * 0.3,2),$store_order_data['order_id'],5,$group_order['group_order_sn'],'推广获得养老金'.round($pv * 0.3,2),$store_order_data['mer_id']); //推广佣金 $this->bill_user_log($spread_data['uid'],$yj_amount_90,$store_order_data['order_id'],3,$group_order['group_order_sn'],'推广获得佣金',$store_order_data['mer_id'],0); $this->con_log($spread_data['uid'],round($pv * 0.03,2),$store_order_data['order_id'],11,"推广会员专区商品赠送贡献值"); $this->score_log($spread_data['uid'],round($pv * 0.03,2),$store_order_data['order_id'],11,"推广会员专区商品赠送积分"); } } //锁客收益 if($user_data['mer_id'] != 0){ $merchant_data = Db::name('merchant')->where('mer_id',$user_data['mer_id'])->find(); $merchant_user_data = Db::name('user')->where('uid',$merchant_data['uid'])->find(); if(!empty($merchant_user_data)){ //$merchant_amount = $merchant_user_data['brokerage_price'] + round($pv * 0.05,2); //给推广者分配佣金 $yj_amount_90 = round($pv * 0.05,2) * 0.9; $fgj_amount_10 = round($pv * 0.05,2) * 0.1;//推广者的佣金抽10%到个人复购金 $yj_amount = $merchant_user_data['brokerage_price'] + $yj_amount_90; $fgj_amount = $merchant_user_data['fugou'] + $fgj_amount_10; $this->fugou_user_log($merchant_data['uid'],$fgj_amount_10,$store_order_data['order_id'],1); Db::name('user')->where('uid',$merchant_data['uid'])->update(['brokerage_price'=>$yj_amount,'fugou'=>$fgj_amount]); //推广佣金 $this->bill_user_log($merchant_data['uid'], $yj_amount_90,$store_order_data['order_id'],3,$group_order['group_order_sn'],'推广获得佣金',$store_order_data['mer_id'],0); } } //} //var_dump($ylj_amount); } //VIP专区 }else if($store_order_data['mer_id'] == 496){ //业务员和以上推广的等级获得推广佣金 $le_yw_amount = 0; //获赠的贡献值和积分 $gx_jf = 0; $yj1 = 0; if($store_product_data['price'] == 1180){ $pv = 1000; $gx_jf = 700; $yj1 = 100; $le_yw_amount = 300; }else if($store_product_data['price'] == 10620){ $pv = 9000; $gx_jf = 6300; $yj1 = 900; $le_yw_amount = 2700; }else if($store_product_data['price'] == 11800){ $pv = 10000; $gx_jf = 7000; $yj1 = 1000; $le_yw_amount = 3000; } $ylj_pri = round($pv * 0.035,2); //$pv = round($pv * 0.35,2); //分配养老金给消费者 //普通用户获取贡献值和pv3.5%养老金和积分 $ylj_amount_mine = $user_data['annuity'] + $ylj_pri; $gxz_amount_mine = $user_data['contribute'] + $gx_jf; $jf_amount_mine = $user_data['score'] + $gx_jf; Db::name('user')->where('uid',$user_data['uid'])->update(['annuity'=>$ylj_amount_mine,'contribute'=> $gxz_amount_mine,'score'=> $jf_amount_mine]); $this->bill_user_log($user_data['uid'],round($pv * 0.035,2),$store_order_data['order_id'],5,$group_order['group_order_sn'],'消费获得养老金'.round($pv * 0.035,2),$store_order_data['mer_id']); $this->con_log($user_data['uid'],$gx_jf,$store_order_data['order_id'],11,"购买会员专区商品赠送贡献值"); $this->score_log($user_data['uid'],$gx_jf,$store_order_data['order_id'],11,"购买会员专区商品赠送积分"); //给推广者分配养老金 //给推广者分配佣金 if($user_data['spread_uid'] != 0){ //查询下单用户上级身份 $spread_data = Db::name('user')->where('uid',$user_data['spread_uid'])->find(); //user_group=1是消费者,2:业务,3:业务经理,4:初级合伙人,5:中级合伙人,6:高级合伙人,7:董事 //业务或以上等级推广人 //获得养老金、佣金、贡献值和积分 if($spread_data['user_group'] > 1){ $con =0;//贡献值 $score = 0;//积分 //养老金 $uer_bill = $spread_data['annuity'] + round($pv * 0.035,2); //$yongjin = $spread_data['brokerage_price'] + $le_yw_amount; $yj_amount_90 = $le_yw_amount * 0.9; $fgj_amount_10 = $le_yw_amount * 0.1;//推广者的佣金抽10%到个人复购金 $yongjin = $spread_data['brokerage_price'] + $yj_amount_90; $fgj_amount = $spread_data['fugou'] + $fgj_amount_10; if($spread_data['user_group'] == 2){ $con = $spread_data['contribute'] + round($pv * 0.07,2); $score = $spread_data['brokerage_price'] + round($pv * 0.07,2); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yongjin,'annuity'=>$uer_bill,"fugou"=> $fgj_amount]); //贡献值 $this->con_log($spread_data['uid'],round($pv * 0.07,2),$store_order_data['order_id'],11,"推广会员专区商品赠送贡献值"); //积分 $this->score_log($spread_data['uid'],round($pv * 0.07,2),$store_order_data['order_id'],11,"推广会员专区商品赠送积分"); }else if($spread_data['user_group'] == 3){ $con = $spread_data['contribute'] + round($pv * 0.09,2); $score = $spread_data['brokerage_price'] + round($pv * 0.09,2); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yongjin,'annuity'=>$uer_bill,"fugou"=> $fgj_amount]); //贡献值 $this->con_log($spread_data['uid'],round($pv * 0.09,2),$store_order_data['order_id'],11,"推广会员专区商品赠送贡献值"); //积分 $this->score_log($spread_data['uid'],round($pv * 0.09,2),$store_order_data['order_id'],11,"推广会员专区商品赠送积分"); }else if($spread_data['user_group'] == 4){ $con = $spread_data['contribute'] + round($pv * 0.11,2); $score = $spread_data['brokerage_price'] + round($pv * 0.11,2); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yongjin,'annuity'=>$uer_bill,"fugou"=> $fgj_amount]); //贡献值 $this->con_log($spread_data['uid'],round($pv * 0.11,2),$store_order_data['order_id'],11,"推广会员专区商品赠送贡献值"); //积分 $this->score_log($spread_data['uid'],round($pv * 0.11,2),$store_order_data['order_id'],11,"推广会员专区商品赠送积分"); }else if($spread_data['user_group'] == 5){ $con = $spread_data['contribute'] + round($pv * 0.13,2); $score = $spread_data['brokerage_price'] + round($pv * 0.13,2); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yongjin,'annuity'=>$uer_bill,"fugou"=> $fgj_amount]); //贡献值 $this->con_log($spread_data['uid'],round($pv * 0.13,2),$store_order_data['order_id'],11,"推广会员专区商品赠送贡献值"); //积分 $this->score_log($spread_data['uid'],round($pv * 0.13,2),$store_order_data['order_id'],11,"推广会员专区商品赠送积分"); }else if($spread_data['user_group'] == 6){ $con = $spread_data['contribute'] + round($pv * 0.15,2); $score = $spread_data['brokerage_price'] + round($pv * 0.15,2); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yongjin,'annuity'=>$uer_bill,"fugou"=> $fgj_amount]); //贡献值 $this->con_log($spread_data['uid'],round($pv * 0.15,2),$store_order_data['order_id'],11,"推广会员专区商品赠送贡献值"); //积分 $this->score_log($spread_data['uid'],round($pv * 0.15,2),$store_order_data['order_id'],11,"推广会员专区商品赠送积分"); }else if($spread_data['user_group'] == 7){ $con = $spread_data['contribute'] + round($pv * 0.17,2); $score = $spread_data['brokerage_price'] + round($pv * 0.17,2); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $con,'score'=> $score,'brokerage_price'=> $yongjin,'annuity'=>$uer_bill,"fugou"=> $fgj_amount]); //贡献值 $this->con_log($spread_data['uid'],round($pv * 0.17,2),$store_order_data['order_id'],11,"推广会员专区商品赠送贡献值"); //积分 $this->score_log($spread_data['uid'],round($pv * 0.17,2),$store_order_data['order_id'],11,"推广会员专区商品赠送积分"); } //养老金 $this->bill_user_log($spread_data['uid'],round($pv * 0.035,2),$store_order_data['order_id'],5,$group_order['group_order_sn'],'消费获得养老金'.round($pv * 0.035,2),$store_order_data['mer_id']); //佣金 $this->bill_user_log($spread_data['uid'], $yj_amount_90,$store_order_data['order_id'],3,$group_order['group_order_sn'],'推广获得佣金',$store_order_data['mer_id']); //复购金 $this->fugou_user_log($spread_data['uid'],$fgj_amount_10,$store_order_data['order_id'],1); } //普通的用户推广人 if($spread_data['user_group'] == 1){ // $yj_amount = $spread_data['annuity'] + round($pv * 0.01,2); // Db::name('user')->where('uid',$user_data['spread_uid'])->update(['annuity'=>$ylj_amount,'brokerage_price'=>$yj_amount]); // //推广养老金 // $this->bill_user_log($user_data['spread_uid'],round($pv * 0.01,2),$store_order_data['order_id'],5,$group_order['group_order_sn'],'推广获得养老金'.round($pv * 0.01,2),$store_order_data['mer_id']); // //推广佣金 // $this->bill_user_log($user_data['spread_uid'],round($pv * 0.01,2),$store_order_data['order_id'],3,$group_order['group_order_sn'],'推广获得佣金',$store_order_data['mer_id']); //获取贡献值和积分和佣金 $gx_jf = $spread_data['contribute'] + round($pv * 0.03,2); //$yj111 = $spread_data['brokerage_price'] + $yj1; $yj_amount_90 = round($yj1 * 0.9,2); $fgj_amount_10 = round($yj1 * 0.1,2);//推广者的佣金抽10%到个人复购金 $yj_amount = $spread_data['brokerage_price'] + $yj_amount_90; $fgj_amount = $spread_data['fugou'] + $fgj_amount_10; $this->fugou_user_log($spread_data['uid'],$fgj_amount_10,$store_order_data['order_id'],1); Db::name('user')->where('uid',$spread_data['uid'])->update(['contribute'=> $gx_jf,'score'=> $gx_jf,'brokerage_price'=> $yj_amount,'fugou'=>$fgj_amount]); $this->con_log($spread_data['uid'],round($pv * 0.03,2),$store_order_data['order_id'],11,"推广会员专区商品赠送贡献值"); $this->score_log($spread_data['uid'],round($pv * 0.03,2),$store_order_data['order_id'],11,"推广会员专区商品赠送积分"); //推广佣金 $this->bill_user_log($spread_data['uid'],$yj_amount_90,$store_order_data['order_id'],3,$group_order['group_order_sn'],'推广获得佣金',$store_order_data['mer_id']); } } //锁客收益 if($user_data['mer_id'] != 0){ $merchant_data = Db::name('merchant')->where('mer_id',$user_data['mer_id'])->find(); $merchant_user_data = Db::name('user')->where('uid',$merchant_data['uid'])->find(); if(!empty($merchant_user_data)){ //$merchant_amount = $merchant_user_data['brokerage_price'] + round($pv * 0.35,2); $yj_amount_90 = round($pv * 0.035,2) * 0.9; $fgj_amount_10 = round($pv * 0.035,2) * 0.1;//推广者的佣金抽10%到个人复购金 $yj_amount = $merchant_data['brokerage_price'] + $yj_amount_90; $fgj_amount = $merchant_data['fugou'] + $fgj_amount_10; $this->fugou_user_log($merchant_data['uid'],$fgj_amount_10,$store_order_data['order_id'],1); Db::name('user')->where('uid',$merchant_data['uid'])->update(['brokerage_price'=>$yj_amount,'fugou'=>$fgj_amount]); //推广佣金 $this->bill_user_log($merchant_data['uid'],round($pv * 0.35,2),$store_order_data['order_id'],3,$group_order['group_order_sn'],'推广获得佣金',$store_order_data['mer_id']); } } } } }