Sfoglia il codice sorgente

Merge branch 'master' of https://git.bjtdba.com/shop/php

xialei 1 anno fa
parent
commit
a577049052

+ 31 - 1
app/common/repositories/store/order/StoreOrderRepository.php

@@ -1036,7 +1036,7 @@ class StoreOrderRepository extends BaseRepository
1036 1036
                             // Db::name('user')->where('uid',$user_data['uid'])->update(['annuity'=>$ylj_amount_mine,'contribute'=> $gxz_amount_mine,'score'=> $jf_amount_mine]);
1037 1037
                             $paystage_status = 1;
1038 1038
                             //修改订单状态
1039
-                            $orderdatas = Db::name("store_order")->where("order_id", $_order->order_id)->update(['paid'=>1,'pay_time'=> date('Y-m-d H:i:s'),'status'=>0]);
1039
+                            $orderdatas = Db::name("store_order")->where("order_id", $_order->order_id)->update(['paid'=>1,'pay_time'=> date('Y-m-d H:i:s'),'status'=>0,'distribution_mode'=>1]);
1040 1040
                             Db::name("store_group_order")->where("group_order_id",  $groupOrder->group_order_id)->update(['paid'=>1,'pay_time'=> date('Y-m-d H:i:s')]);
1041 1041
 
1042 1042
                             //支出账号存到log日志
@@ -9641,6 +9641,36 @@ class StoreOrderRepository extends BaseRepository
9641 9641
 
9642 9642
 
9643 9643
         }
9644
+        
9645
+        //1.0老用户在新2.0表中升级
9646
+         $sf = Db::name('old_user_jbp')->where('id',$user_data['uid'])->find();//父级在旧表有注册
9647
+
9648
+           // $sf1 = Db::name('old_user_jbp')->where('id',$userdatas['id'])->find();
9649
+
9650
+            // 当前用户是在2.0注册的新用户,父级是在1.0
9651
+
9652
+            //当前用户在1.0中没有注册,但是父级在1.0系统中注册过。
9653
+            if(!empty($sf)){
9654
+
9655
+                //检查用户在旧表中是否与上级,有的话就是升级权限,要新增一个user_of_goods的表
9656
+                if($store_order_data['user_of_goods_id'] != 1){
9657
+                    
9658
+                    $data1['id']=$store_order_data['user_of_goods_id'];
9659
+                    $data1['status']=1;
9660
+                 
9661
+                
9662
+                    $data1['create_time']=time();
9663
+    
9664
+                    //return app('json')->fail("333");
9665
+    
9666
+                    $sfe=  Db::name('old_user_of_goods')->update($data1);
9667
+                }
9668
+               
9669
+
9670
+            }
9671
+        
9672
+          //1.0老用户在新2.0表中升级 end
9673
+        
9644 9674
 
9645 9675
 
9646 9676
     }

+ 10 - 0
app/controller/api/Notify.php

@@ -635,6 +635,16 @@ class Notify
635 635
                                 //供应链的状态
636 636
                                 Db::name('store_order')->where('group_order_id', $group_order_id)->update(['douhuomall'=>1,'douhuomall_status'=>9]);
637 637
                             }
638
+                            
639
+                             //判断是否是自营商品,如果是自营商品需要更改这个值
640
+                             
641
+                            if($store_order_data['mer_id'] == 496){
642
+                                //自营商品
643
+                                Db::name('store_order')->where('group_order_id', $group_order_id)->update(['distribution_mode'=>1]);
644
+                            }
645
+                            
646
+                            
647
+                          
638 648
 
639 649
 
640 650
                             //利润分配 end

+ 13 - 12
app/controller/api/store/order/StoreOrder.php

@@ -508,38 +508,39 @@ class StoreOrder extends BaseController
508 508
                 //生活 VR支付
509 509
 
510 510
                 $vrpri = $userdatas['vr'] -  $array_fzone_paytype['price'];
511
+                
511 512
 
512 513
                 if($vrpri < 0){
513 514
                     return app('json')->fail("支付失败,VR不足!");
514 515
                 }
515
-                //return app('json')->fail(123);
516
+               // return app('json')->fail($userdatas['spread_old']);
516 517
                 //检查在旧表中是否有上级
