橙汁先生 1 год назад
Родитель
Сommit
d79b832849
1 измененных файлов с 337 добавлено и 14 удалено
  1. 337 14
      app/controller/api/user/User.php

+ 337 - 14
app/controller/api/user/User.php

@@ -1113,7 +1113,7 @@ class User extends BaseController
1113 1113
     /**
1114 1114
      * 一壶茶-团队列表
1115 1115
      */
1116
-    public function team_list()
1116
+    public function team_list_1()
1117 1117
     {
1118 1118
         $teamid = $this->request->uid();
1119 1119
 
@@ -1193,7 +1193,7 @@ class User extends BaseController
1193 1193
             $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//个人联盟PV
1194 1194
             // $data['effective_fans_num'] = DB::name('enterprise_user')
1195 1195
         }
1196
-
1196
+        //var_dump($data);
1197 1197
         //把新表中的新增邀请用户加到数组中
1198 1198
         //$spread_usersdata = Db::name('user')->where("spread_uid",$teamid)->select();//查询旗下会员
1199 1199
 
@@ -1245,6 +1245,21 @@ class User extends BaseController
1245 1245
         //获取团队总数量
1246 1246
         $team_count_total = 0;
1247 1247
 
1248
+        $small_count = 0;//小部门人数
1249
+
1250
+
1251
+
1252
+        //var_dump($this->calculatePerformance($subordinate_members));
1253
+
1254
+//获取大小部门数据(新表)
1255
+        $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);//下标0是大部门
1256
+//var_dump( $get_big_small_datas);
1257
+//判断大小部门的人数(根据业绩多的就是大部门,业绩小的就是小部门来计算展示的部门人数);
1258
+        $big_team_count = $get_big_small_datas[0]['team_count'];
1259
+        $smallteam_count = $get_big_small_datas[1]['team_count'];
1260
+        //end
1261
+
1262
+
1248 1263
 
1249 1264
 
1250 1265
         // 遍历分页数据,构造每个会员的详细信息
@@ -1253,11 +1268,7 @@ class User extends BaseController
1253 1268
             //计算自己和旗下的业绩
1254 1269
             $t_teams_pv = $this->calculatePerformance($v['uid']);
1255 1270
 
1256
-            //获取团队数量总人数
1257
-            // foreach($t_teams_pv as $k=>$v){
1258
-            //  var_dump($t_teams_pv['team_count']);
1259
-            //$team_count_total += $k['team_count'];
1260
-            //}
1271
+
1261 1272
 
1262 1273
             $total_amount_pv_team += $t_teams_pv['total_performance'];
1263 1274
 
@@ -1297,13 +1308,13 @@ class User extends BaseController
1297 1308
         // 构造最终返回的数据
1298 1309
         $data = [
1299 1310
             'team_list' => $data1,
1300
-            'fans_num' => $total_members, // 粉丝数
1301
-            'new_performance' =>  $total_amount_pv_team, // 新增业绩
1302
-            'total_performance' =>  $total_amount_pv_team, // 总业绩
1303
-            'person_nums' =>  $team_count_total, // 个人联盟
1304
-            'common_nums' =>  $team_count_total, // 共建联盟
1305
-            'common_nums_pv' => 5, // 公共联盟PV
1306
-            'person_nums_pv' => 6, // 个人联盟PV
1311
+            'fans_num' => $get_big_small_datas[0]['team_count'] + $get_big_small_datas[1]['team_count'], // 粉丝数
1312
+            'new_performance' =>  $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 新增业绩
1313
+            'total_performance' =>  $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 总业绩
1314
+            'person_nums' =>   $big_team_count, // 大部门人数
1315
+            'common_nums' =>  $smallteam_count, // 小部门人数
1316
+            'common_nums_pv' => $get_big_small_datas[0]['total_performance'], // 公共联盟PV
1317
+            'person_nums_pv' => $get_big_small_datas[1]['total_performance'], // 个人联盟PV
1307 1318
         ];
1308 1319
 
1309 1320
 
@@ -1314,9 +1325,321 @@ class User extends BaseController
1314 1325
 
1315 1326
     }
1316 1327
 
