瀏覽代碼

Merge branch 'master' into huangfamily

family 1 年之前
父節點
當前提交
51ba3c425a
共有 3 個文件被更改,包括 775 次插入128 次删除
  1. 80 93
      app/controller/api/Auth.php
  2. 3 0
      app/controller/api/merchant/sxy/Access.php
  3. 692 35
      app/controller/api/user/User.php

+ 80 - 93
app/controller/api/Auth.php

@@ -2041,18 +2041,23 @@ class Auth extends BaseController
2041
 
2041
 
2042
     
2042
     
2043
     public function getconlev(){
2043
     public function getconlev(){
2044
-        $userid = 17;
2045
-        $datas = $this->getPerformance22($userid);
2044
+        // $userid = 17;
2045
+        // $datas = $this->getPerformance_getcon($userid);
2046
+
2047
+        // var_dump($datas);
2048
+
2049
+        $dats = db::name("store_order")->whereIn("status",[0,1,2,3])->select();
2050
+        var_dump($dats);
2051
+
2046
 
2052
 
2047
-        var_dump($datas);
2048
     }
2053
     }
2049
 
2054
 
2050
 
2055
 
2051
 
2056
 
2052
     /**
2057
     /**
2053
-     * 获取当前用户业绩
2058
+     * 获取当前用户大小部门贡献值
2054
      */
2059
      */
2055
-    public function getPerformance22($user_id) {
2060
+    public function getPerformance_getcon($user_id) {
2056
 
2061
 
2057
       
2062
       
2058
 
2063
 
@@ -2063,7 +2068,7 @@ class Auth extends BaseController
2063
         $result_big_team_arr = [];
2068
         $result_big_team_arr = [];
2064
         $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
2069
         $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
2065
         //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
2070
         //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
2066
-        $common_nums = $this->getCommonNums($user_id);
2071
+        $common_nums = $this->getCommonNums_getcon($user_id);
2067
       
2072
       
2068
         //var_dump($common_nums);
2073
         //var_dump($common_nums);
2069
         $get_teams_comm_num = 0;
2074
         $get_teams_comm_num = 0;
@@ -2080,7 +2085,7 @@ class Auth extends BaseController
2080
          
2085
          
2081
             //获取当前用户
2086
             //获取当前用户
2082
             foreach($common_nums as $v){
2087
             foreach($common_nums as $v){
2083
-                $child_nums[] = $this->getRecursiveChildren($v);
2088
+                $child_nums[] = $this->getRecursiveChildren_getcon($v);
2084
             }
2089
             }
2085
            
2090
            
2086
          
2091
          
@@ -2097,7 +2102,7 @@ class Auth extends BaseController
2097
             //var_dump($result_big_team_arr);
2102
             //var_dump($result_big_team_arr);
2098
             //获取当前用户下面在2.0中的下级所有PV
2103
             //获取当前用户下面在2.0中的下级所有PV
2099
             //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
2104
             //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
2100
-            $t_pv = $this->getteampv($result_big_team_arr);
2105
+            $t_pv = $this->getteampv_getcon($result_big_team_arr);
2101
             $get_teams_comm_pv = $t_pv;
2106
             $get_teams_comm_pv = $t_pv;
2102
             //var_dump($get_teams_comm_pv);echo "ttt";
2107
             //var_dump($get_teams_comm_pv);echo "ttt";
2103
 
2108
 
@@ -2105,15 +2110,15 @@ class Auth extends BaseController
2105
         }else{
2110
         }else{
2106
           
2111
           
2107
                //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
2112
                //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
2108
-              $child_nums = $this->getChildren($user_id);
2113
+              $child_nums = $this->getChildren_getcon($user_id);
2109
              
2114
              
2110
               //获取父级子级下面的个人
2115
               //获取父级子级下面的个人
2111
-              $num_teams = $this->getTeamSize($child_nums);
2116
+              $num_teams = $this->getTeamSize_getcon($child_nums);
2112
           
2117
           
2113
               //var_dump($num_teams);
2118
               //var_dump($num_teams);
2114
               foreach($child_nums as $v){
2119
               foreach($child_nums as $v){
2115
                 
2120
                 
2116
-                   $get_teams_comm_datas[] = $this->getTeamPv11($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
2121
+                   $get_teams_comm_datas[] = $this->getTeamPv11_getcon($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
2117
               }
2122
               }
2118
 
2123
 
2119
               //$s = $this->getparents_child_pv($user_id);
2124
               //$s = $this->getparents_child_pv($user_id);
@@ -2129,7 +2134,7 @@ class Auth extends BaseController
2129
 
2134
 
2130
                     // var_dump( $get_teams_comm_datas);
2135
                     // var_dump( $get_teams_comm_datas);
2131
                     //获取一个最大值,设为大部门,其他的加载一块是小部门
2136
                     //获取一个最大值,设为大部门,其他的加载一块是小部门
2132
-                    $getss = $this->processArray($get_teams_comm_datas);
2137
+                    $getss = $this->processArray_getcon($get_teams_comm_datas);
2133
                  //var_dump($getss);
2138
                  //var_dump($getss);
2134
                     $max_value_count = $num_teams[$getss['max_index']]['total_count'];
2139
                     $max_value_count = $num_teams[$getss['max_index']]['total_count'];
2135
 
2140
 
@@ -2149,8 +2154,7 @@ class Auth extends BaseController
2149
                     $person_amount = $getss['remaining_sum'];
2154
                     $person_amount = $getss['remaining_sum'];
2150
                     $get_teams_comm_pv = $getss['max_value'];
2155
                     $get_teams_comm_pv = $getss['max_value'];
2151
               }
2156
               }
2152
-              
2153
-              
2157
+          
2154
         }
2158
         }
2155
         //var_dump($get_teams_comm_pv);
2159
         //var_dump($get_teams_comm_pv);
2156
         //合并业绩和人数
2160
         //合并业绩和人数
@@ -2158,7 +2162,7 @@ class Auth extends BaseController
2158
            
2162
            
2159
         //var_dump($team_amount);
2163
         //var_dump($team_amount);
2160
         //1.0获取小区业绩
2164
         //1.0获取小区业绩
2161
-        $person_nums = $this->getPersonageNums($user_id);
2165
+        $person_nums = $this->getPersonageNums_getcon($user_id);
2162
         //var_dump($person_nums);
2166
         //var_dump($person_nums);
2163
         $result_small_team_arr = [];
2167
         $result_small_team_arr = [];
2164
           //1.0系统中有下级,需要在2.0中再加下级数据
2168
           //1.0系统中有下级,需要在2.0中再加下级数据
@@ -2170,7 +2174,7 @@ class Auth extends BaseController
2170
 
2174
 
2171
               //获取当前用户
2175
               //获取当前用户
2172
             foreach($person_nums as $v){
2176
             foreach($person_nums as $v){
2173
-                $child_nums_mix[] = $this->getRecursiveChildren($v);
2177
+                $child_nums_mix[] = $this->getRecursiveChildren_getcon($v);
2174
             }
2178
             }
2175
        
2179
        
2176
             //去除空数组,并重新组合有数据的数组
2180
             //去除空数组,并重新组合有数据的数组
@@ -2188,7 +2192,7 @@ class Auth extends BaseController
2188
             //var_dump($result_small_team_arr);
2192
             //var_dump($result_small_team_arr);
2189
             //获取当前用户下面在2.0中的下级所有PV