517
-                if($userdatas['spread_uid'] != 0){
518
-
519
-                    return app('json')->fail($userdatas['spread_old']);
518
+                if($userdatas['spread_old'] != 0){
519
+//return app('json')->fail(123);
520
+                   // return app('json')->fail($userdatas['spread_old']);
520 521
                     //查询当前用户的上级在1.0中是有数据的,那么老用户介绍新用户。
521
-                    $sf = Db::name('old_user_jbp')->where('id',$userdatas['spread_uid'])->find();//父级在旧表有注册
522
-
523
-                    $sf1 = Db::name('old_user_jbp')->where('id',$userdatas['id'])->find();
522
+                    $sf = Db::name('old_user_jbp')->where('id',$userdatas['uid'])->find();//父级在旧表有注册
524 523
 
524
+                   // $sf1 = Db::name('old_user_jbp')->where('id',$userdatas['id'])->find();
525
+ //return app('json')->fail($userdatas['server_id_old']);
525 526
                     // 当前用户是在2.0注册的新用户,父级是在1.0
526 527
 
527 528
                     //当前用户在1.0中没有注册,但是父级在1.0系统中注册过。
528
-                    if(!empty($sf1)){
529
+                    if(!empty($sf)){
529 530
 
530 531
                         //检查用户在旧表中是否与上级,有的话就是升级权限,要新增一个user_of_goods的表
531 532
                         $data1['user_id']=$uid;
532 533
                         $data1['goods_list_id']=0;
533 534
                         $data1['status']=0;
534
-                        $data1['spread_id']=$sf1['invite_id'];
535
-                        $data1['node_id']=$sf1['spread'];
535
+                        $data1['spread_id']=$sf['invite_id'];
536
+                        $data1['node_id']=$sf['spread'];
536 537
                         $data1['money']= $array_fzone_paytype['price'];
537 538
                         $data1['order_id']=10;
538
-                        $data1['server_id']=$userdatas['server_id'];
539
+                        $data1['server_id']=$userdatas['server_id_old'];
539 540
                         $data1['pay_gb']=0;
540 541
                         $data1['pay_vr']= $array_fzone_paytype['price'];
541 542
                         $data1['pay_bt']=0;
542
-
543
+//return app('json')->fail(json_encode($data1));
543 544
                         //return app('json')->fail("333");
544 545
 
545 546
                         $sfe=  Db::name('old_user_of_goods')->insertGetId($data1);

+ 663 - 102
app/controller/api/user/User.php

@@ -1367,13 +1367,10 @@ class User extends BaseController
1367 1367
         //$teamid = 17;
1368 1368
 
1369 1369
 
1370
-        //根据用户找jbp1.0的节点人数组
1371
-        $userdatas = Db::name('user')->where("uid",$teamid)->find();
1372
-        //判断用户上级是否在1.0中注册过
1373
-        if(!empty($userdatas['spread_uid'])){
1374
-            if($userdatas['spread_uid'] >= 611){
1375
-                $spreaddatas = Db::name('user')->where("uid",$userdatas['spread_uid'])->find();
1376
-            }
1370
+        if($teamid == 592){
1371
+             $teamid = 593;
1372
+                $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
1373
+            //var_dump($team_userinfo_old_jbp1);return;
1377 1374
         }
1378 1375
 
1379 1376
 
@@ -1394,7 +1391,7 @@ class User extends BaseController
1394 1391
         ];
1395 1392
 
1396 1393
         // 如果在旧系统中有数据
1397
-        if (!empty($datas_jbp)) {
1394
+       //if (!empty($datas_jbp)) {
1398 1395
             $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
1399 1396
             $tes = $this->teamPeople($teamid, $type); // 1:团队, 2:个人
1400 1397
 
@@ -1451,99 +1448,99 @@ class User extends BaseController
1451 1448
             $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];
1452 1449
             $data['common_nums_pv'] = max($team_userinfo_old_jbp1['common_nums_pv'], $team_userinfo_old_jbp1['person_nums_pv']);
1453 1450
             $data['person_nums_pv'] = min($team_userinfo_old_jbp1['common_nums_pv'], $team_userinfo_old_jbp1['person_nums_pv']);
1454
-        }
1455
-
1456
-// 查询当前会员旗下的会员数据(分页)
1457
-        [$page, $limit] = $this->getPage();
1458
-        $subordinate_members = Db::name('user')
1459
-            // ->alias('u')
1460
-            // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
1461
-            ->where("spread_uid", $teamid)
1462
-            // ->where("so.mer_id", 496)
1463
-            // ->group('u.uid')
1464
-            ->page($page, $limit)
1465
-            ->select();
1466
-
1467
-        $total_members = Db::name('user')
1468
-            // ->alias('u')
1469
-            // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
1470
-            ->where("spread_uid", $teamid)
1471
-            // ->where("so.mer_id", 496)
1472
-            // ->group('u.uid')
1473
-            ->count();
1474
-
1475
-        $data1 = [
1476
-            "total" => $total_members,
1477
-            "per_page" => $limit,
1478
-            "current_page" => $page,
1479
-            "last_page" => ceil($total_members / $limit),
1480
-            "data" => []
1481
-        ];
1482
-
1483
-        $total_amount_pv_team = 0;
1484
-        $team_count_total = 0;
1485
-
1486
-        foreach ($subordinate_members as $k => $v) {
1487
-            $t_teams_pv = $this->calculatePerformance($v['uid']);
1488
-            $total_amount_pv_team += $t_teams_pv['total_performance'];
1489
-            $team_count_total += $t_teams_pv['team_count'];
1490
-
1491
-            $data1['data'][$k] = [
1492
-                "uid" => $v["uid"],
1493
-                "nickname" => $v['nickname'],
1494
-                "phone" => substr_replace($v['phone'], '****', 3, 4),
1495
-                "avatar" => $v['avatar'],
1496
-                "create_time" => $v['create_time'],
1497
-                "total_performance" => $t_teams_pv['total_performance'],
1498
-                "new_performance" => $t_teams_pv['total_performance'],
1499
-                "team_count" => $t_teams_pv['team_count'],
1500
-            ];
1501
-        }
1502
-
1503
-// 获取大小部门数据
1504
-        $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);
1505
-
1506
-// 判断大小部门的人数
1507
-        $big_team_count = $get_big_small_datas[0]['team_count'];
1508
-        $small_team_count = $get_big_small_datas[1]['team_count'];
1509
-
1510
-// 根据 type 参数处理数据
1511
-        if ($type == 1) {
1512
-            usort($data1['data'], function ($a, $b) {
1513
-                return $b['total_performance'] <=> $a['total_performance'];
1514
-            });
1515
-            $data1['data'] = array_slice($data1['data'], 0, 1);
1516
-        } elseif ($type == 0) {
1517
-            usort($data1['data'], function ($a, $b) {
1518
-                return $b['total_performance'] <=> $a['total_performance'];
1519
-            });
1520
-            $data1['data'] = array_slice($data1['data'], 1);
1521
-        }
1522
-
1523
-// 合并数据
1524
-        if (!empty($datas_jbp)) {
1525
-            // 如果旧系统中有数据,合并新旧数据
1526
-            $data['team_list']['data'] = array_merge($data['team_list']['data'], $data1['data']);
1527
-            $data['fans_num'] += $team_count_total;
1528
-            $data['new_performance'] += $total_amount_pv_team;
1529
-            $data['total_performance'] += $total_amount_pv_team;
1530
-            $data['person_nums'] += $big_team_count;
1531
-            $data['common_nums'] += $small_team_count;
1532
-            $data['common_nums_pv'] += $get_big_small_datas[0]['total_performance'];
1533
-            $data['person_nums_pv'] += $get_big_small_datas[1]['total_performance'];
1534
-        } else {
1535
-            // 如果旧系统中没有数据,直接使用新数据
1536
-            $data['team_list'] = $data1;
1537
-            $data['fans_num'] = $team_count_total;
1538
-            $data['new_performance'] = $total_amount_pv_team;
1539
-            $data['total_performance'] = $total_amount_pv_team;
1540
-            $data['person_nums'] = $big_team_count;
1541
-            $data['common_nums'] = $small_team_count;
1542
-            $data['common_nums_pv'] = $get_big_small_datas[0]['total_performance'];
1543
-            $data['person_nums_pv'] = $get_big_small_datas[1]['total_performance'];
1544
-        }
1545
-
1546
-        return app("json")->success($data);
1451
+       // }
1452
+return app("json")->success($data);
1453
+// // 查询当前会员旗下的会员数据(分页)
1454
+//         [$page, $limit] = $this->getPage();
1455
+//         $subordinate_members = Db::name('user')
1456
+//             // ->alias('u')
1457
+//             // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
1458
+//             ->where("spread_uid", $teamid)
1459
+//             // ->where("so.mer_id", 496)
1460
+//             // ->group('u.uid')
1461
+//             ->page($page, $limit)
1462
+//             ->select();
1463
+
1464
+//         $total_members = Db::name('user')
1465
+//             // ->alias('u')
1466
+//             // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
1467
+//             ->where("spread_uid", $teamid)
1468
+//             // ->where("so.mer_id", 496)
1469
+//             // ->group('u.uid')
1470
+//             ->count();
1471
+
1472
+//         $data1 = [
1473
+//             "total" => $total_members,
1474
+//             "per_page" => $limit,
1475
+//             "current_page" => $page,
1476
+//             "last_page" => ceil($total_members / $limit),
1477
+//             "data" => []
1478
+//         ];
1479
+
1480
+//         $total_amount_pv_team = 0;
1481
+//         $team_count_total = 0;
1482
+
1483
+//         foreach ($subordinate_members as $k => $v) {
1484
+//             $t_teams_pv = $this->calculatePerformance($v['uid']);
1485
+//             $total_amount_pv_team += $t_teams_pv['total_performance'];
1486
+//             $team_count_total += $t_teams_pv['team_count'];
1487
+
1488
+//             $data1['data'][$k] = [
1489
+//                 "uid" => $v["uid"],
1490
+//                 "nickname" => $v['nickname'],
1491
+//                 "phone" => substr_replace($v['phone'], '****', 3, 4),
1492
+//                 "avatar" => $v['avatar'],
1493
+//                 "create_time" => $v['create_time'],
1494
+//                 "total_performance" => $t_teams_pv['total_performance'],
1495
+//                 "new_performance" => $t_teams_pv['total_performance'],
1496
+//                 "team_count" => $t_teams_pv['team_count'],
1497
+//             ];
1498
+//         }
1499
+
1500
+// // 获取大小部门数据
1501
+//         $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);
1502
+
1503
+// // 判断大小部门的人数
1504
+//         $big_team_count = $get_big_small_datas[0]['team_count'];
1505
+//         $small_team_count = $get_big_small_datas[1]['team_count'];
1506
+
1507
+// // 根据 type 参数处理数据
1508
+//         if ($type == 1) {
1509
+//             usort($data1['data'], function ($a, $b) {
1510
+//                 return $b['total_performance'] <=> $a['total_performance'];
1511
+//             });
1512
+//             $data1['data'] = array_slice($data1['data'], 0, 1);
1513
+//         } elseif ($type == 0) {
1514
+//             usort($data1['data'], function ($a, $b) {
1515
+//                 return $b['total_performance'] <=> $a['total_performance'];
1516
+//             });
1517
+//             $data1['data'] = array_slice($data1['data'], 1);
1518
+//         }
1519
+
1520
+// // 合并数据
1521
+//         if (!empty($datas_jbp)) {
1522
+//             // 如果旧系统中有数据,合并新旧数据
1523
+//             $data['team_list']['data'] = array_merge($data['team_list']['data'], $data1['data']);
1524
+//             $data['fans_num'] += $team_count_total;
1525
+//             $data['new_performance'] += $total_amount_pv_team;
1526
+//             $data['total_performance'] += $total_amount_pv_team;
1527
+//             $data['person_nums'] += $big_team_count;
1528
+//             $data['common_nums'] += $small_team_count;
1529
+//             $data['common_nums_pv'] += $get_big_small_datas[0]['total_performance'];
1530
+//             $data['person_nums_pv'] += $get_big_small_datas[1]['total_performance'];
1531
+//         } else {
1532
+//             // 如果旧系统中没有数据,直接使用新数据
1533
+//             $data['team_list'] = $data1;
1534
+//             $data['fans_num'] = $team_count_total;
1535
+//             $data['new_performance'] = $total_amount_pv_team;
1536
+//             $data['total_performance'] = $total_amount_pv_team;
1537
+//             $data['person_nums'] = $big_team_count;
1538
+//             $data['common_nums'] = $small_team_count;
1539
+//             $data['common_nums_pv'] = $get_big_small_datas[0]['total_performance'];
1540
+//             $data['person_nums_pv'] = $get_big_small_datas[1]['total_performance'];
1541
+//         }
1542
+
1543
+//         return app("json")->success($data);
1547 1544
 
1548 1545
     }
1549 1546
 
@@ -3364,7 +3361,7 @@ class User extends BaseController
3364 3361
                 Db::name('user_sign_vr')->insertGetId($insertdata);
3365 3362
                 return app('json')->success('转VR成功');
3366 3363
             }else{
3367
-                return app('json')->fail('转VR失败');
3364
+        return app('json')->fail('转VR失败');
3368 3365
             }