1328
+    /**
1329
+     * 一壶茶-团队列表
1330
+     */
1331
+    public function team_list()
1332
+    {
1333
+        $teamid = $this->request->uid();
1334
+
1335
+
1336
+        $teamid =  $this->request->param('teamid');//测试ID
1337
+        //$teamid = 17;
1338
+
1339
+        $datas_jbp = Db::name('old_user_jbp')->where("id",$teamid)->find();//查询旧系统是否有当前会员
1340
+        $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推
1341
+// 初始化最终返回的数据
1342
+        $data = [
1343
+            'team_list' => [],
1344
+            'fans_num' => 0, // 粉丝数
1345
+            'new_performance' => 0, // 新增业绩
1346
+            'total_performance' => 0, // 总业绩
1347
+            'person_nums' => 0, // 个人联盟人数
1348
+            'common_nums' => 0, // 公共联盟人数
1349
+            'common_nums_pv' => 0, // 公共联盟PV
1350
+            'person_nums_pv' => 0, // 个人联盟PV
1351
+        ];
1352
+
1353
+// 如果在旧系统中有数据
1354
+        if (!empty($datas_jbp)) {
1355
+            $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
1356
+            $tes = $this->teamPeople($teamid, $type); // 1:团队, 2:个人
1357
+
1358
+            $data1 = [
1359
+                "total" => 100,
1360
+                "per_page" => 10,
1361
+                "current_page" => 1,
1362
+                "last_page" => 1,
1363
+                "data" => []
1364
+            ];
1365
+
1366
+            if ($type != 2) {
1367
+                foreach ($tes as $k => $v) {
1368
+                    $curr_pv = '';
1369
+                    if ($v['curr_type'] == 0) {
1370
+                        $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
1371
+                    } elseif ($v['curr_type'] == 1) {
1372
+                        $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
1373
+                    } else {
1374
+                        $curr_pv = 0;
1375
+                    }
1376
+
1377
+                    $data1['data'][$k] = [
1378
+                        "uid" => $v["id"],
1379
+                        "nickname" => $v['user_name'] . $curr_pv,
1380
+                        "phone" => "137****3315",
1381
+                        "avatar" => "https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
1382
+                        "create_time" => "2025-01-25 11:00:18",
1383
+                        "identity" => "11",
1384
+                        "level" => "40002",
1385
+                        "partnership" => "22",
1386
+                        "total_performance" => $curr_pv,
1387
+                        "new_performance" => 0,
1388
+                        "team_count" => $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,
1389
+                    ];
1390
+                }
1391
+            } else {
1392
+                foreach ($tes as $k => $v) {
1393
+                    $data1['data'][$k] = [
1394
+                        "uid" => $v["uid"],
1395
+                        "nickname" => $v['nickname'],
1396
+                        "avatar" => $v['avatar'],
1397
+                        "create_time" => "2025-01-25 11:00:18",
1398
+                    ];
1399
+                }
1400
+            }
1401
+
1402
+            // 旧系统中的公共部分数据
1403
+            $data['team_list'] = $data1;
1404
+            $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'];
1405
+            $data['new_performance'] = 0;
1406
+            $data['total_performance'] = $team_userinfo_old_jbp1['sum_nums_pv'];
1407
+            $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];
1408
+            $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];
1409
+            $data['common_nums_pv'] = max($team_userinfo_old_jbp1['common_nums_pv'], $team_userinfo_old_jbp1['person_nums_pv']);
1410
+            $data['person_nums_pv'] = min($team_userinfo_old_jbp1['common_nums_pv'], $team_userinfo_old_jbp1['person_nums_pv']);
1411
+        }
1412
+
1413
+// 查询当前会员旗下的会员数据(分页)
1414
+        [$page, $limit] = $this->getPage();
1415
+        $subordinate_members = Db::name('user')
1416
+            ->alias('u')
1417
+            ->join('store_order so', 'u.uid = so.uid', 'LEFT')
1418
+            ->where("u.spread_uid", $teamid)
1419
+            ->where("so.mer_id", 496)
1420
+            ->group('u.uid')
1421
+            ->page($page, $limit)
1422
+            ->select();
1423
+
1424
+        $total_members = Db::name('user')
1425
+            ->alias('u')
1426
+            ->join('store_order so', 'u.uid = so.uid', 'LEFT')
1427
+            ->where("u.spread_uid", $teamid)
1428
+            ->where("so.mer_id", 496)
1429
+            ->group('u.uid')
1430
+            ->count();
1431
+
1432
+        $data1 = [
1433
+            "total" => $total_members,
1434
+            "per_page" => $limit,
1435
+            "current_page" => $page,
1436
+            "last_page" => ceil($total_members / $limit),
1437
+            "data" => []
1438
+        ];
1439
+
1440
+        $total_amount_pv_team = 0;
1441
+        $team_count_total = 0;
1442
+
1443
+        foreach ($subordinate_members as $k => $v) {
1444
+            $t_teams_pv = $this->calculatePerformance($v['uid']);
1445
+            $total_amount_pv_team += $t_teams_pv['total_performance'];
1446
+            $team_count_total += $t_teams_pv['team_count'];
1447
+
1448
+            $data1['data'][$k] = [
1449
+                "uid" => $v["uid"],
1450
+                "nickname" => $v['nickname'],
1451
+                "phone" => substr_replace($v['phone'], '****', 3, 4),
1452
+                "avatar" => $v['avatar'],
1453
+                "create_time" => $v['create_time'],
1454
+                "total_performance" => $t_teams_pv['total_performance'],
1455
+                "new_performance" => $t_teams_pv['total_performance'],
1456
+                "team_count" => $t_teams_pv['team_count'],
1457
+            ];
1458
+        }
1459
+
1460
+// 获取大小部门数据
1461
+        $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);
1462
+
1463
+// 判断大小部门的人数
1464
+        $big_team_count = $get_big_small_datas[0]['team_count'];
1465
+        $small_team_count = $get_big_small_datas[1]['team_count'];
1466
+
1467
+// 根据 type 参数处理数据
1468
+        if ($type == 1) {
1469
+            usort($data1['data'], function ($a, $b) {
1470
+                return $b['total_performance'] <=> $a['total_performance'];
1471
+            });
1472
+            $data1['data'] = array_slice($data1['data'], 0, 1);
1473
+        } elseif ($type == 0) {
1474
+            usort($data1['data'], function ($a, $b) {
1475
+                return $b['total_performance'] <=> $a['total_performance'];
1476
+            });
1477
+            $data1['data'] = array_slice($data1['data'], 1);
1478
+        }
1479
+
1480
+// 合并数据
1481
+        if (!empty($datas_jbp)) {
1482
+            // 如果旧系统中有数据,合并新旧数据
1483
+            $data['team_list']['data'] = array_merge($data['team_list']['data'], $data1['data']);
1484
+            $data['fans_num'] += $team_count_total;
1485
+            $data['new_performance'] += $total_amount_pv_team;
1486
+            $data['total_performance'] += $total_amount_pv_team;
1487
+            $data['person_nums'] += $big_team_count;
1488
+            $data['common_nums'] += $small_team_count;
1489
+            $data['common_nums_pv'] += $get_big_small_datas[0]['total_performance'];
1490
+            $data['person_nums_pv'] += $get_big_small_datas[1]['total_performance'];
1491
+        } else {
1492
+            // 如果旧系统中没有数据,直接使用新数据
1493
+            $data['team_list'] = $data1;
1494
+            $data['fans_num'] = $team_count_total;
1495
+            $data['new_performance'] = $total_amount_pv_team;
1496
+            $data['total_performance'] = $total_amount_pv_team;
1497
+            $data['person_nums'] = $big_team_count;
1498
+            $data['common_nums'] = $small_team_count;
1499
+            $data['common_nums_pv'] = $get_big_small_datas[0]['total_performance'];
1500
+            $data['person_nums_pv'] = $get_big_small_datas[1]['total_performance'];
1501
+        }
1502
+
1503
+        return app("json")->success($data);
1504
+
1505
+    }
1506
+
1317 1507
     //计算自己和自己团队下面的业绩。新表
