Browse Source

团队灵活配置

sunhao 5 years ago
parent
commit
25cba967c8

+ 7 - 6
app/Console/Commands/DayGrandTeamTotal.php

@@ -6,6 +6,7 @@ use DB;
6 6
 use App\CustTotal;
7 7
 use App\CustDetail;
8 8
 use App\Order;
9
+use App\Admin;
9 10
 class DayGrandTeamTotal extends Command {
10 11
 
11 12
     protected $signature = 'DayGrandTeamTotal';
@@ -35,9 +36,9 @@ class DayGrandTeamTotal extends Command {
35 36
             echo "\n日期:".$idate." 已存在";
36 37
             return false;
37 38
         }
38
-        $team_ids = [1,3,5];
39
+        $team_ids = Admin::getTeams();
39 40
         //获取各个团队销售id
40
-        $salerIds = $this->getTeamSalers();
41
+        $salerIds = $this->getTeamSalers($team_ids);
41 42
         foreach($team_ids as $team_id){
42 43
             //获取团队销售
43 44
             $saler_ids = $salerIds[$team_id];
@@ -97,11 +98,11 @@ class DayGrandTeamTotal extends Command {
97 98
         }
98 99
     }
99 100
 
100
-    public function getTeamSalers(){
101
+    public function getTeamSalers($team_ids){
101 102
         $data = array();
102
-        $data[1] = DB::table('admin')->where('team_id', 1)->lists('id');
103
-        $data[3] = DB::table('admin')->where('team_id', 3)->lists('id');
104
-        $data[5] = DB::table('admin')->where('team_id', 5)->lists('id');
103
+        foreach($team_ids as $team_id){
104
+            $data[$team_id] = DB::table('admin')->where('team_id', $team_id)->lists('id');
105
+        }
105 106
         return $data;
106 107
     }
107 108
 

+ 7 - 6
app/Console/Commands/DayGrandTeamTotalHistory.php

@@ -6,6 +6,7 @@ use DB;
6 6
 use App\CustTotal;
7 7
 use App\CustDetail;
8 8
 use App\Order;
9
+use App\Admin;
9 10
 class DayGrandTeamTotalHistory extends Command {
10 11
 
11 12
     protected $signature = 'DayGrandTeamTotalHistory';
@@ -37,9 +38,9 @@ class DayGrandTeamTotalHistory extends Command {
37 38
                 echo "\n日期:".$idate." 已存在";
38 39
                 return false;
39 40
             }
40
-            $team_ids = [1,3,5];
41
+            $team_ids = Admin::getTeams();
41 42
             //获取各个团队销售id
42
-            $salerIds = $this->getTeamSalers();
43
+            $salerIds = $this->getTeamSalers($team_ids);
43 44
             foreach($team_ids as $team_id){
44 45
                 //获取团队销售
45 46
                 $saler_ids = $salerIds[$team_id];
@@ -105,11 +106,11 @@ class DayGrandTeamTotalHistory extends Command {
105 106
         }
106 107
     }
107 108
 
108
-    public function getTeamSalers(){
109
+    public function getTeamSalers($team_ids){
109 110
         $data = array();
110
-        $data[1] = DB::table('admin')->where('team_id', 1)->lists('id');
111
-        $data[3] = DB::table('admin')->where('team_id', 3)->lists('id');
112
-        $data[5] = DB::table('admin')->where('team_id', 5)->lists('id');
111
+        foreach($team_ids as $team_id){
112
+            $data[$team_id] = DB::table('admin')->where('team_id', $team_id)->lists('id');
113
+        }
113 114
         return $data;
114 115
     }
115 116
 

+ 8 - 6
app/Console/Commands/RoiTeamTotal.php

@@ -5,6 +5,7 @@ use Illuminate\Console\Command;
5 5
 use DB;
6 6
 use App\CustTotal;
7 7
 use App\CustDetail;
8
+use App\Admin;
8 9
 class RoiTeamTotal extends Command {
9 10
 
10 11
     protected $signature = 'RoiTeamTotal';
@@ -30,12 +31,13 @@ class RoiTeamTotal extends Command {
30 31
             5 => '-60 day',
31 32
         );
32 33
         //获取各个团队销售id
33
-        $salerIds = $this->getTeamSalers();
34
+        $team_ids = Admin::getTeams();
35
+        $salerIds = $this->getTeamSalers($team_ids);
34 36
         for($i=1;$i<6;$i++){
35 37
             $stime = date('Y-m-d', strtotime($timeArr[$i]));   
36 38
             $etime = $date = date('Y-m-d');
37 39
             //计算date i天内的roi    
38
-            $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, team_id'))->whereIn('team_id', [1,3,5])->where('is_del',0)->where('dtime', $stime)->groupBy('team_id')->get();
40
+            $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, team_id'))->whereIn('team_id', $team_ids)->where('is_del',0)->where('dtime', $stime)->groupBy('team_id')->get();
39 41
 
40 42
             $result = json_decode(json_encode($result), true);           
41 43
             
@@ -83,11 +85,11 @@ class RoiTeamTotal extends Command {
83 85
         return DB::table('roi_team_total')->insert($data);
84 86
     }
85 87
 
86
-    public function getTeamSalers(){
88
+    public function getTeamSalers($team_ids){
87 89
         $data = array();
88
-        $data[1] = DB::table('admin')->where('team_id', 1)->lists('id');
89
-        $data[3] = DB::table('admin')->where('team_id', 3)->lists('id');
90
-        $data[5] = DB::table('admin')->where('team_id', 5)->lists('id');
90
+        foreach($team_ids as $team_id){
91
+            $data[$team_id] = DB::table('admin')->where('team_id', $team_id)->lists('id');
92
+        }
91 93
         return $data;
92 94
     }
93 95
 

+ 8 - 6
app/Console/Commands/RoiTeamTotalHistory.php

@@ -5,6 +5,7 @@ use Illuminate\Console\Command;
5 5
 use DB;
6 6
 use App\CustTotal;
7 7
 use App\CustDetail;
8
+use App\Admin;
8 9
 class RoiTeamTotalHistory extends Command {
9 10
 
10 11
     protected $signature = 'RoiTeamTotalHistory';
@@ -30,7 +31,8 @@ class RoiTeamTotalHistory extends Command {
30 31
             5 => '60',
31 32
         );
32 33
         //获取各个团队销售id
33
-        $salerIds = $this->getTeamSalers();
34
+        $team_ids = Admin::getTeams();
35
+        $salerIds = $this->getTeamSalers($team_ids);
34 36
         for($i=1;$i<6;$i++){
35 37
             $j_min = $timeArr[$i];
36 38
             for($j=69; $j>=$j_min; $j--){
@@ -39,7 +41,7 @@ class RoiTeamTotalHistory extends Command {
39 41
                 $etime = $date = date('Y-m-d', strtotime('-'.$e.' day'));
40 42
 
41 43
                //计算date i天内的roi    
42
-                $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, team_id'))->whereIn('team_id', [1,3,5])->where('is_del',0)->where('dtime', $stime)->groupBy('team_id')->get();
44
+                $result = CustTotal::select(DB::raw('sum(total_cost) as total_cost, sum(total_fan_add) as total_fan_add, team_id'))->whereIn('team_id', $team_ids)->where('is_del',0)->where('dtime', $stime)->groupBy('team_id')->get();
43 45
 
44 46
                 $result = json_decode(json_encode($result), true);           
45 47
                 foreach($result as $k=>$v){
@@ -87,11 +89,11 @@ class RoiTeamTotalHistory extends Command {
87 89
         return DB::table('roi_team_total')->insert($data);
88 90
     }
89 91
 
90
-    public function getTeamSalers(){
92
+    public function getTeamSalers($team_ids){
91 93
         $data = array();
92
-        $data[1] = DB::table('admin')->where('team_id', 1)->lists('id');
93
-        $data[3] = DB::table('admin')->where('team_id', 3)->lists('id');
94
-        $data[5] = DB::table('admin')->where('team_id', 5)->lists('id');
94
+        foreach($team_ids as $team_id){
95
+            $data[$team_id] = DB::table('admin')->where('team_id', $team_id)->lists('id');
96
+        }
95 97
         return $data;
96 98
     }
97 99
 

+ 2 - 1
app/Console/Commands/TeamOrderRateByDay.php

@@ -3,6 +3,7 @@ namespace App\Console\Commands;
3 3
 
4 4
 use Illuminate\Console\Command;
5 5
 use DB;
6
+use App\Admin;
6 7
 class TeamOrderRateByDay extends Command {
7 8
 
8 9
     protected $signature = 'TeamOrderRateByDay';
@@ -20,7 +21,7 @@ class TeamOrderRateByDay extends Command {
20 21
         $this->TeamOrderRateByDay();
21 22
     }
22 23
     public function TeamOrderRateByDay(){
23
-        $team_ids = [1,3,5];
24
+        $team_ids = Admin::getTeams();
24 25
         foreach($team_ids as $team_id){
25 26
             #团队成员:
26 27
             $saler_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');

+ 2 - 1
app/Console/Commands/TeamOrderRateByDayHistory.php

@@ -3,6 +3,7 @@ namespace App\Console\Commands;
3 3
 
4 4
 use Illuminate\Console\Command;
5 5
 use DB;
6
+use App\Admin;
6 7
 class TeamOrderRateByDayHistory extends Command {
7 8
 
8 9
     protected $signature = 'TeamOrderRateByDayHistory';
@@ -20,7 +21,7 @@ class TeamOrderRateByDayHistory extends Command {
20 21
         $this->TeamOrderRateByDayHistory();
21 22
     }
22 23
     public function TeamOrderRateByDayHistory(){
23
-        $team_ids = [1,3,5];
24
+        $team_ids = Admin::getTeams();
24 25
         foreach($team_ids as $team_id){
25 26
             #团队成员:
26 27
             $saler_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');

+ 2 - 1
app/Http/Controllers/Admin/CustReportController.php

@@ -739,8 +739,9 @@ class custReportController extends Controller
739 739
         //销售名字
740 740
         $salers = DB::table('admin')->whereIn('id', $ids)->lists('realname', 'id');
741 741
  
742
+        $stime = date('Y-m-d', strtotime('-15 day'));
742 743
         //查每日上报数据销售
743
-        $result = DB::table('cust_day_detail')->select('admin_id', 'dtime')->where('dtime','<',$today)->where('dtime','>=','2019-09-04')->where('is_del', 0)->orderBy('dtime', 'desc')->get();
744
+        $result = DB::table('cust_day_detail')->select('admin_id', 'dtime')->where('dtime','<',$today)->where('dtime','>=',$stime)->where('is_del', 0)->orderBy('dtime', 'desc')->get();
744 745
         $result = json_decode(json_encode($result), true);
745 746
 
746 747
         $data = array();

+ 7 - 13
app/Http/Controllers/Admin/StatisticsController.php

@@ -3516,7 +3516,7 @@ class StatisticsController extends Controller
3516 3516
         if($etime && $etime<$edate){
3517 3517
             $edate = $etime;
3518 3518
         }
3519
-        $teams = [1,3,5];
3519
+        $teams = Admin::getTeams();
3520 3520
         if($team_id>0){
3521 3521
             $teams = [$team_id];
3522 3522
         }
@@ -4398,12 +4398,13 @@ class StatisticsController extends Controller
4398 4398
 
4399 4399
         //假如有团队筛选,检索销售队员
4400 4400
         $saler_ids = null;
4401
+        $team_ids = Admin::getTeams();
4401 4402
         if($saler_id>0){
4402 4403
             $saler_ids = [$saler_id];
4403 4404
         }elseif($team_id>0){
4404 4405
             $saler_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
4405 4406
         }else{
4406
-            $saler_ids = DB::table('admin')->whereIn('team_id', [1,3,5])->lists('id');
4407
+            $saler_ids = DB::table('admin')->whereIn('team_id', $team_ids)->lists('id');
4407 4408
         }
4408 4409
 
4409 4410
         $page = (int)$request->input('page');
@@ -4519,12 +4520,13 @@ class StatisticsController extends Controller
4519 4520
 
4520 4521
         //假如有团队筛选,检索销售队员
4521 4522
         $saler_ids = null;
4523
+        $team_ids = Admin::getTeams();
4522 4524
         if($saler_id>0){
4523 4525
             $saler_ids = [$saler_id];
4524 4526
         }elseif($team_id>0){
4525 4527
             $saler_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
4526 4528
         }else{
4527
-            $saler_ids = DB::table('admin')->whereIn('team_id', [1,3,5])->lists('id');
4529
+            $saler_ids = DB::table('admin')->whereIn('team_id', $team_ids)->lists('id');
4528 4530
         }
4529 4531
 
4530 4532
         //销售名字
@@ -4838,11 +4840,7 @@ class StatisticsController extends Controller
4838 4840
             if($stime) $query->where('idate', '>=', $stime);
4839 4841
             if($etime) $query->where('idate', '<=', $etime);
4840 4842
         })->count();
4841
-        $teamArr = array(
4842
-            1 => '北京销售团队',
4843
-            3 => '济南销售团队',
4844
-            5 => '杭州雷霆团队',
4845
-        );
4843
+        $teamArr = Admin::getTeamsName();
4846 4844
         $result = DB::table('day_grand_team_total')->where(function($query) use($team_id, $stime, $etime){
4847 4845
             if($team_id) $query->where('team_id', $team_id);
4848 4846
             if($stime) $query->where('idate', '>=', $stime);
@@ -4889,11 +4887,7 @@ class StatisticsController extends Controller
4889 4887
         $stime = $request->input('stime');
4890 4888
         $etime = $request->input('etime');
4891 4889
        
4892
-        $teamArr = array(
4893
-            1 => '北京销售团队',
4894
-            3 => '济南销售团队',
4895
-            5 => '杭州雷霆团队',
4896
-        );
4890
+        $teamArr = Admin::getTeamsName();
4897 4891
         $result = DB::table('day_grand_team_total')->where(function($query) use($team_id, $stime, $etime){
4898 4892
             if($team_id) $query->where('team_id', $team_id);
4899 4893
             if($stime) $query->where('idate', '>=', $stime);