3369 3366
         }
3370 3367
 
@@ -3391,17 +3388,581 @@ class User extends BaseController
3391 3388
         });
3392 3389
         return app('json')->success('获取转VR记录成功', ['list'=>$list, 'count'=>$count]);
3393 3390
     }
3391
+    
3392
+    
3393
+    // 根据父级uid,递归获取所有子级UID数组
3394
+function getRecursiveChildren($parentUid) {
3395
+    $result = []; // 用于存储所有子级的 uid
3396
+
3397
+    // 定义递归函数
3398
+    $recursion = function ($parentUid) use (&$result, &$recursion) {
3399
+        // 查询当前父级的所有直接子级
3400
+        $children = Db::name("user")
3401
+                      ->where("spread_uid", $parentUid)
3402
+                      ->column("uid"); // 获取子级的 uid 列表
3403
+
3404
+        // 如果没有子级,直接返回
3405
+        if (empty($children)) {
3406
+            return;
3407
+        }
3408
+
3409
+        // 遍历每个子级
3410
+        foreach ($children as $childUid) {
3411
+            $result[] = $childUid; // 将子级的 uid 添加到结果数组
3412
+            $recursion($childUid); // 递归查询子级的子级
3413
+        }
3414
+    };
3415
+
3416
+    // 从初始父级开始递归查询
3417
+    $recursion($parentUid);
3418
+
3419
+    return array_unique($result); // 返回结果数组,并去重
3420
+}
3421
+
3422
+    // 2.0 根据父级uid,找到当前用户下面的UID
3423
+function getChildren($parentUid) {
3424
+    $result = []; // 用于存储所有子级的 uid
3425
+
3426
+  
3427
+        $children = Db::name("user")
3428
+                      ->where("spread_uid", $parentUid)
3429
+                      ->column("uid"); // 获取子级的 uid 列表
3430
+
3431
+      
3432
+    return $children; // 返回结果数组,并去重
3433
+}
3434
+
3435
+
3436
+public function getNewTeamPv($common_nums) {
3437
+    // 初始化结果数组
3438
+    $result = [
3439
+        'max_value' => null,
3440
+        'max_uid' => null,
3441
+        'remaining_values' => 0, // 剩余值的总和
3442
+        'remaining_uids' => []  // 剩余值对应的 UID
3443
+    ];
3444
+
3445
+    // 递归获取所有子级 UID 的函数
3446
+    $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
3447
+        $children = Db::name("user")
3448
+                      ->where("spread_uid", $parentUid)
3449
+                      ->column("uid");
3450
+        $allChildren = [];
3451
+        foreach ($children as $childUid) {
3452
+            $allChildren[] = $childUid;
3453
+            $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
3454
+        }
3455
+        return $allChildren;
3456
+    };
3457
+
3458
+    // 获取每个用户的总业绩,包括子级的业绩
3459
+    $userTotalPv = [];
3460
+    foreach ($common_nums as $uid) {
3461
+        // 获取当前用户及其所有子级的 UID
3462
+        $allUids = array_merge([$uid], $getRecursiveChildren($uid));
3463
+
3464
+        // 查询当前用户及其子级的所有订单
3465
+        $orders = Db::name("store_order")
3466
+                    ->whereIn('status', [0, 1, 2, 3])
3467
+                    ->whereIn("uid", $allUids)
3468
+                    ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
3469
+                    ->select();
3470
+
3471
+        // 计算总业绩
3472
+        $totalPv = 0;
3473
+        foreach ($orders as $order) {
3474
+            if ($order['total_price'] == 1180) {
3475
+                $totalPv += 700;
3476
+            } else if ($order['total_price'] == 11800) {
3477
+                $totalPv += 7000;
3478
+            } else if ($order['total_price'] == 10620) {
3479
+                $totalPv += 6300;
3480
+            } else if ($order['total_price'] == 2360) {
3481
+                $totalPv += 1400;
3482
+            } else if ($order['total_price'] == 9440) {
3483
+                $totalPv += 5600;
3484
+            }
3485
+        }
3486
+
3487
+        // 将当前用户的总业绩和 UID 存入数组
3488
+        $userTotalPv[] = ['uid' => $uid, 'totalPv' => $totalPv];
3489
+    }
3490
+
3491
+    // 如果没有符合条件的订单,直接返回空数组
3492
+    if (empty($userTotalPv)) {
3493
+        return [];
3494
+    }
3495
+
3496
+    // 找到最大值及其对应的 UID
3497
+    usort($userTotalPv, function($a, $b) {
3498
+        return $b['totalPv'] <=> $a['totalPv']; // 按 totalPv 降序排序
3499
+    });
3500
+
3501
+    // 获取最大值及其 UID
3502
+    $result['max_value'] = $userTotalPv[0]['totalPv'];
3503
+    $result['max_uid'] = $userTotalPv[0]['uid'];
3504
+
3505
+    // 计算剩余值的总和和对应的 UID
3506
+    foreach ($userTotalPv as $index => $user) {
3507
+        if ($index > 0) { // 跳过第一个(最大值)
3508
+            $result['remaining_values'] += $user['totalPv'];
3509
+            $result['remaining_uids'][] = $user['uid'];
3510
+        }
3511
+    }
3512
+
3513
+    return $result;
3514
+}
3515
+
3516
+
3517
+//只获取数组中的业绩
3518
+public function getteampv($common_nums) {
3519
+
3520
+
3521
+        // 查询当前用户及其子级的所有订单
3522
+        $orders = Db::name("store_order")
3523
+                    ->whereIn('status', [0, 1, 2, 3])
3524
+                    ->whereIn("uid", $common_nums)
3525
+                    ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
3526
+                    ->select();
3527
+
3528
+        // 计算总业绩
3529
+        $totalPv = 0;
3530
+        foreach ($orders as $order) {
3531
+            
3532
+           // var_dump($order['uid']."订单:".$order['total_price']);
3533
+            if ($order['total_price'] == 1180) {
3534
+                $totalPv += 700;
3535
+            } else if ($order['total_price'] == 11800) {
3536
+                $totalPv += 7000;
3537
+            } else if ($order['total_price'] == 10620) {
3538
+                $totalPv += 6300;
3539
+            } else if ($order['total_price'] == 2360) {
3540
+                $totalPv += 1400;
3541
+            } else if ($order['total_price'] == 9440) {
3542
+                $totalPv += 5600;
3543
+            }
3544
+        }
3545
+
3546
+       
3547
+
3548
+    return $totalPv;
3549
+}
3550
+
3551
+  // 递归获取所有子级 UID 的业绩
3552
+public function getTeamPv11($parentUid) {
3553
+  
3554
+    $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
3555
+        $children = Db::name("user")
3556
+                      ->where("spread_uid", $parentUid)
3557
+                      ->column("uid");
3558
+        $allChildren = [];
3559
+        foreach ($children as $childUid) {
3560
+            $allChildren[] = $childUid;
3561
+            $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
3562
+        }
3563
+        return $allChildren;
3564
+    };
3565
+
3566
+    // 获取当前用户及其所有子级的 UID
3567
+    $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
3568
+
3569
+    // 查询当前用户及其子级的所有订单
3570
+    $orders = Db::name("store_order")
3571
+                ->whereIn('status', [0, 1, 2, 3])
3572
+                ->whereIn("uid", $allUids)
3573
+                ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
3574
+                ->select();
3575
+
3576
+    // 计算总业绩
3577
+    $totalPv = 0;
3578
+    foreach ($orders as $order) {
3579
+        switch ($order['total_price']) {
3580
+            case 1180:
3581
+                $totalPv += 700;
3582
+                break;
3583
+            case 11800:
3584
+                $totalPv += 7000;
3585
+                break;
3586
+            case 10620:
3587
+                $totalPv += 6300;
3588
+                break;
3589
+            case 2360:
3590
+                $totalPv += 1400;
3591
+                break;
3592
+            case 9440:
3593
+                $totalPv += 5600;
3594
+                break;
3595
+        }
3596
+    }
3597
+
3598
+    return $totalPv;
3599
+}
3600
+
3601
+//根据传递的父级数组,返回他的对应子级的个数
3602
+public function getTeamSize($parentUids) {
3603
+    // 初始化结果数组
3604
+    $result = [];
3605
+
3606
+    // 遍历每个父级ID
3607
+    foreach ($parentUids as $parentUid) {
3608
+        // 递归获取所有子级 UID
3609
+        $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
3610
+            $children = Db::name("user")
3611
+                          ->where("spread_uid", $parentUid)
3612
+                          ->column("uid");
3613
+
3614
+            // 确保返回的是数组
3615
+            if (!is_array($children)) {
3616
+                return [];
3617
+            }
3618
+
3619
+            $allChildren = [];
3620
+            foreach ($children as $childUid) {
3621
+                $allChildren[] = $childUid;
3622
+                $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
3623
+            }
3624
+            return $allChildren;
3625
+        };
3626
+
3627
+        // 获取当前父级及其所有子级的 UID
3628
+        $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
3629
+
3630
+        // 计算总个数(包括父级自身)
3631
+        $totalUids = count($allUids);
3632
+
3633
+        // 将结果存入数组
3634
+        $result[] = [
3635
+            'parent_uid' => $parentUid,
3636
+            'total_count' => $totalUids
3637
+        ];
3638
+    }
3394 3639
 