1508
+//计算自己和自己团队下面的业绩。新表
1318 1509
     public function calculatePerformance($uid)
1319 1510
     {
1511
+        // 初始化业绩数组
1512
+        $performance = [
1513
+
1514
+            'personal_performance' => 0, // 个人业绩
1515
+            'team_performance' => 0, // 团队业绩
1516
+            'total_performance' => 0, // 总业绩
1517
+            'team_count' => 0, // 加上自己的团队数量
1518
+
1519
+        ];
1520
+
1521
+        // 定义业绩换算规则
1522
+        $performanceMapping = [
1523
+            1180 => 700,
1524
+            10620 => 6300,
1525
+            11800 => 7000
1526
+        ];
1527
+
1528
+        // 计算个人业绩
1529
+        $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
1530
+
1531
+        if ($personalOrder) {
1532
+            // 将浮点数转换为整数
1533
+            $totalPrice = (int)$personalOrder['total_price'];
1534
+            if (isset($performanceMapping[$totalPrice])) {
1535
+                $performance['personal_performance'] = $performanceMapping[$totalPrice];
1536
+            }
1537
+        }
1538
+
1539
+        // 计算旗下团队成员的业绩
1540
+        $teamOrders = Db::name('user')
1541
+            ->alias('u')
1542
+            ->join('store_order so', 'u.uid = so.uid', 'LEFT')
1543
+            ->where("u.spread_uid", $uid) // 查询旗下会员
1544
+            ->where("so.mer_id", 496)
1545
+            // ->where("so.douhuomall", 1)
1546
+            // ->where("so.douhuomall_status", 9)
1547
+            // ->where("so.status", 0)
1548
+            ->select();
1549
+
1550
+        $teamOrders_count = Db::name('user')
1551
+            ->alias('u')
1552
+            ->join('store_order so', 'u.uid = so.uid', 'LEFT')
1553
+            ->where("u.spread_uid", $uid) // 查询旗下会员
1554
+            ->where("so.mer_id", 496)
1555
+            // ->where("so.douhuomall", 1)
1556
+            // ->where("so.douhuomall_status", 9)
1557
+            // ->where("so.status", 0)
1558
+            ->count();
1559
+
1560
+        $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量
1561
+
1562
+        foreach ($teamOrders as $order) {
1563
+            if ($order['total_price']) {
1564
+                // 将浮点数转换为整数
1565
+                $totalPrice = (int)$order['total_price'];
1566
+                if (isset($performanceMapping[$totalPrice])) {
1567
+                    $performance['team_performance'] += $performanceMapping[$totalPrice];
1568
+                }
1569
+            }
1570
+        }
1571
+
1572
+        // 计算总业绩
1573
+        $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
1574
+
1575
+        // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false
1576
+        return $performance;
1577
+    }
1578
+
1579
+//获取大小部门业绩(新表)
1580
+    public function getbig_samll_datas($subordinate_members){
1581
+        //单独写一个方法获取大小部门的数据
1582
+        $arr_team = [];
1583
+        foreach ($subordinate_members as $k => $v) {
1584
+
1585
+            //计算自己和旗下的业绩
1586
+            $arr_team[] = $this->calculatePerformance($v['uid']);
1587
+        }
1588
+
1589
+        // 初始化变量
1590
+        $maxPerformance = 0;
1591
+        $maxIndex = -1;
1592
+
1593
+        // 找出 total_performance 最高的记录
1594
+        foreach ($arr_team as $index => $item) {
1595
+            if ($item['total_performance'] > $maxPerformance) {
1596
+                $maxPerformance = $item['total_performance'];
1597
+                $maxIndex = $index;
1598
+            }
1599
+        }
1600
+
1601
+        // 如果找到了最高记录
1602
+        if ($maxIndex !== -1) {
1603
+            // 提取最高记录
1604
+            $maxRecord = $arr_team[$maxIndex];
1605
+            // 从原数组中移除该记录
1606
+            unset($arr_team[$maxIndex]);
1607
+            // 重新索引数组
1608
+            $arr_team = array_values($arr_team);
1609
+        } else {
1610
+            // 如果没有找到记录,可以设置一个默认值
1611
+            $maxRecord = null;
1612
+        }
1613
+
1614
+        // 计算大部门和小部门的汇总信息
1615
+        $majorDepartmentSummary = [
1616
+            "total_person_performance" => $maxRecord ? $maxRecord['personal_performance'] : 0,
1617
+            "total_team_performance" => $maxRecord ? $maxRecord['team_performance'] : 0,
1618
+            "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0,
1619
+            "team_count" => $maxRecord ? $maxRecord['team_count'] : 0,
1620
+            "data" => $maxRecord ? [$maxRecord] : []
1621
+        ];
1622
+
1623
+        $minorDepartmentSummary = [
1624
+            "total_person_performance" => array_sum(array_column($arr_team, 'personal_performance')),
1625
+            "total_team_performance" => array_sum(array_column($arr_team, 'team_performance')),
1626
+            "total_performance" => array_sum(array_column($arr_team, 'total_performance')),
1627
+            "team_count" => array_sum(array_column($arr_team, 'team_count')),
1628
+            "data" => $arr_team
1629
+        ];
1630
+
1631
+        // 输出结果
1632
+        // echo "大部门汇总信息:\n";
1633
+        // print_r($majorDepartmentSummary);
1634
+        // echo "小部门汇总信息:\n";
1635
+        // print_r($minorDepartmentSummary);
1636
+
1637
+        return array($majorDepartmentSummary,$minorDepartmentSummary);
1638
+    }
1639
+
1640
+    //计算自己和自己团队下面的业绩。新表
1641
+    public function calculatePerformance_copy($uid)
1642
+    {
1320 1643
 
1321 1644
         // 初始化业绩数组
1322 1645
         $performance = [