|
|
@@ -1334,6 +1334,199 @@ public function getteampv($common_nums) {
|
|
1334
|
1334
|
return $totalPv;
|
|
1335
|
1335
|
}
|
|
1336
|
1336
|
|
|
|
1337
|
+ // 2.0 根据父级uid,找到当前用户下面的UID
|
|
|
1338
|
+ function getChildren($parentUid) {
|
|
|
1339
|
+ $result = []; // 用于存储所有子级的 uid
|
|
|
1340
|
+
|
|
|
1341
|
+
|
|
|
1342
|
+ $children = Db::name("user")
|
|
|
1343
|
+ ->where("spread_uid", $parentUid)
|
|
|
1344
|
+ ->column("uid"); // 获取子级的 uid 列表
|
|
|
1345
|
+
|
|
|
1346
|
+
|
|
|
1347
|
+ return $children; // 返回结果数组,并去重
|
|
|
1348
|
+ }
|
|
|
1349
|
+
|
|
|
1350
|
+ //根据传递的父级数组,返回他的对应子级的个数
|
|
|
1351
|
+public function getTeamSize($parentUids) {
|
|
|
1352
|
+ // 初始化结果数组
|
|
|
1353
|
+ $result = [];
|
|
|
1354
|
+
|
|
|
1355
|
+ // 遍历每个父级ID
|
|
|
1356
|
+ foreach ($parentUids as $parentUid) {
|
|
|
1357
|
+ // 递归获取所有子级 UID
|
|
|
1358
|
+ $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
|
|
|
1359
|
+ $children = Db::name("user")
|
|
|
1360
|
+ ->where("spread_uid", $parentUid)
|
|
|
1361
|
+ ->column("uid");
|
|
|
1362
|
+
|
|
|
1363
|
+ // 确保返回的是数组
|
|
|
1364
|
+ if (!is_array($children)) {
|
|
|
1365
|
+ return [];
|
|
|
1366
|
+ }
|
|
|
1367
|
+
|
|
|
1368
|
+ $allChildren = [];
|
|
|
1369
|
+ foreach ($children as $childUid) {
|
|
|
1370
|
+ $allChildren[] = $childUid;
|
|
|
1371
|
+ $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
|
|
|
1372
|
+ }
|
|
|
1373
|
+ return $allChildren;
|
|
|
1374
|
+ };
|
|
|
1375
|
+
|
|
|
1376
|
+ // 获取当前父级及其所有子级的 UID
|
|
|
1377
|
+ $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
|
|
|
1378
|
+
|
|
|
1379
|
+ // 计算总个数(包括父级自身)
|
|
|
1380
|
+ $totalUids = count($allUids);
|
|
|
1381
|
+
|
|
|
1382
|
+ // 将结果存入数组
|
|
|
1383
|
+ $result[] = [
|
|
|
1384
|
+ 'parent_uid' => $parentUid,
|
|
|
1385
|
+ 'total_count' => $totalUids
|
|
|
1386
|
+ ];
|
|
|
1387
|
+ }
|
|
|
1388
|
+
|
|
|
1389
|
+ return $result;
|
|
|
1390
|
+}
|
|
|
1391
|
+ // 递归获取所有子级 UID 的业绩
|
|
|
1392
|
+ public function getTeamPv11($parentUid) {
|
|
|
1393
|
+
|
|
|
1394
|
+ $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
|
|
|
1395
|
+ $children = Db::name("user")
|
|
|
1396
|
+ ->where("spread_uid", $parentUid)
|
|
|
1397
|
+ ->column("uid");
|
|
|
1398
|
+ $allChildren = [];
|
|
|
1399
|
+ foreach ($children as $childUid) {
|
|
|
1400
|
+ $allChildren[] = $childUid;
|
|
|
1401
|
+ $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
|
|
|
1402
|
+ }
|
|
|
1403
|
+ return $allChildren;
|
|
|
1404
|
+ };
|
|
|
1405
|
+
|
|
|
1406
|
+ // 获取当前用户及其所有子级的 UID
|
|
|
1407
|
+ $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
|
|
|
1408
|
+
|
|
|
1409
|
+ // 查询当前用户及其子级的所有订单
|
|
|
1410
|
+ $orders = Db::name("store_order")
|
|
|
1411
|
+ ->whereIn('status', [0, 1, 2, 3])
|
|
|
1412
|
+ ->whereIn("uid", $allUids)
|
|
|
1413
|
+ ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
|
|
|
1414
|
+ ->select();
|
|
|
1415
|
+
|
|
|
1416
|
+ // 计算总业绩
|
|
|
1417
|
+ $totalPv = 0;
|
|
|
1418
|
+ foreach ($orders as $order) {
|
|
|
1419
|
+ switch ($order['total_price']) {
|
|
|
1420
|
+ case 1180:
|
|
|
1421
|
+ $totalPv += 700;
|
|
|
1422
|
+ break;
|
|
|
1423
|
+ case 11800:
|
|
|
1424
|
+ $totalPv += 7000;
|
|
|
1425
|
+ break;
|
|
|
1426
|
+ case 10620:
|
|
|
1427
|
+ $totalPv += 6300;
|
|
|
1428
|
+ break;
|
|
|
1429
|
+ case 2360:
|
|
|
1430
|
+ $totalPv += 1400;
|
|
|
1431
|
+ break;
|
|
|
1432
|
+ case 9440:
|
|
|
1433
|
+ $totalPv += 5600;
|
|
|
1434
|
+ break;
|
|
|
1435
|
+ }
|
|
|
1436
|
+ }
|
|
|
1437
|
+
|
|
|
1438
|
+ return $totalPv;
|
|
|
1439
|
+}
|
|
|
1440
|
+
|
|
|
1441
|
+public function getTeamPv22($parentUid) {
|
|
|
1442
|
+ // 定义递归函数,用于获取所有子级 UID 的业绩
|
|
|
1443
|
+ $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
|
|
|
1444
|
+ $children = Db::name("user")
|
|
|
1445
|
+ ->where("spread_uid", $parentUid)
|
|
|
1446
|
+ ->column("uid");
|
|
|
1447
|
+
|
|
|
1448
|
+ $allChildren = [];
|
|
|
1449
|
+ foreach ($children as $childUid) {
|
|
|
1450
|
+ $allChildren[] = $childUid;
|
|
|
1451
|
+ $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
|
|
|
1452
|
+ }
|
|
|
1453
|
+ return $allChildren;
|
|
|
1454
|
+ };
|
|
|
1455
|
+
|
|
|
1456
|
+ // 获取当前用户及其所有子级的 UID
|
|
|
1457
|
+ $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
|
|
|
1458
|
+
|
|
|
1459
|
+ // 查询当前用户及其子级的所有订单
|
|
|
1460
|
+ $orders = Db::name("store_order")
|
|
|
1461
|
+ ->whereIn('status', [0, 1, 2, 3])
|
|
|
1462
|
+ ->whereIn("uid", $allUids)
|
|
|
1463
|
+ ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
|
|
|
1464
|
+ ->select();
|
|
|
1465
|
+
|
|
|
1466
|
+ // 计算总业绩
|
|
|
1467
|
+ $totalPv = 0;
|
|
|
1468
|
+ foreach ($orders as $order) {
|
|
|
1469
|
+ switch ($order['total_price']) {
|
|
|
1470
|
+ case 1180:
|
|
|
1471
|
+ $totalPv += 700;
|
|
|
1472
|
+ break;
|
|
|
1473
|
+ case 11800:
|
|
|
1474
|
+ $totalPv += 7000;
|
|
|
1475
|
+ break;
|
|
|
1476
|
+ case 10620:
|
|
|
1477
|
+ $totalPv += 6300;
|
|
|
1478
|
+ break;
|
|
|
1479
|
+ case 2360:
|
|
|
1480
|
+ $totalPv += 1400;
|
|
|
1481
|
+ break;
|
|
|
1482
|
+ case 9440:
|
|
|
1483
|
+ $totalPv += 5600;
|
|
|
1484
|
+ break;
|
|
|
1485
|
+ }
|
|
|
1486
|
+ }
|
|
|
1487
|
+
|
|
|
1488
|
+ return $totalPv;
|
|
|
1489
|
+}
|
|
|
1490
|
+
|
|
|
1491
|
+public function processArray($array) {
|
|
|
1492
|
+ // 初始化结果数组
|
|
|
1493
|
+ $result = [
|
|
|
1494
|
+ 'max_value' => null, // 最大值
|
|
|
1495
|
+ 'max_index' => null, // 最大值的下标
|
|
|
1496
|
+ 'remaining_sum' => 0 // 剩余值的总和
|
|
|
1497
|
+ ];
|
|
|
1498
|
+
|
|
|
1499
|
+ // 检查数组是否为空
|
|
|
1500
|
+ if (empty($array)) {
|
|
|
1501
|
+ return $result;
|
|
|
1502
|
+ }
|
|
|
1503
|
+
|
|
|
1504
|
+ // 找出最大值及其下标
|
|
|
1505
|
+ $maxValue = $array[0];
|
|
|
1506
|
+ $maxIndex = 0;
|
|
|
1507
|
+ for ($i = 1; $i < count($array); $i++) {
|
|
|
1508
|
+ if ($array[$i] > $maxValue) {
|
|
|
1509
|
+ $maxValue = $array[$i];
|
|
|
1510
|
+ $maxIndex = $i;
|
|
|
1511
|
+ }
|
|
|
1512
|
+ }
|
|
|
1513
|
+
|
|
|
1514
|
+ // 计算剩余值的总和
|
|
|
1515
|
+ $remainingSum = 0;
|
|
|
1516
|
+ for ($i = 0; $i < count($array); $i++) {
|
|
|
1517
|
+ if ($i != $maxIndex) {
|
|
|
1518
|
+ $remainingSum += $array[$i];
|
|
|
1519
|
+ }
|
|
|
1520
|
+ }
|
|
|
1521
|
+
|
|
|
1522
|
+ // 将结果存入数组
|
|
|
1523
|
+ $result['max_value'] = $maxValue;
|
|
|
1524
|
+ $result['max_index'] = $maxIndex;
|
|
|
1525
|
+ $result['remaining_sum'] = $remainingSum;
|
|
|
1526
|
+
|
|
|
1527
|
+ return $result;
|
|
|
1528
|
+}
|
|
|
1529
|
+
|
|
1337
|
1530
|
// 根据父级uid,递归获取所有子级UID数组
|
|
1338
|
1531
|
function getRecursiveChildren($parentUid) {
|
|
1339
|
1532
|
$result = []; // 用于存储所有子级的 uid
|
|
|
@@ -1363,10 +1556,37 @@ function getRecursiveChildren($parentUid) {
|
|
1363
|
1556
|
return array_unique($result); // 返回结果数组,并去重
|
|
1364
|
1557
|
}
|
|
1365
|
1558
|
|
|
|
1559
|
+//挑出大小值
|
|
|
1560
|
+function getMaxAndSumRest($array) {
|
|
|
1561
|
+ // 检查数组是否为空
|
|
|
1562
|
+ if (empty($array)) {
|
|
|
1563
|
+ return null; // 如果数组为空,返回 null 或其他默认值
|
|
|
1564
|
+ }
|
|
|
1565
|
+
|
|
|
1566
|
+ // 找出数组中的最大值
|
|
|
1567
|
+ $maxValue = max($array);
|
|
|
1568
|
+
|
|
|
1569
|
+ // 移除最大值
|
|
|
1570
|
+ $array = array_diff($array, [$maxValue]);
|
|
|
1571
|
+
|
|
|
1572
|
+ // 将剩下的值相加
|
|
|
1573
|
+ $sumRest = array_sum($array);
|
|
|
1574
|
+
|
|
|
1575
|
+ // 返回结果
|
|
|
1576
|
+ return [
|
|
|
1577
|
+ 'maxValue' => $maxValue,
|
|
|
1578
|
+ 'sumRest' => $sumRest
|
|
|
1579
|
+ ];
|
|
|
1580
|
+}
|
|
|
1581
|
+
|
|
1366
|
1582
|
//获取大小部门业绩(新表小标0是大部门,下标1是小部门)
|
|
1367
|
1583
|
public function getbig_samll_datas($user_id) {
|
|
1368
|
1584
|
|
|
|
1585
|
+ $user_id = 17;
|
|
|
1586
|
+
|
|
1369
|
1587
|
$common_nums = $this->getCommonNums($user_id);
|
|
|
1588
|
+
|
|
|
1589
|
+
|
|
1370
|
1590
|
$child_nums = [];
|
|
1371
|
1591
|
$result_big_team_arr = [];
|
|
1372
|
1592
|
$get_teams_per_pv = [];//获取当前用户在2.0中小部门的总业绩
|
|
|
@@ -1377,11 +1597,17 @@ public function getbig_samll_datas($user_id) {
|
|
1377
|
1597
|
//var_dump($common_nums);
|
|
1378
|
1598
|
//用户三峡所有在2.0系统下面的业绩和人数 start
|
|
1379
|
1599
|
$child_nums = [];
|
|
|
1600
|
+
|
|
|
1601
|
+ //再加上当前用户直属的子级
|
|
|
1602
|
+ $common_ns = $common_nums;
|
|
|
1603
|
+ $common_ns[] = $user_id;
|
|
|
1604
|
+
|
|
|
1605
|
+
|
|
1380
|
1606
|
//获取当前用户
|
|
1381
|
|
- foreach($common_nums as $v){
|
|
|
1607
|
+ foreach($common_ns as $v){
|
|
1382
|
1608
|
$child_nums[] = $this->getRecursiveChildren($v);
|
|
1383
|
1609
|
}
|
|
1384
|
|
-
|
|
|
1610
|
+ // var_dump($child_nums);
|
|
1385
|
1611
|
//去除空数组,并重新组合有数据的数组
|
|
1386
|
1612
|
$filteredData = array_filter($child_nums, function($array) {
|
|
1387
|
1613
|
return !empty($array); // 如果数组不为空,则保留
|
|
|
@@ -1424,6 +1650,30 @@ public function getbig_samll_datas($user_id) {
|
|
1424
|
1650
|
$get_teams_per_pv = $this->getteampv($result_small_team_arr);
|
|
1425
|
1651
|
|
|
1426
|
1652
|
//获取当前用户在2.0中小区的业绩 end
|
|
|
1653
|
+
|
|
|
1654
|
+ }else{
|
|
|
1655
|
+ $get_teams_comm_datas = [];
|
|
|
1656
|
+ //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
|
|
|
1657
|
+ $child_nums = $this->getChildren($user_id);
|
|
|
1658
|
+ //如果当前用户只有一个子级,那么就是默认一个大部门
|
|
|
1659
|
+ if(count($child_nums)==1){
|
|
|
1660
|
+ //var_dump($child_nums);
|
|
|
1661
|
+ //获取父级子级下面的个人
|
|
|
1662
|
+ $get_teams_comm_pv = $this->getTeamPv11($child_nums[0]);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
|
|
|
1663
|
+ // var_dump($get_teams_comm_pv);
|
|
|
1664
|
+
|
|
|
1665
|
+ }else if(count($child_nums) > 1){
|
|
|
1666
|
+
|
|
|
1667
|
+ foreach($child_nums as $v){
|
|
|
1668
|
+
|
|
|
1669
|
+ $get_teams_comm_datas[] = $this->getTeamPv11($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
|
|
|
1670
|
+ }
|
|
|
1671
|
+ $get_big_small_pv = $this->getMaxAndSumRest($get_teams_comm_datas);//区分大小部门业绩
|
|
|
1672
|
+ //var_dump($get_big_small_pv);
|
|
|
1673
|
+ $get_teams_comm_pv = $get_big_small_pv['maxValue'];
|
|
|
1674
|
+ $get_teams_per_pv = $get_big_small_pv['sumRest'];
|
|
|
1675
|
+ }
|
|
|
1676
|
+
|
|
1427
|
1677
|
}
|
|
1428
|
1678
|
|
|
1429
|
1679
|
//var_dump($get_teams_per_pv);
|
|
|
@@ -1444,6 +1694,7 @@ public function getbig_samll_datas($user_id) {
|
|
1444
|
1694
|
$minorDepartmentSummary['total_performance']
|
|
1445
|
1695
|
];
|
|
1446
|
1696
|
}
|
|
|
1697
|
+
|
|
1447
|
1698
|
|
|
1448
|
1699
|
|
|
1449
|
1700
|
//获取大小部门业绩(新表小标0是大部门,下标1是小部门)
|