3640
+    return $result;
3641
+}
3642
+
3643
+public function processArray($array) {
3644
+    // 初始化结果数组
3645
+    $result = [
3646
+        'max_value' => null,     // 最大值
3647
+        'max_index' => null,     // 最大值的下标
3648
+        'remaining_sum' => 0     // 剩余值的总和
3649
+    ];
3650
+
3651
+    // 检查数组是否为空
3652
+    if (empty($array)) {
3653
+        return $result;
3654
+    }
3655
+
3656
+    // 找出最大值及其下标
3657
+    $maxValue = $array[0];
3658
+    $maxIndex = 0;
3659
+    for ($i = 1; $i < count($array); $i++) {
3660
+        if ($array[$i] > $maxValue) {
3661
+            $maxValue = $array[$i];
3662
+            $maxIndex = $i;
3663
+        }
3664
+    }
3665
+
3666
+    // 计算剩余值的总和
3667
+    $remainingSum = 0;
3668
+    for ($i = 0; $i < count($array); $i++) {
3669
+        if ($i != $maxIndex) {
3670
+            $remainingSum += $array[$i];
3671
+        }
3672
+    }
3673
+
3674
+    // 将结果存入数组
3675
+    $result['max_value'] = $maxValue;
3676
+    $result['max_index'] = $maxIndex;
3677
+    $result['remaining_sum'] = $remainingSum;
3678
+
3679
+    return $result;
3680
+}
3395 3681
 