2193
             //获取当前用户下面在2.0中的下级所有PV
2190
            // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
2194
            // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
2191
-           $t_pv = $this->getteampv($result_small_team_arr);
2195
+           $t_pv = $this->getteampv_getcon($result_small_team_arr);
2192
            $get_teams_per_pv =$t_pv;
2196
            $get_teams_per_pv =$t_pv;
2193
            //var_dump(  $get_teams_per_pv);
2197
            //var_dump(  $get_teams_per_pv);
2194
           
2198
           
@@ -2196,40 +2200,19 @@ class Auth extends BaseController
2196
         
2200
         
2197
         
2201
         
2198
           //获取当前用户下面在2.0中的下级所有人数
2202
           //获取当前用户下面在2.0中的下级所有人数
2199
-            $get_teams_per_num += count($result_small_team_arr);
2203
+           // $get_teams_per_num += count($result_small_team_arr);
2200
             //合并业绩和人数
2204
             //合并业绩和人数
2201
             $person_amount += $get_teams_per_pv;
2205
             $person_amount += $get_teams_per_pv;
2202
 
2206
 
2203
-            
2204
-        //     if($user_id == 593){
2205
-        //         $person_amount = 2800;
2206
-               
2207
-        //    }
2208
-
2209
-        //var_dump($common_nums);
2210
-        //用户小部门所有在2.0系统下面的业绩和人数 end
2211
-
2212
-      //var_dump($team_amount);
2213
-        // $common_nums[] = $user_id;
2214
-        // foreach ($common_nums as $key => $value) {
2215
-        //     # code...
2216
-        //     $amount = $this->getPerformance1($value);
2217
-        //     $team_amount += $amount;
2218
-        // }
2219
-        // foreach ($person_nums as $key => $value) {
2220
-        //     # code...
2221
-        //     $amount = $this->getPerformance1($value);
2222
-        //     $person_amount += $amount;
2223
-        // }
2224
-        
2207
+      
2225
         //当前会员直属的业绩(1.0大部门)
2208
         //当前会员直属的业绩(1.0大部门)
2226
-        $t_pv = $this->getteampv($common_nums);
2209
+        $t_pv = $this->getteampv_getcon($common_nums);
2227
         $team_amount += $t_pv;
2210
         $team_amount += $t_pv;
2228
 
2211
 
2229
          //当前会员直属的业绩(1.0大部门)
2212
          //当前会员直属的业绩(1.0大部门)
2230
-        $p_pv = $this->getteampv($person_nums);
2213
+        $p_pv = $this->getteampv_getcon($person_nums);
2231
         $person_amount += $p_pv;
2214
         $person_amount += $p_pv;
2232
-       
2215
+    
2233
 
2216
 
2234
       
2217
       
2235
     //var_dump($team_amount,$person_amount);
2218
     //var_dump($team_amount,$person_amount);
@@ -2238,21 +2221,12 @@ class Auth extends BaseController
2238
         
2221
         
2239
             //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
2222
             //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
2240
             //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
2223
             //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
2241
-            $b_s = $this->getparents_child_pv11($user_id,$team_amount,$person_amount);
2242
-            
2243
-            //var_dump($b_s);
2244
-            // var_dump($team_amount,$person_amount);
2245
-            // var_dump(count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
2246
-            //var_dump( $b_s);echo "yyyyyyyyyyyyy";
2224
+            $b_s = $this->getparents_child_pv11_getcon($user_id,$team_amount,$person_amount);
2225
+         
2247
             $team_amount = $b_s[0];
2226
             $team_amount = $b_s[0];
2248
-            // $teams_num = $b_s['big_department']['count'];
2249
-              //var_dump($b_s);
2250
-            //       var_dump($b_s['per_pv']);
2251
-
2227
+          
2252
             $person_amount = $b_s[1];
2228
             $person_amount = $b_s[1];
2253
 
2229
 
2254
-            // $per_num = $b_s['small_department']['count'];//小部门人数
2255
-            //var_dump( $b_s['team_num'],$b_s['per_num']);
2256
         }
2230
         }
2257
 
2231
 
2258
 
2232
 
@@ -2271,7 +2245,7 @@ class Auth extends BaseController
2271
      /**
2245
      /**
2272
      * 获取该用户共建联盟
2246
      * 获取该用户共建联盟
2273
      */
2247
      */
2274
-    public function getCommonNums($user_id){
2248
+    public function getCommonNums_getcon($user_id){
2275
 
2249
 
2276
 
2250
 
2277
 
2251
 
@@ -2295,7 +2269,7 @@ class Auth extends BaseController
2295
     /**
2269
     /**
2296
      * 获取该用户个人联盟
2270
      * 获取该用户个人联盟
2297
      */
2271
      */
2298
-    public function getPersonageNums($user_id){
2272
+    public function getPersonageNums_getcon($user_id){
2299
 
2273
 
2300
         $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
2274
         $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
2301
         $new_array_ids =[];
2275
         $new_array_ids =[];
@@ -2316,7 +2290,7 @@ class Auth extends BaseController
2316
     }
2290
     }
2317
 
2291
 
2318
         // 根据父级uid,递归获取所有子级UID数组
2292
         // 根据父级uid,递归获取所有子级UID数组
2319
-    public function getRecursiveChildren($parentUid) {
2293
+    public function getRecursiveChildren_getcon($parentUid) {
2320
         $result = []; // 用于存储所有子级的 uid
2294
         $result = []; // 用于存储所有子级的 uid
2321
 
2295
 
2322
         // 定义递归函数
2296
         // 定义递归函数
@@ -2345,7 +2319,7 @@ class Auth extends BaseController
2345
     }
2319
     }
2346
 
2320
 
2347
     //只获取数组中的业绩
2321
     //只获取数组中的业绩
2348
-    public function getteampv($common_nums) {
2322
+    public function getteampv_getcon($common_nums) {
2349
 
2323
 
2350
          // // 查询当前用户及其子级的所有订单
2324
          // // 查询当前用户及其子级的所有订单
2351
         $orders_gongxian = Db::name("user_sign_gongxian")
2325
         $orders_gongxian = Db::name("user_sign_gongxian")
@@ -2353,7 +2327,7 @@ class Auth extends BaseController
2353
                     ->whereIn("uid", $common_nums)
2327
                     ->whereIn("uid", $common_nums)
2354
                   
2328
                   
2355
                     ->select();
2329
                     ->select();
2356
-
2330
+        //var_dump( $common_nums);
2357
 
2331
 
2358
         $total_gongxian = 0;
2332
         $total_gongxian = 0;
2359
         // // 遍历订单计算业绩
2333
         // // 遍历订单计算业绩
@@ -2363,9 +2337,9 @@ class Auth extends BaseController
2363
             }
2337
             }
2364
         }    
2338
         }    
2365
 
2339
 
2366
-        return $total_gongxian;
2340
+         return $total_gongxian;
2367
 
2341
 
2368
-        // // 查询当前用户及其子级的所有订单
2342
+        // // // 查询当前用户及其子级的所有订单
2369
         // $orders = Db::name("store_order")
2343
         // $orders = Db::name("store_order")
2370
         //             ->whereIn('status', [0, 1, 2, 3])
2344
         //             ->whereIn('status', [0, 1, 2, 3])
2371
         //             ->whereIn("uid", $common_nums)
2345
         //             ->whereIn("uid", $common_nums)
@@ -2400,7 +2374,7 @@ class Auth extends BaseController
2400
 
