Browse Source

修改贡献升级1

chengzhiyixia 1 year ago
parent
commit
b380be92d6
4 changed files with 1202 additions and 444 deletions
  1. 679 0
      app/controller/api/Auth.php
  2. 68 46
      app/controller/api/store/merchant/Taskorder.php
  3. 451 398
      app/controller/api/user/User.php
  4. 4 0
      route/api.php

+ 679 - 0
app/controller/api/Auth.php

@@ -2038,4 +2038,683 @@ class Auth extends BaseController
2038 2038
         return app('json')->success($result);
2039 2039
     }
2040 2040
 
2041
+
2042
+    
2043
+    public function getconlev(){
2044
+        $userid = 17;
2045
+        $datas = $this->getPerformance22($userid);
2046
+
2047
+        var_dump($datas);
2048
+    }
2049
+
2050
+
2051
+
2052
+    /**
2053
+     * 获取当前用户业绩
2054
+     */
2055
+    public function getPerformance22($user_id) {
2056
+
2057
+      
2058
+
2059
+        $team_amount = 0;
2060
+        $person_amount = 0;
2061
+        $user_id = 593; //598 523 536
2062
+        
2063
+        $result_big_team_arr = [];
2064
+        $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
2065
+        //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
2066
+        $common_nums = $this->getCommonNums($user_id);
2067
+      
2068
+        //var_dump($common_nums);
2069
+        $get_teams_comm_num = 0;
2070
+        $get_teams_comm_pv = 0;
2071
+
2072
+        $get_teams_per_num = 0;//小部门人数
2073
+        //1.0系统中有下级,需要在2.0中再加下级数据
2074
+        if($user_id < 611){
2075
+             //梅红在2.0中的ID是780
2076
+           
2077
+         //var_dump( $common_nums);
2078
+            //用户三峡所有在2.0系统下面的业绩和人数 start
2079
+            $child_nums = [];
2080
+         
2081
+            //获取当前用户
2082
+            foreach($common_nums as $v){
2083
+                $child_nums[] = $this->getRecursiveChildren($v);
2084
+            }
2085
+           
2086
+         
2087
+            //去除空数组,并重新组合有数据的数组
2088
+            $filteredData = array_filter($child_nums, function($array) {
2089
+                return !empty($array); // 如果数组不为空,则保留
2090
+            });
2091
+
2092
+            // 合并所有非空数组
2093
+           
2094
+            foreach ($filteredData as $array) {
2095
+                $result_big_team_arr = array_merge($result_big_team_arr, $array);
2096
+            }
2097
+            //var_dump($result_big_team_arr);
2098
+            //获取当前用户下面在2.0中的下级所有PV
2099
+            //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
2100
+            $t_pv = $this->getteampv($result_big_team_arr);
2101
+            $get_teams_comm_pv = $t_pv;
2102
+            //var_dump($get_teams_comm_pv);echo "ttt";
2103
+
2104
+            //用户伞下小部门所有在2.0系统下面的业绩和人数 end
2105
+        }else{
2106
+          
2107
+               //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
2108
+              $child_nums = $this->getChildren($user_id);
2109
+             
2110
+              //获取父级子级下面的个人
2111
+              $num_teams = $this->getTeamSize($child_nums);
2112
+          
2113
+              //var_dump($num_teams);
2114
+              foreach($child_nums as $v){
2115
+                
2116
+                   $get_teams_comm_datas[] = $this->getTeamPv11($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
2117
+              }
2118
+
2119
+              //$s = $this->getparents_child_pv($user_id);
2120
+
2121
+              //var_dump($get_teams_comm_datas);
2122
+              //如果只有一个部门,就是默认大部门
2123
+              if( count($get_teams_comm_datas) ==1 ){
2124
+                  
2125
+                  $get_teams_comm_pv =$get_teams_comm_datas[0];
2126
+                  $get_teams_comm_num = $num_teams[0]['total_count'];
2127
+                  
2128
+              }else if(count($get_teams_comm_datas) >1){
2129
+
2130
+                    // var_dump( $get_teams_comm_datas);
2131
+                    //获取一个最大值,设为大部门,其他的加载一块是小部门
2132
+                    $getss = $this->processArray($get_teams_comm_datas);
2133
+                 //var_dump($getss);
2134
+                    $max_value_count = $num_teams[$getss['max_index']]['total_count'];
2135
+
2136
+                    unset($num_teams[$getss['max_index']]);
2137
+
2138
+                       //获取小部门的人数
2139
+                       $per_num = 0;
2140
+                       foreach($num_teams as $k=>$v){
2141
+                        $per_num +=$v['total_count'];
2142
+                       }
2143
+        
2144
+                    //找到最大值的(大部门)
2145
+                    //$get_teams_comm_num = $max_value_count;
2146
+                    //小部门的数量
2147
+                   // $get_teams_per_num =  $per_num;
2148
+                    //var_dump($getss['max_value']);
2149
+                    $person_amount = $getss['remaining_sum'];
2150
+                    $get_teams_comm_pv = $getss['max_value'];
2151
+              }
2152
+              
2153
+              
2154
+        }
2155
+        //var_dump($get_teams_comm_pv);
2156
+        //合并业绩和人数
2157
+        $team_amount += $get_teams_comm_pv;
2158
+           
2159
+        //var_dump($team_amount);
2160
+        //1.0获取小区业绩
2161
+        $person_nums = $this->getPersonageNums($user_id);
2162
+        //var_dump($person_nums);
2163
+        $result_small_team_arr = [];
2164
+          //1.0系统中有下级,需要在2.0中再加下级数据
2165
+     
2166
+      
2167
+      
2168
+           //用户三峡所有在2.0系统下面的业绩和人数 start
2169
+            $child_nums_mix = [];
2170
+
2171
+              //获取当前用户
2172
+            foreach($person_nums as $v){
2173
+                $child_nums_mix[] = $this->getRecursiveChildren($v);
2174
+            }
2175
+       
2176
+            //去除空数组,并重新组合有数据的数组
2177
+            $filteredData_1 = array_filter($child_nums_mix, function($array) {
2178
+                return !empty($array); // 如果数组不为空,则保留
2179
+            });
2180
+            
2181
+            // 合并所有非空数组
2182
+            $result_small_team_arr = [];
2183
+            foreach ($filteredData_1 as $array) {
2184
+                $result_small_team_arr = array_merge($result_small_team_arr, $array);
2185
+            }
2186
+
2187
+
2188
+            //var_dump($result_small_team_arr);
2189
+            //获取当前用户下面在2.0中的下级所有PV
2190
+           // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
2191
+           $t_pv = $this->getteampv($result_small_team_arr);
2192
+           $get_teams_per_pv =$t_pv;
2193
+           //var_dump(  $get_teams_per_pv);
2194
+          
2195
+       
2196
+        
2197
+        
2198
+          //获取当前用户下面在2.0中的下级所有人数
2199
+            $get_teams_per_num += count($result_small_team_arr);
2200
+            //合并业绩和人数
2201
+            $person_amount += $get_teams_per_pv;
2202
+
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
+        
2225
+        //当前会员直属的业绩(1.0大部门)
2226
+        $t_pv = $this->getteampv($common_nums);
2227
+        $team_amount += $t_pv;
2228
+
2229
+         //当前会员直属的业绩(1.0大部门)
2230
+        $p_pv = $this->getteampv($person_nums);
2231
+        $person_amount += $p_pv;
2232
+       
2233
+
2234
+      
2235
+    //var_dump($team_amount,$person_amount);
2236
+        //如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
2237
+        if($user_id < 611){
2238
+        
2239
+            //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
2240
+            //例子: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";
2247
+            $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
+
2252
+            $person_amount = $b_s[1];
2253
+
2254
+            // $per_num = $b_s['small_department']['count'];//小部门人数
2255
+            //var_dump( $b_s['team_num'],$b_s['per_num']);
2256
+        }
2257
+
2258
+
2259
+
2260
+        $return_data = [
2261
+           
2262
+            'common_nums_pv'=> $team_amount,
2263
+            'person_nums_pv'=> $person_amount,
2264
+          
2265
+        ];
2266
+
2267
+        return $return_data;
2268
+
2269
+    }
2270
+
2271
+     /**
2272
+     * 获取该用户共建联盟
2273
+     */
2274
+    public function getCommonNums($user_id){
2275
+
2276
+
2277
+
2278
+        //先获取共建联盟下用户的id
2279
+        $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
2280
+        $new_array_ids =[];
2281
+        foreach ($son_ids as $key => $value) {
2282
+            # code...
2283
+            $son_id = $value['id'];
2284
+            $new_array_ids = array_merge($new_array_ids,[$son_id]);
2285
+            $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
2286
+
2287
+            if(count($son_value_ids) > 0) {
2288
+                $son_value_ids = array_column($son_value_ids,"id");
2289
+                $new_array_ids = array_merge($new_array_ids,$son_value_ids);
2290
+            }
2291
+
2292
+        }
2293
+        return $new_array_ids;
2294
+    }
2295
+    /**
2296
+     * 获取该用户个人联盟
2297
+     */
2298
+    public function getPersonageNums($user_id){
2299
+
2300
+        $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
2301
+        $new_array_ids =[];
2302
+        // return 3343;
2303
+        foreach ($son_ids as $key => $value) {
2304
+            # code...
2305
+            $son_id = $value['id'];
2306
+            $new_array_ids = array_merge($new_array_ids,[$son_id]);
2307
+            $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
2308
+
2309
+            if(count($son_value_ids) > 0) {
2310
+                $son_value_ids = array_column($son_value_ids,"id");
2311
+                $new_array_ids = array_merge($new_array_ids,$son_value_ids);
2312
+            }
2313
+
2314
+        }
2315
+        return $new_array_ids;
2316
+    }
2317
+
2318
+        // 根据父级uid,递归获取所有子级UID数组
2319
+    public function getRecursiveChildren($parentUid) {
2320
+        $result = []; // 用于存储所有子级的 uid
2321
+
2322
+        // 定义递归函数
2323
+        $recursion = function ($parentUid) use (&$result, &$recursion) {
2324
+            // 查询当前父级的所有直接子级
2325
+            $children = Db::name("user")
2326
+                        ->where("spread_uid", $parentUid)
2327
+                        ->column("uid"); // 获取子级的 uid 列表
2328
+
2329
+            // 如果没有子级,直接返回
2330
+            if (empty($children)) {
2331
+                return;
2332
+            }
2333
+
2334
+            // 遍历每个子级
2335
+            foreach ($children as $childUid) {
2336
+                $result[] = $childUid; // 将子级的 uid 添加到结果数组
2337
+                $recursion($childUid); // 递归查询子级的子级
2338
+            }
2339
+        };
2340
+
2341
+        // 从初始父级开始递归查询
2342
+        $recursion($parentUid);
2343
+
2344
+        return array_unique($result); // 返回结果数组,并去重
2345
+    }
2346
+
2347
+    //只获取数组中的业绩
2348
+    public function getteampv($common_nums) {
2349
+
2350
+         // // 查询当前用户及其子级的所有订单
2351
+        $orders_gongxian = Db::name("user_sign_gongxian")
2352
+                    ->whereIn('status', [1])
2353
+                    ->whereIn("uid", $common_nums)
2354
+                  
2355
+                    ->select();
2356
+
2357
+
2358
+        $total_gongxian = 0;
2359
+        // // 遍历订单计算业绩
2360
+         foreach ($orders_gongxian as $order) {
2361
+            if (strpos($order['mark'], "购买") !== false) {
2362
+                $total_gongxian += $order['number'];
2363
+            }
2364
+        }    
2365
+
2366
+        return $total_gongxian;
2367
+
2368
+        // // 查询当前用户及其子级的所有订单
2369
+        // $orders = Db::name("store_order")
2370
+        //             ->whereIn('status', [0, 1, 2, 3])
2371
+        //             ->whereIn("uid", $common_nums)
2372
+        //             ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
2373
+        //             ->select();
2374
+
2375
+        // // 初始化业绩和人数
2376
+        // $totalPv = 0;
2377
+        // $totalUsers = count($common_nums); // 初始化人数为子级总数
2378
+
2379
+        // // 遍历订单计算业绩
2380
+        // foreach ($orders as $order) {
2381
+        //     if ($order['total_price'] == 1180) {
2382
+        //         $totalPv += 700;
2383
+        //     } else if ($order['total_price'] == 11800) {
2384
+        //         $totalPv += 7000;
2385
+        //     } else if ($order['total_price'] == 10620) {
2386
+        //         $totalPv += 6300;
2387
+        //     } else if ($order['total_price'] == 2360) {
2388
+        //         $totalPv += 1400;
2389
+        //     } else if ($order['total_price'] == 9440) {
2390
+        //         $totalPv += 5600;
2391
+        //     }
2392
+        // }
2393
+
2394
+        // // 返回业绩和人数
2395
+        // return [
2396
+        //     'totalPv' => $totalPv,
2397
+        //     'totalUsers' => $totalUsers
2398
+        // ];
2399
+    }
2400
+
2401
+
2402
+        // 2.0 根据父级uid,找到当前用户下面的UID
2403
+    public function getChildren($parentUid) {
2404
+        $result = []; // 用于存储所有子级的 uid
2405
+
2406
+    
2407
+            $children = Db::name("user")
2408
+                        ->where("spread_uid", $parentUid)
2409
+                        ->column("uid"); // 获取子级的 uid 列表
2410
+
2411
+        
2412
+        return $children; // 返回结果数组,并去重
2413
+    }
2414
+
2415
+
2416
+      // 递归获取所有子级 UID 的业绩
2417
+    public function getTeamPv11($parentUid) {
2418
+    
2419
+        $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
2420
+            $children = Db::name("user")
2421
+                        ->where("spread_uid", $parentUid)
2422
+                        ->column("uid");
2423
+            $allChildren = [];
2424
+            foreach ($children as $childUid) {
2425
+                $allChildren[] = $childUid;
2426
+                $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
2427
+            }
2428
+            return $allChildren;
2429
+        };
2430
+
2431
+        // 获取当前用户及其所有子级的 UID
2432
+        $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
2433
+
2434
+
2435
+        $orders_gongxian = Db::name("user_sign_gongxian")
2436
+                    ->whereIn('status', [1])
2437
+                    ->whereIn("uid", $allUids)
2438
+                  
2439
+                    ->select();
2440
+
2441
+
2442
+        $total_gongxian = 0;
2443
+        // // 遍历订单计算业绩
2444
+        foreach ($orders_gongxian as $order) {
2445
+            if (strpos($order['mark'], "购买") !== false) {
2446
+                $total_gongxian += $order['number'];
2447
+            }
2448
+           
2449
+        }    
2450
+
2451
+        return $total_gongxian;
2452
+        // // 查询当前用户及其子级的所有订单
2453
+        // $orders = Db::name("store_order")
2454
+        //             ->whereIn('status', [0, 1, 2, 3])
2455
+        //             ->whereIn("uid", $allUids)
2456
+        //             ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
2457
+        //             ->select();
2458
+
2459
+        // // 计算总业绩
2460
+        // $totalPv = 0;
2461
+        // foreach ($orders as $order) {
2462
+        //     switch ($order['total_price']) {
2463
+        //         case 1180:
2464
+        //             $totalPv += 700;
2465
+        //             break;
2466
+        //         case 11800:
2467
+        //             $totalPv += 7000;
2468
+        //             break;
2469
+        //         case 10620:
2470
+        //             $totalPv += 6300;
2471
+        //             break;
2472
+        //         case 2360:
2473
+        //             $totalPv += 1400;
2474
+        //             break;
2475
+        //         case 9440:
2476
+        //             $totalPv += 5600;
2477
+        //             break;
2478
+        //     }
2479
+        // }
2480
+
2481
+       // return $totalPv;
2482
+    }
2483
+
2484
+    //根据传递的父级数组,返回他的对应子级的个数
2485
+    public function getTeamSize($parentUids) {
2486
+        // 初始化结果数组
2487
+        $result = [];
2488
+
2489
+        // 遍历每个父级ID
2490
+        foreach ($parentUids as $parentUid) {
2491
+            // 递归获取所有子级 UID
2492
+            $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
2493
+                $children = Db::name("user")
2494
+                            ->where("spread_uid", $parentUid)
2495
+                            ->column("uid");
2496
+
2497
+                // 确保返回的是数组
2498
+                if (!is_array($children)) {
2499
+                    return [];
2500
+                }
2501
+
2502
+                $allChildren = [];
2503
+                foreach ($children as $childUid) {
2504
+                    $allChildren[] = $childUid;
2505
+                    $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
2506
+                }
2507
+                return $allChildren;
2508
+            };
2509
+
2510
+            // 获取当前父级及其所有子级的 UID
2511
+            $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
2512
+
2513
+            // 计算总个数(包括父级自身)
2514
+            $totalUids = count($allUids);
2515
+
2516
+            // 将结果存入数组
2517
+            $result[] = [
2518
+                'parent_uid' => $parentUid,
2519
+                'total_count' => $totalUids
2520
+            ];
2521
+        }
2522
+
2523
+        return $result;
2524
+    }
2525
+
2526
+    public function processArray($array) {
2527
+        // 初始化结果数组
2528
+        $result = [
2529
+            'max_value' => null,     // 最大值
2530
+            'max_index' => null,     // 最大值的下标
2531
+            'remaining_sum' => 0     // 剩余值的总和
2532
+        ];
2533
+    
2534
+        // 检查数组是否为空
2535
+        if (empty($array)) {
2536
+            return $result;
2537
+        }
2538
+    
2539
+        // 找出最大值及其下标
2540
+        $maxValue = $array[0];
2541
+        $maxIndex = 0;
2542
+        for ($i = 1; $i < count($array); $i++) {
2543
+            if ($array[$i] > $maxValue) {
2544
+                $maxValue = $array[$i];
2545
+                $maxIndex = $i;
2546
+            }
2547
+        }
2548
+    
2549
+        // 计算剩余值的总和
2550
+        $remainingSum = 0;
2551
+        for ($i = 0; $i < count($array); $i++) {
2552
+            if ($i != $maxIndex) {
2553
+                $remainingSum += $array[$i];
2554
+            }
2555
+        }
2556
+    
2557
+        // 将结果存入数组
2558
+        $result['max_value'] = $maxValue;
2559
+        $result['max_index'] = $maxIndex;
2560
+        $result['remaining_sum'] = $remainingSum;
2561
+    
2562
+        return $result;
2563
+    }
2564
+
2565
+       /**
2566
+     * 获取流水信息
2567
+     */
2568
+    public function getPerformance1($user_id) {
2569
+        // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
2570
+
2571
+        // $amount = isset($amount) ? round($amount*0.7,2) : 0;
2572
+        // return $amount;
2573
+
2574
+        $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
2575
+
2576
+        $money1180Sum = 0;
2577
+
2578
+        foreach ($money1180Records as $record) {
2579
+            $money1180Sum += $record['money'] - 300 - 180;
2580
+        }
2581
+        // var_dump($money1180Sum);
2582
+        $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
2583
+
2584
+        //var_dump($person_nums);
2585
+        //计算个人的11800单价的业绩 集合
2586
+        $money11800Sum = 0;
2587
+
2588
+        foreach ($money11800Records as $record) {
2589
+            $money11800Sum += $record['money'] - 3000 - 1800;
2590
+        }
2591
+
2592
+        $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
2593
+
2594
+        //var_dump($person_nums);
2595
+        //计算个人的11800单价的业绩 集合
2596
+        $money10620Sum = 0;
2597
+
2598
+        foreach ($money10620Records as $record) {
2599
+            $money10620Sum += $record['money'] - 2700 - 1620;
2600
+        }
2601
+
2602
+        // 计算除去特定值后的总和
2603
+        $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
2604
+        $otherMoneySum = 0;
2605
+        foreach ($otherMoneyRecords as $record) {
2606
+            $otherMoneySum += $record['money'];
2607
+        }
2608
+
2609
+        // 分别处理特定值的情况并加上其他值的总和
2610
+        $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
2611
+
2612
+        return $user_person_amount;
2613
+
2614
+
2615
+    }
2616
+
2617
+        //1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
2618
+        public function getparents_child_pv11($user_id, $bigamount, $smallamount) {
2619
+        // 获取直接下级的 UID 列表
2620
+            $get_childs = Db::name("user")
2621
+            ->where("spread_uid", $user_id)
2622
+            ->column("uid");
2623
+
2624
+            // 如果没有直属下级,直接返回 [0, 0]
2625
+            if (empty($get_childs)) {
2626
+                return [0, 0];
2627
+            }
2628
+
2629
+            // 初始化数组存储直属下级的业绩
2630
+            $all_departments = [];
2631
+
2632
+            // 遍历每个直属下级
2633
+            foreach ($get_childs as $child) {
2634
+                // 获取当前下级及其子级
2635
+                $child_group = [$child];
2636
+                $recursive_children = $this->getRecursiveChildren($child);
2637
+                $child_group = array_merge($child_group, $recursive_children);
2638
+
2639
+                // 获取当前分组的业绩
2640
+                $result = $this->getteampv($child_group);
2641
+
2642
+                // 如果返回的业绩为 null 或 0,直接返回 [0, 0]
2643
+                if ($result === null || $result['totalPv'] == 0) {
2644
+                    return [0, 0];
2645
+                }
2646
+
2647
+                // 将直属下级的业绩加入数组
2648
+                $all_departments[] = $result['totalPv'];
2649
+            }
2650
+
2651
+            // 将传入的 $bigamount 和 $smallamount 也加入数组
2652
+            $all_departments[] = $bigamount;
2653
+            $all_departments[] = $smallamount;
2654
+
2655
+            // 找出最大业绩
2656
+            $max_department = max($all_departments);
2657
+
2658
+            // 计算小部门业绩:总和 - 最大值
2659
+            $small_department = array_sum($all_departments) - $max_department;
2660
+var_dump($max_department);
2661
+            // 返回结果
2662
+            return [$max_department, $small_department];
2663
+
2664
+        }
2665
+
2666
+        //获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
2667
+        public function getparents_child_pv($user_id){
2668
+        // 获取直接下级的 UID 列表
2669
+        //$user_id = 593;
2670
+        // $get_childs = $this->getRecursiveChildren($user_id);
2671
+        $get_childs = Db::name("user")
2672
+        ->where("spread_uid", $user_id)
2673
+        ->column("uid"); // 获取子级的 uid 列表
2674
+        //根据获得的直接推荐下级2.0,来获取他们和她伞下的子级PV。对比拿一个最大的值,设为大部门,其余的是小部门
2675
+
2676
+        //获取直接下级
2677
+        $children_group = []; // 用于存储每个直接下级及其子级的分组
2678
+
2679
+        // 遍历每个直接下级
2680
+        foreach ($get_childs as $child) {
2681
+            $child_group = [$child]; // 将直接下级加入分组
2682
+            $recursive_children = $this->getRecursiveChildren($child); // 获取直接下级的所有子级
2683
+            $child_group = array_merge($child_group, $recursive_children); // 将子级加入分组
2684
+            $children_group[] = $child_group; // 将分组加入最终结果
2685
+        }
2686
+
2687
+
2688
+        $get_teams_comm_datas = [];
2689
+        foreach($children_group as $v){
2690
+                    
2691
+            $get_teams_comm_datas[] = $this->getteampv($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
2692
+        }
2693
+
2694
+        if(count($get_teams_comm_datas)  > 0){
2695
+
2696
+
2697
+            // 找到最大值作为大部门
2698
+            $max_value = max($get_teams_comm_datas);
2699
+            $total_sum = array_sum($get_teams_comm_datas); // 计算数组的总和
2700
+
2701
+            // 小部门为总和减去最大值
2702
+            $small_department = $total_sum - $max_value;
2703
+
2704
+            //返回大部门和小部门
2705
+            return [
2706
+                $max_value,
2707
+                $small_department
2708
+            ];
2709
+
2710
+        }else{
2711
+        return [
2712
+        0,
2713
+        0
2714
+        ];
2715
+        }
2716
+    
2717
+    }
2718
+
2719
+
2041 2720
 }