3396 3682
     /**
3397 3683
      * 获取当前用户业绩
3398 3684
      */
3399 3685
     public function getPerformance($user_id) {
3686
+        $team_amount = 0;
3687
+        $person_amount = 0;
3688
+        
3689
+        
3690
+         $result_big_team_arr = [];
3691
+         $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
3692
+        //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
3693
+        $common_nums = $this->getCommonNums($user_id);
3694
+        $get_teams_comm_num = 0;
3695
+        $get_teams_comm_pv = 0;
3696
+        //1.0系统中有下级,需要在2.0中再加下级数据
3697
+        if($user_id < 611){
3698
+             //梅红在2.0中的ID是780
3699
+            if($user_id == 593){
3700
+                 $common_nums[] = 780;
3701
+                 unset($common_nums[0]);
3702
+            }
3703
+            //var_dump($common_nums);
3704
+            //用户三峡所有在2.0系统下面的业绩和人数 start
3705
+            $child_nums = [];
3706
+              //获取当前用户
3707
+            foreach($common_nums as $v){
3708
+                $child_nums[] = $this->getRecursiveChildren($v);
3709
+            }
3710
+            
3711
+              //梅红在2.0中的ID是780
3712
+            if($user_id == 593){
3713
+                 $child_nums[0][] = 780;
3714
+                
3715
+            }
3716
+          
3717
+            
3718
+            //去除空数组,并重新组合有数据的数组
3719
+            $filteredData = array_filter($child_nums, function($array) {
3720
+                return !empty($array); // 如果数组不为空,则保留
3721
+            });
3722
+            
3723
+            // 合并所有非空数组
3724
+           
3725
+            foreach ($filteredData as $array) {
3726
+                $result_big_team_arr = array_merge($result_big_team_arr, $array);
3727
+            }
3728
+              //var_dump($result_big_team_arr);echo "ppppppppppppppppp";
3729
+            //获取当前用户下面在2.0中的下级所有PV
3730
+            $get_teams_comm_pv = $this->getteampv($result_big_team_arr);
3731
+         //获取当前用户下面在2.0中的下级所有人数
3732
+        $get_teams_comm_num = count($result_big_team_arr);
3733
+        //var_dump($get_teams_comm_num);
3734
+           
3735
+            //用户伞下小部门所有在2.0系统下面的业绩和人数 end
3736
+        }else{
3737
+            //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
3738
+              $child_nums = $this->getChildren($user_id);
3739
+              //获取父级子级下面的个人
3740
+              $num_teams = $this->getTeamSize($child_nums);
3741
+             //var_dump($num_teams);
3742
+               //= $child_nums;
3743
+            // $getss = $this->processArray($get_teams_comm_datas);
3744
+            // var_dump($getss);
3745
+            //         var_dump($num_teams[$getss['max_index']]);
3746
+              
3747
+              foreach($child_nums as $v){
3748
+                
3749
+                   $get_teams_comm_datas[] = $this->getTeamPv11($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
3750
+              }
3751
+            
3752
+              if( count($get_teams_comm_datas) ==1 ){
3753
+                  
3754
+                  $get_teams_comm_pv =$get_teams_comm_datas[0];
3755
+                  $get_teams_comm_num = $num_teams[0]['total_count'];
3756
+                  
3757
+              }else if(count($get_teams_comm_datas) >1){
3758
+                    $getss = $this->processArray($get_teams_comm_datas);
3759
+                    //var_dump($getss);
3760
+                   $team_datas = $num_teams[$getss['max_index']];
3761
+              }
3762
+              
3763
+              
3764
+        }
3765
+        
3766
+        // var_dump($result_big_team_arr);
3767
+       
3768
+       
3769
+        //var_dump(count($get_teams_comm_num));
3770
+        //合并业绩和人数
3771
+        $team_amount += $get_teams_comm_pv;
3772
+           
3773
+        //var_dump($team_amount);
3774
+        //1.0获取小区业绩
3775
+        $person_nums = $this->getPersonageNums($user_id);
3776
+        //var_dump($person_nums);
3777
+        $result_small_team_arr = [];
3778
+          //1.0系统中有下级,需要在2.0中再加下级数据
3779
+     
3780
+      
3781
+      
3782
+           //用户三峡所有在2.0系统下面的业绩和人数 start
3783
+            $child_nums_mix = [];
3784
+              //获取当前用户
3785
+            foreach($person_nums as $v){
3786
+                $child_nums_mix[] = $this->getRecursiveChildren($v);
3787
+            }
3788
+          
3789
+            //去除空数组,并重新组合有数据的数组
3790
+            $filteredData_1 = array_filter($child_nums_mix, function($array) {
3791
+                return !empty($array); // 如果数组不为空,则保留
3792
+            });
3793
+            
3794
+            // 合并所有非空数组
3795
+            $result_small_team_arr = [];
3796
+            foreach ($filteredData_1 as $array) {
3797
+                $result_small_team_arr = array_merge($result_small_team_arr, $array);
3798
+            }
3799
+            
3800
+            //获取当前用户下面在2.0中的下级所有PV
3801
+            $get_teams_per_pv = $this->getteampv($result_small_team_arr);
3802
+          
3803
+          
3804
+       
3805
+        
3806
+        
3807
+          //获取当前用户下面在2.0中的下级所有人数
3808
+            $get_teams_per_num = count($result_small_team_arr);
3809
+            //合并业绩和人数
3810
+            $person_amount += $get_teams_per_pv;
3811
+       // var_dump($person_amount);
3812
+        //用户小部门所有在2.0系统下面的业绩和人数 end
3813
+
3814
+      
3815
+        // $common_nums[] = $user_id;
3816
+        foreach ($common_nums as $key => $value) {
3817
+            # code...
3818
+            $amount = $this->getPerformance1($value);
3819
+            $team_amount += $amount;
3820
+        }
3821
+        foreach ($person_nums as $key => $value) {
3822
+            # code...
3823
+            $amount = $this->getPerformance1($value);
3824
+            $person_amount += $amount;
3825
+        }
3826
+        //var_dump($team_amount);
3827
+
3828
+
3829
+
3830
+        $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
3831
+
3832
+        //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
3833
+// 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
3834
+        $money1180Sum = 0;
3835
+        foreach ($user_team_amount as $record) {
3836
+            $money1180Sum += $record['money'] - 300 - 180;
3837
+        }
3838
+
3839
+// 获取 status 为 1 且 money 为 11800 的记录集合
3840
+
3841
+        $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
3842
+
3843
+// 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
3844
+        $money11800Sum = 0;
3845
+        foreach ($money11800Records as $record) {
3846
+            $money11800Sum += $record['money'] - 3000 - 1800;
3847
+        }
3848
+
3849
+        $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
3850
+
3851
+// 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
3852
+        $money10620Sum = 0;
3853
+        foreach ($money10620Records as $record) {
3854
+            $money10620Sum += $record['money'] - 2700 - 1620;
3855
+        }
3856
+
3857
+// 计算除去特定值后的总和
3858
+//$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
3859
+        $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
3860
+        $otherMoneySum = 0;
3861
+        foreach ($otherMoneyRecords as $record) {
3862
+            $otherMoneySum += $record['money'];
3863
+        }
3864
+
3865
+
3866
+// 分别处理特定值的情况并加上其他值的总和
3867
+        $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
3868
+        // var_dump($all_record_nums);
3869
+        $team_amount += $all_record_nums;
3870
+
3871
+        //计算自己的个人联盟总流水
3872
+
3873
+        // // //计算自己的个人联盟总流水
3874
+        // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
3875
+        // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
3876
+        // $person_amount += $user_person_amount;
3877
+        //计算个人的1180单价的业绩 集合
3878
+        $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
3879
+
3880
+        $money1180Sum = 0;
3881
+
3882
+        foreach ($money1180Records as $record) {
3883
+            $money1180Sum += $record['money'] - 300 - 180;
3884
+        }
3885
+
3886
+        $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
3887
+
3888
+        //var_dump($person_nums);
3889
+        //计算个人的11800单价的业绩 集合
3890
+        $money11800Sum = 0;
3891
+
3892
+        foreach ($money11800Records as $record) {
3893
+            $money11800Sum += $record['money'] - 3000 - 1800;
3894
+        }
3895
+
3896
+
3897
+        $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
3898
+
3899
+        //var_dump($person_nums);
3900
+        //计算个人的10620单价的业绩 集合
3901
+        $money10620Sum = 0;
3902
+
3903
+        foreach ($money10620Records as $record) {
3904
+            $money10620Sum += $record['money'] - 2700 - 1620;
3905
+        }
3906
+
3907
+
3908
+        // 计算除去特定值后的总和
3909
+        $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
3910
+        $otherMoneySum = 0;
3911
+        foreach ($otherMoneyRecords as $record) {
3912
+            $otherMoneySum += $record['money'];
3913
+        }
3914
+
3915
+        // 分别处理特定值的情况并加上其他值的总和
3916
+        $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
3917
+
3918
+
3919
+        $person_amount += $user_person_amount;
3920
+
3921
+
3922
+        //级别信息
3923
+        $userInfo = Db::name("user")->find($user_id);//
3924
+        $zk_level = 4;
3925
+        $is_zk = false;
3926
+        if($userInfo['user_level_id_old'] == $zk_level) {
3927
+            $is_zk = true;
3928
+            $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
3929
+            $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
3930
+        } else{
3931
+            $sales_incentive = 0;
3932
+        }
3933
+
3934
+
3935
+        $return_data = [
3936
+            'common_nums'=>count($common_nums) + $get_teams_comm_num,
3937
+            'person_nums'=>count($person_nums) + $get_teams_per_num,
3938
+            'common_nums_pv'=> $team_amount,
3939
+            'person_nums_pv'=> $person_amount,
3940
+            'sum_nums_pv' =>$team_amount + $person_amount,
3941
+            'sales_incentive' => $sales_incentive,
3942
+            "is_zk"=>$is_zk
3943
+        ];
3944
+        return $return_data;
3945
+
3946
+
3947
+
3948
+
3949
+
3950
+    }
3951
+
3952
+
3953
+    /**
3954
+     * 获取当前用户业绩
3955
+     */
3956
+    public function getPerformance_copy($user_id) {
3400 3957
         // $user_id = $this->request->post("user_id");
3401 3958
 
3402 3959
 
3403 3960
         //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
3404 3961
         $common_nums = $this->getCommonNums($user_id);
3962
+       
3963
+        
3964
+        
3965
+        //1.0获取小区业绩
3405 3966
         $person_nums = $this->getPersonageNums($user_id);
3406 3967
         //return  $person_nums;
3407 3968
         // var_dump( $common_nums);