2374
 
2401
 
2375
 
2402
         // 2.0 根据父级uid,找到当前用户下面的UID
2376
         // 2.0 根据父级uid,找到当前用户下面的UID
2403
-    public function getChildren($parentUid) {
2377
+    public function getChildren_getcon($parentUid) {
2404
         $result = []; // 用于存储所有子级的 uid
2378
         $result = []; // 用于存储所有子级的 uid
2405
 
2379
 
2406
     
2380
     
@@ -2414,7 +2388,7 @@ class Auth extends BaseController
2414
 
2388
 
2415
 
2389
 
2416
       // 递归获取所有子级 UID 的业绩
2390
       // 递归获取所有子级 UID 的业绩
2417
-    public function getTeamPv11($parentUid) {
2391
+    public function getTeamPv11_getcon($parentUid) {
2418
     
2392
     
2419
         $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
2393
         $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
2420
             $children = Db::name("user")
2394
             $children = Db::name("user")
@@ -2482,7 +2456,7 @@ class Auth extends BaseController
2482
     }
2456
     }
2483
 
2457
 
2484
     //根据传递的父级数组,返回他的对应子级的个数
2458
     //根据传递的父级数组,返回他的对应子级的个数
2485
-    public function getTeamSize($parentUids) {
2459
+    public function getTeamSize_getcon($parentUids) {
2486
         // 初始化结果数组
2460
         // 初始化结果数组
2487
         $result = [];
2461
         $result = [];
2488
 
2462
 
@@ -2523,7 +2497,7 @@ class Auth extends BaseController
2523
         return $result;
2497
         return $result;
2524
     }
2498
     }
2525
 
2499
 
2526
-    public function processArray($array) {
2500
+    public function processArray_getcon($array) {
2527
         // 初始化结果数组
2501
         // 初始化结果数组
2528
         $result = [
2502
         $result = [
2529
             'max_value' => null,     // 最大值
2503
             'max_value' => null,     // 最大值
@@ -2565,7 +2539,7 @@ class Auth extends BaseController
2565
        /**
2539
        /**
2566
      * 获取流水信息
2540
      * 获取流水信息
2567
      */
2541
      */
2568
-    public function getPerformance1($user_id) {
2542
+    public function getPerformance1_getcon($user_id) {
2569
         // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
2543
         // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
2570
 
2544
 
2571
         // $amount = isset($amount) ? round($amount*0.7,2) : 0;
2545
         // $amount = isset($amount) ? round($amount*0.7,2) : 0;
@@ -2615,56 +2589,69 @@ class Auth extends BaseController
2615
     }
2589
     }
2616
 
2590
 
2617
         //1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
2591
         //1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
2618
-        public function getparents_child_pv11($user_id, $bigamount, $smallamount) {
2619
-        // 获取直接下级的 UID 列表
2592
+        public function getparents_child_pv11_getcon($user_id, $bigamount, $smallamount) {
2593
+
2594
+            // 获取直接下级的 UID 列表
2620
             $get_childs = Db::name("user")
2595
             $get_childs = Db::name("user")
2621
             ->where("spread_uid", $user_id)
2596
             ->where("spread_uid", $user_id)
2622
             ->column("uid");
2597
             ->column("uid");
2623
 
2598
 
2624
-            // 如果没有直属下级,直接返回 [0, 0]
2625
-            if (empty($get_childs)) {
2626
-                return [0, 0];
2627
-            }
2628
-
2629
-            // 初始化数组存储直属下级的业绩
2630
-            $all_departments = [];
2599
+            // 初始化变量
2600
+            $all_departments = []; // 用于存储所有直属下级的业绩
2631
 
2601
 
2632
             // 遍历每个直属下级
2602
             // 遍历每个直属下级
2633
             foreach ($get_childs as $child) {
2603
             foreach ($get_childs as $child) {
2634
                 // 获取当前下级及其子级
2604
                 // 获取当前下级及其子级
2635
                 $child_group = [$child];
2605
                 $child_group = [$child];
2636
-                $recursive_children = $this->getRecursiveChildren($child);
2606
+                $recursive_children = $this->getRecursiveChildren_getcon($child);
2637
                 $child_group = array_merge($child_group, $recursive_children);
2607
                 $child_group = array_merge($child_group, $recursive_children);
2638
 
2608
 
2639
                 // 获取当前分组的业绩
2609
                 // 获取当前分组的业绩
2640
-                $result = $this->getteampv($child_group);
2641
-
2642
-                // 如果返回的业绩为 null 或 0,直接返回 [0, 0]
2643
-                if ($result === null || $result['totalPv'] == 0) {
2644
-                    return [0, 0];
2645
-                }
2610
+                $result = $this->getteampv_getcon($child_group);
2646
 
2611
 
2647
                 // 将直属下级的业绩加入数组
2612
                 // 将直属下级的业绩加入数组
2648
-                $all_departments[] = $result['totalPv'];
2613
+                $all_departments[] = $result;
2649
             }
2614
             }
2650
 
2615
 
2651
-            // 将传入的 $bigamount 和 $smallamount 加入数组
2616
+            // 将传入的 $bigamount 和 $smallamount 加入数组
2652
             $all_departments[] = $bigamount;
2617
             $all_departments[] = $bigamount;
2653
             $all_departments[] = $smallamount;
2618
             $all_departments[] = $smallamount;
2654
 
2619
 
2655
-            // 找出最大业绩
2656
-            $max_department = max($all_departments);
2620
+            // 检查是否所有业绩都是 0
2621
+            if (count(array_filter($all_departments, function($value) { return $value != 0; })) == 0) {
2622
+                return [0, 0];
2623
+            }
2657
 
2624
 
2658
-            // 计算小部门业绩:总和 - 最大值
2659
-            $small_department = array_sum($all_departments) - $max_department;
2660
-var_dump($max_department);
2661
-            // 返回结果
2662
-            return [$max_department, $small_department];
2625
+            // 初始化最大部门和小部门
2626
+            $max_department = 0;
2627
+            $small_department = 0;
2628
+
2629
+            // 遍历 $all_departments,找出最大值并累加小部门的值
2630
+            foreach ($all_departments as $department) {
2631
+                if ($department > $max_department) {
2632
+                    // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
2633
+                    if ($max_department != 0) {
2634
+                        $small_department += $max_department; // 将旧的最大值累加到小部门
2635
+                    }
2636
+                    $max_department = $department; // 更新最大部门
2637
+                } else {
2638
+                    // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
2639
+                    $small_department += $department;
2640
+                }
2641
+            }
2663
 
2642
 
2643
+            // 返回结果
2644
+            return [
2645
+                $max_department, // 大部门业绩
2646
+                $small_department // 小部门业绩
2647
+            ];
2648
+            //拿$bigamount, $smallamount业绩和get_childs产生的result业绩去对比。如果都是0.说明没有大小部门了,直接返回0,0如果只有一个数组有数据,
2649
+            // 说明只有大部门,默认返回大部门数据,小部门返回0,如果有多条数组数据是一样的,那么就是选一个,设为大部门。剩下的数据叠加设为小部门
2650
+          
2664
         }
2651
         }
2665
 
2652
 
2666
         //获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
2653
         //获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
2667
-        public function getparents_child_pv($user_id){
2654
+        public function getparents_child_pv_getcon($user_id){
2668
         // 获取直接下级的 UID 列表
2655
         // 获取直接下级的 UID 列表
2669
         //$user_id = 593;
2656
         //$user_id = 593;
2670
         // $get_childs = $this->getRecursiveChildren($user_id);
2657
         // $get_childs = $this->getRecursiveChildren($user_id);

+ 3 - 0
app/controller/api/merchant/sxy/Access.php

@@ -821,6 +821,7 @@ class Access
821
             if($oid == '')
821
             if($oid == '')
822
                 return app('json')->fail("请检查参数是否正确");
822
                 return app('json')->fail("请检查参数是否正确");
823
             $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
823
             $groupOrder = $groupOrderRepository->detail_noUid((int)$oid);
824
+            db::name("test_log")->insert(["note"=>json_encode($groupOrder)]);
824
             if (!$groupOrder)
825
             if (!$groupOrder)
825
                 return app('json')->fail('订单不存在或已支付');
826
                 return app('json')->fail('订单不存在或已支付');
826
 
827
 
@@ -2208,6 +2209,8 @@ class Access
2208
 
2209
 
2209
 
2210
 
2210
             if ($groupOrder['order_type'] = "marketing"){
2211
             if ($groupOrder['order_type'] = "marketing"){
2212
+
2213
+                db::name("test_log")->insert(["note"=>"pay_huifu" . json_encode($groupOrder)]);
2211
                 // 创富宝 分账
2214
                 // 创富宝 分账
2212
                 //创富宝
2215
                 //创富宝
2213
                 $cfb = sprintf("%01.2f",round(bcmul($groupOrder['pay_price'],'0.094',5),2));//9.4%的分账
2216
                 $cfb = sprintf("%01.2f",round(bcmul($groupOrder['pay_price'],'0.094',5),2));//9.4%的分账

+ 692 - 35
app/controller/api/user/User.php

@@ -252,12 +252,15 @@ class User extends BaseController
252
             }
252
             }
253
            
253
            
254
             
254
             
255
-            $getteamscon = $this->getPerformance($user->uid);
255
+           // $getteamscon = $this->getPerformance($user->uid);
256
+
257
+            $getcon = $this->getPerformance_getcon( $user->uid);
258
+
256
             //我的团队贡献值
259
             //我的团队贡献值
257
-            $data['team_gongxian_num'] = $getteamscon['sum_nums_pv'];
260
+            $data['team_gongxian_num'] = $getcon['common_nums_pv'] + $getcon['person_nums_pv'];
258
 
261
 
259
             //为生贡献值
262
             //为生贡献值
260
-            $data['no_total_source']=Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number');;
263
+            $data['no_total_source']=Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number');
261
             log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
264
             log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
262
             return app('json')->success($data);
265
             return app('json')->success($data);
263
 
266
 
@@ -1403,7 +1406,7 @@ class User extends BaseController
1403
 
1406
 
1404
 
1407
 
1405
         if($teamid == 592){
1408
         if($teamid == 592){
1406
-             $teamid = 222;//593
1409
+             $teamid = 454;//593
1407
 
1410
 
1408
            // $ss=  $this->userupdates($teamid);
1411
            // $ss=  $this->userupdates($teamid);
1409
            // var_dump($ss);
1412
            // var_dump($ss);
@@ -3781,27 +3784,28 @@ return app("json")->success($data);
3781
     }
3784
     }
3782
 
3785
 
3783
     //1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
3786
     //1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
3784
-    public function getparents_child_pv11($user_id, $bigamount, $smallamount,$common_nums,$person_nums) {
3787
+    public function getparents_child_pv11($user_id, $bigamount, $smallamount, $common_nums, $person_nums) {
3785
         // 获取直接下级的 UID 列表
3788
         // 获取直接下级的 UID 列表
3786
         $get_childs = Db::name("user")
3789
         $get_childs = Db::name("user")
3787
-        ->where("spread_uid", $user_id)
3788
-        ->column("uid");
3789
-
3790
-        // var_dump($get_childs);
3790
+            ->where("spread_uid", $user_id)
3791
+            ->column("uid");
3792
+    
3791
         // 初始化变量
3793
         // 初始化变量
3792
         $all_departments = []; // 用于存储所有直属下级的业绩和人数
3794
         $all_departments = []; // 用于存储所有直属下级的业绩和人数
3793
-
3795
+    
3794
         // 遍历每个直属下级
3796
         // 遍历每个直属下级
3795
         foreach ($get_childs as $child) {
3797
         foreach ($get_childs as $child) {
3796
             // 获取当前下级及其子级
3798
             // 获取当前下级及其子级
3797
             $child_group = [$child];
3799
             $child_group = [$child];
3798
             $recursive_children = $this->getRecursiveChildren($child);
3800
             $recursive_children = $this->getRecursiveChildren($child);
3799
-        
3800
             $child_group = array_merge($child_group, $recursive_children);
3801
             $child_group = array_merge($child_group, $recursive_children);
3801
-
3802
+    
3802
             // 获取当前分组的业绩和人数
3803
             // 获取当前分组的业绩和人数
3803
             $result = $this->getteampv($child_group);
3804
             $result = $this->getteampv($child_group);
3804
-
3805
+            // if($user_id == 593){
3806
+            //     var_dump($result);
3807
+            // }
3808
+    
3805
             // 将直属下级的业绩和人数加入数组
3809
             // 将直属下级的业绩和人数加入数组
3806
             $all_departments[] = [
3810
             $all_departments[] = [
3807
                 'value' => $result['totalPv'],
3811
                 'value' => $result['totalPv'],
@@ -3814,39 +3818,39 @@ return app("json")->success($data);
3814
             'value' => $bigamount,
3818
             'value' => $bigamount,
3815
             'count' => $common_nums // 大部门的人数
3819
             'count' => $common_nums // 大部门的人数
3816
         ];
3820
         ];
3821
+    
3817
         $all_departments[] = [
3822
         $all_departments[] = [
3818
             'value' => $smallamount,
3823
             'value' => $smallamount,
3819
             'count' => $person_nums // 小部门的人数
3824
             'count' => $person_nums // 小部门的人数
3820
         ];
3825
         ];
3821
     
3826
     
3822
-        //
3823
-        // 找出最大业绩及其对应的人数
3827
+        // 初始化最大部门和小部门
3824
         $max_department = null;
3828
         $max_department = null;
3825
-        foreach ($all_departments as $department) {
3826
-            if ($max_department === null || $department['value'] > $max_department['value']) {
3827
-                $max_department = $department;
3828
-            }
3829
-        }
3830
-
3831
-        // 计算小部门业绩和人数:总和 - 最大值
3832
         $small_department = [
3829
         $small_department = [
3833
             'value' => 0,
3830
             'value' => 0,
3834
             'count' => 0
3831
             'count' => 0
3835
         ];
3832
         ];
3833
+    
3834
+        // 遍历 $all_departments,找出最大值并累加小部门的值
3836
         foreach ($all_departments as $department) {
3835
         foreach ($all_departments as $department) {
3837
-            if ($department['value'] !== $max_department['value']) {
3836
+            if ($max_department === null || $department['value'] > $max_department['value']) {
3837
+                // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
3838
+                $small_department['value'] += $max_department['value'] ?? 0; // 将旧的最大值累加到小部门
3839
+                $small_department['count'] += $max_department['count'] ?? 0;
3840
+    
3841
+                $max_department = $department; // 更新最大部门
3842
+            } else {
3843
+                // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
3838
                 $small_department['value'] += $department['value'];
3844
                 $small_department['value'] += $department['value'];
3839
                 $small_department['count'] += $department['count'];
3845
                 $small_department['count'] += $department['count'];
3840
             }
3846
             }
3841
         }
3847
         }
3842
-    //var_dump($max_department,$small_department);
3848
+    
3843
         // 返回结果
3849
         // 返回结果
3844
         return [
3850
         return [
3845
             'big_department' => $max_department,
3851
             'big_department' => $max_department,
3846
             'small_department' => $small_department
3852
             'small_department' => $small_department
3847
         ];
3853
         ];
3848
-
3849
-    
3850
     }
3854
     }
3851
 
3855
 
3852
     //根据父级IDS获取伞下的所有子级ID
3856
     //根据父级IDS获取伞下的所有子级ID
@@ -3940,7 +3944,7 @@ return app("json")->success($data);
3940
 
3944
 
3941
         $team_amount = 0;
3945
         $team_amount = 0;
3942
         $person_amount = 0;
3946
         $person_amount = 0;
3943
-        $user_id = 780; //598 523 536
3947
+        $user_id = 454; //598 523 536
3944
         
3948
         
3945
         $result_big_team_arr = [];
3949
         $result_big_team_arr = [];
3946
         $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
3950
         $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
@@ -4044,7 +4048,7 @@ return app("json")->success($data);
4044
         //var_dump($team_amount);
4048
         //var_dump($team_amount);
4045
         //1.0获取小区业绩
4049
         //1.0获取小区业绩
4046
         $person_nums = $this->getPersonageNums($user_id);
4050
         $person_nums = $this->getPersonageNums($user_id);
4047
-      // var_dump($person_nums);
4051
+       //var_dump($person_nums);
4048
         $result_small_team_arr = [];
4052
         $result_small_team_arr = [];
4049
           //1.0系统中有下级,需要在2.0中再加下级数据
4053
           //1.0系统中有下级,需要在2.0中再加下级数据
4050
      
4054
      
@@ -4106,8 +4110,8 @@ return app("json")->success($data);
4106
             $amount = $this->getPerformance1($value);
4110
             $amount = $this->getPerformance1($value);
4107
             $person_amount += $amount;
4111
             $person_amount += $amount;
4108
         }
4112
         }
4109
-       // var_dump($team_amount);
4110
-        //var_dump($person_amount);
4113
+        // var_dump($team_amount);
4114
+        // var_dump($person_amount);
4111
 
4115
 
4112
         //
4116
         //
4113
          
4117
          
@@ -4212,6 +4216,9 @@ return app("json")->success($data);
4212
         $per_num = count($person_nums) + $get_teams_per_num;
4216
         $per_num = count($person_nums) + $get_teams_per_num;
4213
 
4217
 
4214
 
4218
 
4219
+        //  var_dump($team_amount);
4220
+        // var_dump($person_amount);
4221
+
4215
         //如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
4222
         //如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
4216
         if($user_id < 611){
4223
         if($user_id < 611){
4217
          
4224
          
@@ -4222,16 +4229,16 @@ return app("json")->success($data);
4222
             //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
4229
             //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
4223
             $b_s = $this->getparents_child_pv11($user_id,$team_amount,$person_amount,count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
4230
             $b_s = $this->getparents_child_pv11($user_id,$team_amount,$person_amount,count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
4224
             
4231
             
4225
-            var_dump($b_s);
4232
+            //var_dump($b_s);
4226
             // var_dump($team_amount,$person_amount);
4233
             // var_dump($team_amount,$person_amount);
4227
             // var_dump(count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
4234
             // var_dump(count($common_nums)+ $get_teams_comm_num,count($person_nums)+ $get_teams_per_num);
4228
             //var_dump( $b_s);echo "yyyyyyyyyyyyy";
4235
             //var_dump( $b_s);echo "yyyyyyyyyyyyy";
4229
             $team_amount = $b_s['big_department']['value'];
4236
             $team_amount = $b_s['big_department']['value'];
4230
-             $teams_num = $b_s['big_department']['count'];
4231
-        //       var_dump($b_s['team_pv']);
4232
-        //       var_dump($b_s['per_pv']);
4237
+            $teams_num = $b_s['big_department']['count'];
4238
+            //       var_dump($b_s['team_pv']);
4239
+            //       var_dump($b_s['per_pv']);
4233
 
4240
 
4234
-         $person_amount = $b_s['small_department']['value'];
4241
+            $person_amount = $b_s['small_department']['value'];
4235
 
4242
 
4236
             $per_num = $b_s['small_department']['count'];//小部门人数
4243
             $per_num = $b_s['small_department']['count'];//小部门人数
4237
            //var_dump( $b_s['team_num'],$b_s['per_num']);
4244
            //var_dump( $b_s['team_num'],$b_s['per_num']);
@@ -5321,6 +5328,656 @@ return app("json")->success($data);
5321
     // }
5328
     // }
5322
 
5329
 
5323
 
5330
 
5331
+    //获取大小部门贡献值
5332
+    /**
5333
+     * 获取当前用户大小部门贡献值
5334
+     */
5335
+    public function getPerformance_getcon($user_id) {
5336
+
5337
+      
5338
+
5339
+        $team_amount = 0;
5340
+        $person_amount = 0;
5341
+       // $user_id = 593; //598 523 536
5342
+        
5343
+        $result_big_team_arr = [];
5344
+        $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
5345
+        //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
5346
+        $common_nums = $this->getCommonNums_getcon($user_id);
5347
+      
5348
+        //var_dump($common_nums);
5349
+        $get_teams_comm_num = 0;
5350
+        $get_teams_comm_pv = 0;
5351
+
5352
+        $get_teams_per_num = 0;//小部门人数
5353
+        //1.0系统中有下级,需要在2.0中再加下级数据
5354
+        if($user_id < 611){
5355
+             //梅红在2.0中的ID是780
5356
+           
5357
+         //var_dump( $common_nums);
5358
+            //用户三峡所有在2.0系统下面的业绩和人数 start
5359
+            $child_nums = [];
5360
+         
5361
+            //获取当前用户
5362
+            foreach($common_nums as $v){
5363
+                $child_nums[] = $this->getRecursiveChildren_getcon($v);
5364
+            }
5365
+           
5366
+         
5367
+            //去除空数组,并重新组合有数据的数组
5368
+            $filteredData = array_filter($child_nums, function($array) {
5369
+                return !empty($array); // 如果数组不为空,则保留
5370
+            });
5371
+
5372
+            // 合并所有非空数组
5373
+           
5374
+            foreach ($filteredData as $array) {
5375
+                $result_big_team_arr = array_merge($result_big_team_arr, $array);
5376
+            }
5377
+            //var_dump($result_big_team_arr);
5378
+            //获取当前用户下面在2.0中的下级所有PV
5379
+            //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
5380
+            $t_pv = $this->getteampv_getcon($result_big_team_arr);
5381
+            $get_teams_comm_pv = $t_pv;
5382
+            //var_dump($get_teams_comm_pv);echo "ttt";
5383
+
5384
+            //用户伞下小部门所有在2.0系统下面的业绩和人数 end
5385
+        }else{
5386
+          
5387
+               //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
5388
+              $child_nums = $this->getChildren_getcon($user_id);
5389
+             
5390
+              //获取父级子级下面的个人
5391
+              $num_teams = $this->getTeamSize_getcon($child_nums);
5392
+          
5393
+              //var_dump($num_teams);
5394
+              foreach($child_nums as $v){
5395
+                
5396
+                   $get_teams_comm_datas[] = $this->getTeamPv11_getcon($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
5397
+              }
5398
+
5399
+              //$s = $this->getparents_child_pv($user_id);
5400
+
5401
+              //var_dump($get_teams_comm_datas);
5402
+              //如果只有一个部门,就是默认大部门
5403
+              if( count($get_teams_comm_datas) ==1 ){
5404
+                  
5405
+                  $get_teams_comm_pv =$get_teams_comm_datas[0];
5406
+                  $get_teams_comm_num = $num_teams[0]['total_count'];
5407
+                  
5408
+              }else if(count($get_teams_comm_datas) >1){
5409
+
5410
+                    // var_dump( $get_teams_comm_datas);
5411
+                    //获取一个最大值,设为大部门,其他的加载一块是小部门
5412
+                    $getss = $this->processArray_getcon($get_teams_comm_datas);
5413
+                 //var_dump($getss);
5414
+                    $max_value_count = $num_teams[$getss['max_index']]['total_count'];
5415
+
5416
+                    unset($num_teams[$getss['max_index']]);
5417
+
5418
+                       //获取小部门的人数
5419
+                       $per_num = 0;
5420
+                       foreach($num_teams as $k=>$v){
5421
+                        $per_num +=$v['total_count'];
5422
+                       }
5423
+        
5424
+                    //找到最大值的(大部门)
5425
+                    //$get_teams_comm_num = $max_value_count;
5426
+                    //小部门的数量
5427
+                   // $get_teams_per_num =  $per_num;
5428
+                    //var_dump($getss['max_value']);
5429
+                    $person_amount = $getss['remaining_sum'];
5430
+                    $get_teams_comm_pv = $getss['max_value'];
5431
+              }
5432
+          
5433
+        }
5434
+        //var_dump($get_teams_comm_pv);
5435
+        //合并业绩和人数
5436
+        $team_amount += $get_teams_comm_pv;
5437
+           
5438
+        //var_dump($team_amount);
5439
+        //1.0获取小区业绩
5440
+        $person_nums = $this->getPersonageNums_getcon($user_id);
5441
+        //var_dump($person_nums);
5442
+        $result_small_team_arr = [];
5443
+          //1.0系统中有下级,需要在2.0中再加下级数据
5444
+     
5445
+      
5446
+      
5447
+           //用户三峡所有在2.0系统下面的业绩和人数 start
5448
+            $child_nums_mix = [];
5449
+
5450
+              //获取当前用户
5451
+            foreach($person_nums as $v){
5452
+                $child_nums_mix[] = $this->getRecursiveChildren_getcon($v);
5453
+            }
5454
+       
5455
+            //去除空数组,并重新组合有数据的数组
5456
+            $filteredData_1 = array_filter($child_nums_mix, function($array) {
5457
+                return !empty($array); // 如果数组不为空,则保留
5458
+            });
5459
+            
5460
+            // 合并所有非空数组
5461
+            $result_small_team_arr = [];
5462
+            foreach ($filteredData_1 as $array) {
5463
+                $result_small_team_arr = array_merge($result_small_team_arr, $array);
5464
+            }
5465
+
5466
+
5467
+            //var_dump($result_small_team_arr);
5468
+            //获取当前用户下面在2.0中的下级所有PV
5469
+           // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
5470
+           $t_pv = $this->getteampv_getcon($result_small_team_arr);
5471
+           $get_teams_per_pv =$t_pv;
5472
+           //var_dump(  $get_teams_per_pv);
5473
+          
5474
+       
5475
+        
5476
+        
5477
+          //获取当前用户下面在2.0中的下级所有人数
5478
+           // $get_teams_per_num += count($result_small_team_arr);
5479
+            //合并业绩和人数
5480
+            $person_amount += $get_teams_per_pv;
5481
+
5482
+      
5483
+        //当前会员直属的业绩(1.0大部门)
5484
+        $t_pv = $this->getteampv_getcon($common_nums);
5485
+        $team_amount += $t_pv;
5486
+
5487
+         //当前会员直属的业绩(1.0大部门)
5488
+        $p_pv = $this->getteampv_getcon($person_nums);
5489
+        $person_amount += $p_pv;
5490
+    
5491
+
5492
+      
5493
+    //var_dump($team_amount,$person_amount);
5494
+        //如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
5495
+        if($user_id < 611){
5496
+        
5497
+            //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
5498
+            //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
5499
+            $b_s = $this->getparents_child_pv11_getcon($user_id,$team_amount,$person_amount);
5500
+         
5501
+            $team_amount = $b_s[0];
5502
+          
5503
+            $person_amount = $b_s[1];
5504
+
5505
+        }
5506
+
5507
+
5508
+
5509
+        $return_data = [
5510
+           
5511
+            'common_nums_pv'=> $team_amount,
5512
+            'person_nums_pv'=> $person_amount,
5513
+          
5514
+        ];
5515
+
5516
+        return $return_data;
5517
+
5518
+    }
5519
+
5520
+     /**
5521
+     * 获取该用户共建联盟
5522
+     */
5523
+    public function getCommonNums_getcon($user_id){
5524
+
5525
+
5526
+
5527
+        //先获取共建联盟下用户的id
5528
+        $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
5529
+        $new_array_ids =[];
5530
+        foreach ($son_ids as $key => $value) {
5531
+            # code...
5532
+            $son_id = $value['id'];
5533
+            $new_array_ids = array_merge($new_array_ids,[$son_id]);
5534
+            $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
5535
+
5536
+            if(count($son_value_ids) > 0) {
5537
+                $son_value_ids = array_column($son_value_ids,"id");
5538
+                $new_array_ids = array_merge($new_array_ids,$son_value_ids);
5539
+            }
5540
+
5541
+        }
5542
+        return $new_array_ids;
5543
+    }
5544
+    /**
5545
+     * 获取该用户个人联盟
5546
+     */
5547
+    public function getPersonageNums_getcon($user_id){
5548
+
5549
+        $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
5550
+        $new_array_ids =[];
5551
+        // return 3343;
5552
+        foreach ($son_ids as $key => $value) {
5553
+            # code...
5554
+            $son_id = $value['id'];
5555
+            $new_array_ids = array_merge($new_array_ids,[$son_id]);
5556
+            $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
5557
+
5558
+            if(count($son_value_ids) > 0) {
5559
+                $son_value_ids = array_column($son_value_ids,"id");
5560
+                $new_array_ids = array_merge($new_array_ids,$son_value_ids);
5561
+            }
5562
+
5563
+        }
5564
+        return $new_array_ids;
5565
+    }
5566
+
5567
+        // 根据父级uid,递归获取所有子级UID数组
5568
+    public function getRecursiveChildren_getcon($parentUid) {
5569
+        $result = []; // 用于存储所有子级的 uid
5570
+
5571
+        // 定义递归函数
5572
+        $recursion = function ($parentUid) use (&$result, &$recursion) {
5573
+            // 查询当前父级的所有直接子级
5574
+            $children = Db::name("user")
5575
+                        ->where("spread_uid", $parentUid)
5576
+                        ->column("uid"); // 获取子级的 uid 列表
5577
+
5578
+            // 如果没有子级,直接返回
5579
+            if (empty($children)) {
5580
+                return;
5581
+            }
5582
+
5583
+            // 遍历每个子级
5584
+            foreach ($children as $childUid) {
5585
+                $result[] = $childUid; // 将子级的 uid 添加到结果数组
5586
+                $recursion($childUid); // 递归查询子级的子级
5587
+            }
5588
+        };
5589
+
5590
+        // 从初始父级开始递归查询
5591
+        $recursion($parentUid);
5592
+
5593
+        return array_unique($result); // 返回结果数组,并去重
5594
+    }
5595
+
5596
+    //只获取数组中的业绩
5597
+    public function getteampv_getcon($common_nums) {
5598
+
5599
+         // // 查询当前用户及其子级的所有订单
5600
+        $orders_gongxian = Db::name("user_sign_gongxian")
5601
+                    ->whereIn('status', [1])
5602
+                    ->whereIn("uid", $common_nums)
5603
+                  
5604
+                    ->select();
5605
+        //var_dump( $common_nums);
5606
+
5607
+        $total_gongxian = 0;
5608
+        // // 遍历订单计算业绩
5609
+         foreach ($orders_gongxian as $order) {
5610
+            if (strpos($order['mark'], "购买") !== false) {
5611
+                $total_gongxian += $order['number'];
5612
+            }
5613
+        }    
5614
+
5615
+         return $total_gongxian;
5616
+
5617
+        // // // 查询当前用户及其子级的所有订单
5618
+        // $orders = Db::name("store_order")
5619
+        //             ->whereIn('status', [0, 1, 2, 3])
5620
+        //             ->whereIn("uid", $common_nums)
5621
+        //             ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
5622
+        //             ->select();
5623
+
5624
+        // // 初始化业绩和人数
5625
+        // $totalPv = 0;
5626
+        // $totalUsers = count($common_nums); // 初始化人数为子级总数
5627
+
5628
+        // // 遍历订单计算业绩
5629
+        // foreach ($orders as $order) {
5630
+        //     if ($order['total_price'] == 1180) {
5631
+        //         $totalPv += 700;
5632
+        //     } else if ($order['total_price'] == 11800) {
5633
+        //         $totalPv += 7000;
5634
+        //     } else if ($order['total_price'] == 10620) {
5635
+        //         $totalPv += 6300;
5636
+        //     } else if ($order['total_price'] == 2360) {
5637
+        //         $totalPv += 1400;
5638
+        //     } else if ($order['total_price'] == 9440) {
5639
+        //         $totalPv += 5600;
5640
+        //     }
5641
+        // }
5642
+
5643
+        // // 返回业绩和人数
5644
+        // return [
5645
+        //     'totalPv' => $totalPv,
5646
+        //     'totalUsers' => $totalUsers
5647
+        // ];
5648
+    }
5649
+
5650
+
5651
+        // 2.0 根据父级uid,找到当前用户下面的UID
5652
+    public function getChildren_getcon($parentUid) {
5653
+        $result = []; // 用于存储所有子级的 uid
5654
+
5655
+    
5656
+            $children = Db::name("user")
5657
+                        ->where("spread_uid", $parentUid)
5658
+                        ->column("uid"); // 获取子级的 uid 列表
5659
+
5660
+        
5661
+        return $children; // 返回结果数组,并去重
5662
+    }
5663
+
5664
+
5665
+      // 递归获取所有子级 UID 的业绩
5666
+    public function getTeamPv11_getcon($parentUid) {
5667
+    
5668
+        $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
5669
+            $children = Db::name("user")
5670
+                        ->where("spread_uid", $parentUid)
5671
+                        ->column("uid");
5672
+            $allChildren = [];
5673
+            foreach ($children as $childUid) {
5674
+                $allChildren[] = $childUid;
5675
+                $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
5676
+            }
5677
+            return $allChildren;
5678
+        };
5679
+
5680
+        // 获取当前用户及其所有子级的 UID
5681
+        $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
5682
+
5683
+
5684
+        $orders_gongxian = Db::name("user_sign_gongxian")
5685
+                    ->whereIn('status', [1])
5686
+                    ->whereIn("uid", $allUids)
5687
+                  
5688
+                    ->select();
5689
+
5690
+
5691
+        $total_gongxian = 0;
5692
+        // // 遍历订单计算业绩
5693
+        foreach ($orders_gongxian as $order) {
5694
+            if (strpos($order['mark'], "购买") !== false) {
5695
+                $total_gongxian += $order['number'];
5696
+            }
5697
+           
5698
+        }    
5699
+
5700
+        return $total_gongxian;
5701
+        // // 查询当前用户及其子级的所有订单
5702
+        // $orders = Db::name("store_order")
5703
+        //             ->whereIn('status', [0, 1, 2, 3])
5704
+        //             ->whereIn("uid", $allUids)
5705
+        //             ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
5706
+        //             ->select();
5707
+
5708
+        // // 计算总业绩
5709
+        // $totalPv = 0;
5710
+        // foreach ($orders as $order) {
5711
+        //     switch ($order['total_price']) {
5712
+        //         case 1180:
5713
+        //             $totalPv += 700;
5714
+        //             break;
5715
+        //         case 11800:
5716
+        //             $totalPv += 7000;
5717
+        //             break;
5718
+        //         case 10620:
5719
+        //             $totalPv += 6300;
5720
+        //             break;
5721
+        //         case 2360:
5722
+        //             $totalPv += 1400;
5723
+        //             break;
5724
+        //         case 9440:
5725
+        //             $totalPv += 5600;
5726
+        //             break;
5727
+        //     }
5728
+        // }
5729
+
5730
+       // return $totalPv;
5731
+    }
5732
+
5733
+    //根据传递的父级数组,返回他的对应子级的个数
5734
+    public function getTeamSize_getcon($parentUids) {
5735
+        // 初始化结果数组
5736
+        $result = [];
5737
+
5738
+        // 遍历每个父级ID
5739
+        foreach ($parentUids as $parentUid) {
5740
+            // 递归获取所有子级 UID
5741
+            $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
5742
+                $children = Db::name("user")
5743
+                            ->where("spread_uid", $parentUid)
5744
+                            ->column("uid");
5745
+
5746
+                // 确保返回的是数组
5747
+                if (!is_array($children)) {
5748
+                    return [];
5749
+                }
5750
+
5751
+                $allChildren = [];
5752
+                foreach ($children as $childUid) {
5753
+                    $allChildren[] = $childUid;
5754
+                    $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
5755
+                }
5756
+                return $allChildren;
5757
+            };
5758
+
5759
+            // 获取当前父级及其所有子级的 UID
5760
+            $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
5761
+
5762
+            // 计算总个数(包括父级自身)
5763
+            $totalUids = count($allUids);
5764
+
5765
+            // 将结果存入数组
5766
+            $result[] = [
5767
+                'parent_uid' => $parentUid,
5768
+                'total_count' => $totalUids
5769
+            ];
5770
+        }
5771
+
5772
+        return $result;
5773
+    }
5774
+
5775
+    public function processArray_getcon($array) {
5776
+        // 初始化结果数组
5777
+        $result = [
5778
+            'max_value' => null,     // 最大值
5779
+            'max_index' => null,     // 最大值的下标
5780
+            'remaining_sum' => 0     // 剩余值的总和
5781
+        ];
5782
+    
5783
+        // 检查数组是否为空
5784
+        if (empty($array)) {
5785
+            return $result;
5786
+        }
5787
+    
5788
+        // 找出最大值及其下标
5789
+        $maxValue = $array[0];
5790
+        $maxIndex = 0;
5791
+        for ($i = 1; $i < count($array); $i++) {
5792
+            if ($array[$i] > $maxValue) {
5793
+                $maxValue = $array[$i];
5794
+                $maxIndex = $i;
5795
+            }
5796
+        }
5797
+    
5798
+        // 计算剩余值的总和
5799
+        $remainingSum = 0;
5800
+        for ($i = 0; $i < count($array); $i++) {
5801
+            if ($i != $maxIndex) {
5802
+                $remainingSum += $array[$i];
5803
+            }
5804
+        }
5805
+    
5806
+        // 将结果存入数组
5807
+        $result['max_value'] = $maxValue;
5808
+        $result['max_index'] = $maxIndex;
5809
+        $result['remaining_sum'] = $remainingSum;
5810
+    
5811
+        return $result;
5812
+    }
5813
+
5814
+       /**
5815
+     * 获取流水信息
5816
+     */
5817
+    public function getPerformance1_getcon($user_id) {
5818
+        // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
5819
+
5820
+        // $amount = isset($amount) ? round($amount*0.7,2) : 0;
5821
+        // return $amount;
5822
+
5823
+        $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
5824
+
5825
+        $money1180Sum = 0;
5826
+
5827
+        foreach ($money1180Records as $record) {
5828
+            $money1180Sum += $record['money'] - 300 - 180;
5829
+        }
5830
+        // var_dump($money1180Sum);
5831
+        $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
5832
+
5833
+        //var_dump($person_nums);
5834
+        //计算个人的11800单价的业绩 集合
5835
+        $money11800Sum = 0;
5836
+
5837
+        foreach ($money11800Records as $record) {
5838
+            $money11800Sum += $record['money'] - 3000 - 1800;
5839
+        }
5840
+
5841
+        $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
5842
+
5843
+        //var_dump($person_nums);
5844
+        //计算个人的11800单价的业绩 集合
5845
+        $money10620Sum = 0;
5846
+
5847
+        foreach ($money10620Records as $record) {
5848
+            $money10620Sum += $record['money'] - 2700 - 1620;
5849
+        }
5850
+
5851
+        // 计算除去特定值后的总和
5852
+        $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
5853
+        $otherMoneySum = 0;
5854
+        foreach ($otherMoneyRecords as $record) {
5855
+            $otherMoneySum += $record['money'];
5856
+        }
5857
+
5858
+        // 分别处理特定值的情况并加上其他值的总和
5859
+        $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
5860
+
5861
+        return $user_person_amount;
5862
+
5863
+
5864
+    }
5865
+
5866
+        //1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
5867
+        public function getparents_child_pv11_getcon($user_id, $bigamount, $smallamount) {
5868
+
5869
+            // 获取直接下级的 UID 列表
5870
+            $get_childs = Db::name("user")
5871
+            ->where("spread_uid", $user_id)
5872
+            ->column("uid");
5873
+
5874
+            // 初始化变量
5875
+            $all_departments = []; // 用于存储所有直属下级的业绩
5876
+
5877
+            // 遍历每个直属下级
5878
+            foreach ($get_childs as $child) {
5879
+                // 获取当前下级及其子级
5880
+                $child_group = [$child];
5881
+                $recursive_children = $this->getRecursiveChildren_getcon($child);
5882
+                $child_group = array_merge($child_group, $recursive_children);
5883
+
5884
+                // 获取当前分组的业绩
5885
+                $result = $this->getteampv_getcon($child_group);
5886
+
5887
+                // 将直属下级的业绩加入数组
5888
+                $all_departments[] = $result;
5889
+            }
5890
+
5891
+            // 将传入的 $bigamount 和 $smallamount 加入数组
5892
+            $all_departments[] = $bigamount;
5893
+            $all_departments[] = $smallamount;
5894
+
5895
+            // 检查是否所有业绩都是 0
5896
+            if (count(array_filter($all_departments, function($value) { return $value != 0; })) == 0) {
5897
+                return [0, 0];
5898
+            }
5899
+
5900
+            // 初始化最大部门和小部门
5901
+            $max_department = 0;
5902
+            $small_department = 0;
5903
+
5904
+            // 遍历 $all_departments,找出最大值并累加小部门的值
5905
+            foreach ($all_departments as $department) {
5906
+                if ($department > $max_department) {
5907
+                    // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
5908
+                    if ($max_department != 0) {
5909
+                        $small_department += $max_department; // 将旧的最大值累加到小部门
5910
+                    }
5911
+                    $max_department = $department; // 更新最大部门
5912
+                } else {
5913
+                    // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
5914
+                    $small_department += $department;
5915
+                }
5916
+            }
5917
+
5918
+            // 返回结果
5919
+            return [
5920
+                $max_department, // 大部门业绩
5921
+                $small_department // 小部门业绩
5922
+            ];
5923
+            //拿$bigamount, $smallamount业绩和get_childs产生的result业绩去对比。如果都是0.说明没有大小部门了,直接返回0,0如果只有一个数组有数据,
5924
+            // 说明只有大部门,默认返回大部门数据,小部门返回0,如果有多条数组数据是一样的,那么就是选一个,设为大部门。剩下的数据叠加设为小部门
5925
+          
5926
+        }
5927
+
5928
+        //获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
5929
+        public function getparents_child_pv_getcon($user_id){
5930
+        // 获取直接下级的 UID 列表
5931
+        //$user_id = 593;
5932
+        // $get_childs = $this->getRecursiveChildren($user_id);
5933
+        $get_childs = Db::name("user")
5934
+        ->where("spread_uid", $user_id)
5935
+        ->column("uid"); // 获取子级的 uid 列表
5936
+        //根据获得的直接推荐下级2.0,来获取他们和她伞下的子级PV。对比拿一个最大的值,设为大部门,其余的是小部门
5937
+
5938
+        //获取直接下级
5939
+        $children_group = []; // 用于存储每个直接下级及其子级的分组
5940
+
5941
+        // 遍历每个直接下级
5942
+        foreach ($get_childs as $child) {
5943
+            $child_group = [$child]; // 将直接下级加入分组
5944
+            $recursive_children = $this->getRecursiveChildren($child); // 获取直接下级的所有子级
5945
+            $child_group = array_merge($child_group, $recursive_children); // 将子级加入分组
5946
+            $children_group[] = $child_group; // 将分组加入最终结果
5947
+        }
5948
+
5949
+
5950
+        $get_teams_comm_datas = [];
5951
+        foreach($children_group as $v){
5952
+                    
5953
+            $get_teams_comm_datas[] = $this->getteampv($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
5954
+        }
5955
+
5956
+        if(count($get_teams_comm_datas)  > 0){
5957
+
5958
+
5959
+            // 找到最大值作为大部门
5960
+            $max_value = max($get_teams_comm_datas);
5961
+            $total_sum = array_sum($get_teams_comm_datas); // 计算数组的总和
5962
+
5963
+            // 小部门为总和减去最大值
5964
+            $small_department = $total_sum - $max_value;
5965
+
5966
+            //返回大部门和小部门
5967
+            return [
5968
+                $max_value,
5969
+                $small_department
5970
+            ];
5971
+
5972
+        }else{
5973
+        return [
5974
+        0,
5975
+        0
5976
+        ];
5977
+        }
5978
+    
5979
+    }
5980
+
5324
 
5981
 
5325
 
5982
 
5326
 
5983