+ 68 - 46
app/controller/api/store/merchant/Taskorder.php

@@ -73,7 +73,7 @@ class Taskorder extends BaseController
73 73
     {
74 74
 
75 75
        
76
-     return;
76
+   
77 77
         // $user_datas = Db::name("user")->select();//星级等级
78 78
         // foreach($user_datas as $k=>$v){
79 79
         //     if($v['user_level_id_old']==2){
@@ -89,9 +89,9 @@ class Taskorder extends BaseController
89 89
     
90 90
     //    var_dump($totalPv);return;    
91 91
     
92
-       //  $ss = $this->getbig_samll_datas(523);
93
-        // var_dump($ss);    return;
94
-        // return;
92
+         $ss = $this->getbig_samll_datas(222);
93
+         var_dump($ss);    return;
94
+      
95 95
      
96 96
         // $store_product_datas = Db::name('old_user_of_goods_old')->select();
97 97
        
@@ -1218,7 +1218,7 @@ public function getbig_samll_datas($user_id) {
1218 1218
                 if(count($child_nums)==1){
1219 1219
                     //var_dump($child_nums);
1220 1220
                     //获取父级子级下面的个人
1221
-                    $get_teams_comm_pv = $this->getTeamPv11($child_nums[0]);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
1221
+                    $get_teams_comm_pv = $this->getTeamPv11($child_nums[0]);//如果有只有个父级ID,默认为大部门,小部门为0
1222 1222
                     // var_dump($get_teams_comm_pv);
1223 1223
                     
1224 1224
                 }else if(count($child_nums) > 1){
@@ -1243,62 +1243,29 @@ public function getbig_samll_datas($user_id) {
1243 1243
        
1244 1244
         }
1245 1245
 
1246
-        $team_amount   = 0;
1247
-        $person_amount = 0;
1246
+        // $team_amount   = 0;
1247
+        // $person_amount = 0;
1248 1248
 
1249 1249
         if($user_id < 611){
1250 1250
          
1251 1251
             //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
1252 1252
             //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
1253
-            $b_s = $this->getparents_child_pv($user_id);
1253
+            $b_s = $this->getparents_child_pv11($user_id,$get_teams_comm_pv, $get_teams_per_pv);
1254 1254
             
1255 1255
             //var_dump( $b_s);echo "yyyyyyyyyyyyy";
1256
-            $team_amount = $b_s[0];
1257
-            $person_amount = $b_s[1];
1256
+            $get_teams_comm_pv = $b_s[0];
1257
+            $get_teams_per_pv = $b_s[1];
1258 1258
 
1259
-          
1260 1259
         }
1261 1260
 
1262
-    //var_dump("小区业绩:".$get_teams_per_pv);
1263
-
1264
-        //var_dump($team_amount, $person_amount);
1265
-    // if($user_id == 523){
1266
-    //     // 计算大部门和小部门的汇总信息
1267
-    //     $majorDepartmentSummary = [
1268
-    //         "total_performance" =>  0,
1269
-    //     ];
1270
-
1271
-    //     $minorDepartmentSummary = [
1272
-    //         "total_performance" => 7000,
1273
-    //     ];
1274
-
1275
-    // }else if($user_id == 598){
1276
-    //     // 计算大部门和小部门的汇总信息
1277
-    //     $majorDepartmentSummary = [
1278
-    //         "total_performance" =>  7000,
1279
-    //     ];
1280
-
1281
-    //     $minorDepartmentSummary = [
1282
-    //         "total_performance" => 7000,
1283
-    //     ];
1284
-    // }else{
1285
-    //     // 计算大部门和小部门的汇总信息
1286
-    //     $majorDepartmentSummary = [
1287
-    //         "total_performance" =>  $get_teams_comm_pv +  $team_amount,
1288
-    //     ];
1289
-
1290
-    //     $minorDepartmentSummary = [
1291
-    //         "total_performance" => $get_teams_per_pv  + $person_amount,
1292
-    //     ];
1293
-    // }
1294
-
1261
+   
1295 1262
       // 计算大部门和小部门的汇总信息
1296 1263
         $majorDepartmentSummary = [
1297
-            "total_performance" =>  $get_teams_comm_pv +  $team_amount,
1264
+            "total_performance" =>  $get_teams_comm_pv,
1298 1265
         ];
1299 1266
 
1300 1267
         $minorDepartmentSummary = [
1301
-            "total_performance" => $get_teams_per_pv  + $person_amount,
1268
+            "total_performance" => $get_teams_per_pv,
1302 1269
         ];
1303 1270
 
1304 1271
     
@@ -1310,6 +1277,61 @@ public function getbig_samll_datas($user_id) {
1310 1277
     ];
1311 1278
 }
1312 1279
 
1280
+//1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
1281
+public function getparents_child_pv11($user_id, $bigamount, $smallamount) {
1282
+    // 获取直接下级的 UID 列表
1283
+    $get_childs = Db::name("user")
1284
+        ->where("spread_uid", $user_id)
1285
+        ->column("uid");
1286
+
1287
+    // 如果没有直属下级,直接返回 [0, 0]
1288
+    if (empty($get_childs)) {
1289
+        return [0, 0];
1290
+    }
1291
+
1292
+    // 初始化数组存储直属下级的业绩
1293
+    $all_departments = [];
1294
+
1295
+    // 遍历每个直属下级
1296
+    foreach ($get_childs as $child) {
1297
+        // 获取当前下级及其子级
1298
+        $child_group = [$child];
1299
+        $recursive_children = $this->getRecursiveChildren($child);
1300
+        $child_group = array_merge($child_group, $recursive_children);
1301
+
1302
+        // 获取当前分组的业绩
1303
+        $result = $this->getteampv($child_group);
1304
+//var_dump(  $result);
1305
+        // 如果返回的业绩为 null 或 0,直接返回 [0, 0]
1306
+        // if ($result === null || $result == 0) {
1307
+        //     return [0, 0];
1308
+        // }
1309
+
1310
+        // 将直属下级的业绩加入数组
1311
+        $all_departments[] = $result;
1312
+    }
1313
+
1314
+   
1315
+    if(count( $all_departments) > 0 ){
1316
+        //var_dump($all_departments);
1317
+        // 将传入的 $bigamount 和 $smallamount 也加入数组
1318
+        $all_departments[] = $bigamount;
1319
+        $all_departments[] = $smallamount;
1320
+
1321
+        // 找出最大业绩
1322
+        $max_department = max($all_departments);
1323
+
1324
+        // 计算小部门业绩:总和 - 最大值
1325
+        $small_department = array_sum($all_departments) - $max_department;
1326
+
1327
+        // 返回结果
1328
+        return [$max_department, $small_department];
1329
+    }else{
1330
+        return [0, 0];
1331
+    }
1332
+    
1333
+}
1334
+
1313 1335
 //获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
1314 1336
 public function getparents_child_pv($user_id){
1315 1337
     // 获取直接下级的 UID 列表

File diff suppressed because it is too large
+ 451 - 398
app/controller/api/user/User.php


+ 4 - 0
route/api.php

@@ -41,6 +41,10 @@ Route::group('api/', function () {
41 41
         Route::post('logout', 'api.Auth/logout');
42 42
         //用户信息
43 43
         Route::get('user', 'api.Auth/userInfo');
44
+
45
+         //用户升级(贡献值)
46
+         Route::get('user/getconlev', 'api.Auth/getconlev');
47
+
44 48
         //整合用户登录token
45 49
         Route::post('tokenList', 'api.Auth/tokenList');
46 50