Kaynağa Gözat

我的部门增加新增业绩

hefei 1 yıl önce
ebeveyn
işleme
817335ed62
1 değiştirilmiş dosya ile 15 ekleme ve 4 silme
  1. 15 4
      app/controller/api/user/User.php

+ 15 - 4
app/controller/api/user/User.php

@@ -1574,15 +1574,23 @@ class User extends BaseController
1574 1574
         $user = Db::name('user')->where('uid', $user_id)->field('uid,nickname,avatar,spread_uid,pv,create_time')->find();
1575 1575
         $child_nums = $this->getdepartmentStatistics($user_id);
1576 1576
         $child_nums_Tree = $this->buildTreePv($child_nums, $user['spread_uid']);
1577
+        $new_performance = 0; //一周内新增总业绩
1578
+        $end_time = date('Y-m-d ' . '00:00:00', strtotime('-7 days'));
1577 1579
         $person_nums_pv = 0;//大部门业绩
1578 1580
         $common_nums_pv = 0;//小部门业绩
1579 1581
         $aLL_list = [];//全部数据
1580 1582
         $person_list = [];//大部门数据
1581 1583
         $common_list = [];//小部门数据
1582 1584
         if(count($child_nums_Tree) && isset($child_nums_Tree[0]['children']) && count($child_nums_Tree[0]['children'])){
1585
+            // 计算总新增业绩
1586
+            $uid_list = array_column($child_nums, 'uid');
1587
+            $new_performance = Db::name("user_pv_log")->where([['uid','in',$uid_list],['settlement_time','>',$end_time]])->sum('pv');
1583 1588
             //获取大部门的key
1584 1589
             $maxBalanceIndex = array_search(max(array_column($child_nums_Tree[0]['children'], 'total_pv')), array_column($child_nums_Tree[0]['children'], 'total_pv'));
1585 1590
             foreach($child_nums_Tree[0]['children'] as $k=>$v){
1591
+                $child_nums = $this->getdepartmentStatistics($v['uid']);
1592
+                $uid_list = array_column($child_nums, 'uid');
1593
+                $new_performance_child = Db::name("user_pv_log")->where([['uid','in',$uid_list],['settlement_time','>',$end_time]])->sum('pv');
1586 1594
                 if($k == $maxBalanceIndex){
1587 1595
                     $person_list[] = [
1588 1596
                         "uid" => $v["uid"],
@@ -1592,7 +1600,8 @@ class User extends BaseController
1592 1600
                         "pv" => $v['pv'],
1593 1601
                         "total_performance" => (int)$v['total_pv'],
1594 1602
                         "create_time" => $v['create_time'],
1595
-                        'team_count'=> $v['team_count']
1603
+                        'team_count'=> $v['team_count'],
1604
+                        'new_performance' => $new_performance_child
1596 1605
                     ];
1597 1606
                     $person_nums_pv = bcadd($person_nums_pv,$v['total_pv']);
1598 1607
                 }else{
@@ -1604,7 +1613,8 @@ class User extends BaseController
1604 1613
                         "pv" => $v['pv'],
1605 1614
                         "total_performance" => (int)$v['total_pv'],
1606 1615
                         "create_time" => $v['create_time'],
1607
-                        'team_count'=> $v['team_count']
1616
+                        'team_count'=> $v['team_count'],
1617
+                        'new_performance' => $new_performance_child
1608 1618
                     ];
1609 1619
                     $common_nums_pv = bcadd($common_nums_pv,$v['total_pv']);
1610 1620
                 }
@@ -1616,7 +1626,8 @@ class User extends BaseController
1616 1626
                     "pv" => $v['pv'],
1617 1627
                     "total_performance" => (int)$v['total_pv'],
1618 1628
                     "create_time" => $v['create_time'],
1619
-                    'team_count'=> $v['team_count']
1629
+                    'team_count'=> $v['team_count'],
1630
+                    'new_performance' => $new_performance_child
1620 1631
                 ];
1621 1632
             }
1622 1633
         }
@@ -1657,7 +1668,7 @@ class User extends BaseController
1657 1668
             $data['teamid'] = $teamid;
1658 1669
             $data['team_list'] = $data1;
1659 1670
             $data['fans_num'] = $child_nums_Tree[0]['team_count'];//总人数
1660
-            $data['new_performance'] = 0;//新增业绩
1671
+            $data['new_performance'] = $new_performance;//新增总业绩
1661 1672
             $data['total_performance'] = (int)bcadd($child_nums_Tree[0]['total_pv'] ?? 0, 0, 2);//总业绩
1662 1673
             $data['person_nums'] = count($person_list);//大部门人数
1663 1674
             $data['common_nums'] = count($common_list);//小部门人数