sunhao 5 years ago
parent
commit
78e73745ca

+ 37 - 9
app/Http/Controllers/Admin/CustReportController.php

@@ -326,23 +326,42 @@ class custReportController extends Controller
326 326
         }
327 327
 
328 328
         $offset = ($page-1) * $pageSize;
329
-        
329
+        $team_id = (int)$request->input('team_id');
330
+        $admin_id = (int)$request->input('admin_id');
331
+
332
+        $search_admin = 1;
333
+        #只能看自己团队的
330 334
         $self_role = session('role_name');
331
-        if($self_role == '超级管理员' || $self_role == '团队主管' || $self_role == '运营投放'  || $self_role == '售后管理员'){
332
-            $admin_id = $request->input('admin_id');
333
-            $search_admin = 1;
334
-        }else{
335
-            $admin_id = session('admin_id');
335
+        if($self_role != '超级管理员' && $self_role != '售后管理员'){
336
+            $self_id = session('admin_id');
337
+            $team_id = DB::table('admin')->where('id', $self_id)->pluck('team_id');                  
338
+        }
339
+
340
+        if($admin_id>0 && !$team_id){
341
+            $team_id = DB::table('admin')->where('id', $admin_id)->pluck('team_id');
342
+        }
343
+
344
+        if($self_role == '销售'){
336 345
             $search_admin = 0;
346
+            $admin_id = $self_id;
347
+        }
348
+
349
+        //假如有团队筛选,检索销售队员
350
+        $sale_ids = null;
351
+        if($team_id>0 && !$admin_id){
352
+            $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
337 353
         }
338 354
 
355
+        
356
+
339 357
         $stime = $request->input('stime');
340 358
         $etime = $request->input('etime');
341 359
 
342
-        $count = CustDetail::where(function($query) use($admin_id, $stime, $etime){
360
+        $count = CustDetail::where(function($query) use($admin_id, $stime, $etime, $sale_ids){
343 361
             if($admin_id) $query->where('admin_id', $admin_id);
344 362
             if($stime) $query->where('dtime', '>=', $stime);
345 363
             if($etime) $query->where('dtime', '<=', $etime);
364
+            if($sale_ids) $query->whereIn('admin_id', $sale_ids);
346 365
         })->where('is_del',0)->count();
347 366
         if ($count > 1) {
348 367
             // 总页数
@@ -352,14 +371,21 @@ class custReportController extends Controller
352 371
             $pages = 1;
353 372
         }
354 373
 
355
-        $result = CustDetail::where(function($query) use($admin_id, $stime, $etime){
374
+        $result = CustDetail::where(function($query) use($admin_id, $stime, $etime, $sale_ids){
356 375
             if($admin_id) $query->where('admin_id', $admin_id);
357 376
             if($stime) $query->where('dtime', '>=', $stime);
358 377
             if($etime) $query->where('dtime', '<=', $etime);
378
+            if($sale_ids) $query->whereIn('admin_id', $sale_ids);
359 379
         })->where('is_del',0)->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
360 380
         $result = json_decode(json_encode($result),true);
361 381
 
362
-        $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
382
+        $teamList = DB::table('teams')->select('id', 'name')->where(function($query) use($self_role, $team_id){
383
+            if($team_id>0 && $self_role != '超级管理员' && $self_role != '售后管理员') $query->where('id', $team_id);
384
+        })->get();
385
+        $teamList = json_decode(json_encode($teamList), true);
386
+        $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->where(function($query) use($self_role, $team_id){
387
+            if($team_id>0 && $self_role != '超级管理员' && $self_role != '售后管理员') $query->where('team_id', $team_id);
388
+        })->get();
363 389
         $adminList = json_decode(json_encode($adminList), true);
364 390
 
365 391
         //未上报数据销售
@@ -373,8 +399,10 @@ class custReportController extends Controller
373 399
             'stime'             =>$stime,
374 400
             'etime'             =>$etime,
375 401
             'admin_id'          =>$admin_id,
402
+            'team_id'          =>$team_id,
376 403
             'search_admin'      =>$search_admin,
377 404
             'adminlist'         =>$adminList,
405
+            'teamlist'         =>$teamList,
378 406
             'noReportSaler'         =>$noReportSaler,
379 407
             'no_height'         =>$no_height,
380 408
             ]);

+ 49 - 4
resources/views/custreport/detaillist.blade.php

@@ -6,8 +6,15 @@
6 6
             <div>
7 7
                 <a class="btn btn-primary radius" onclick="custreport_add('新增', 0)" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 新增数据</a>
8 8
                 @if($search_admin == 1)
9
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="所属团队"/> 
10
+                <select style="width:10%;text-align:center" id='team_id' name="team_id">
11
+                    <option value="0" @if($team_id=='') selected @endif>-- 选择团队 --</option>
12
+                    @foreach($teamlist as $v)
13
+                        <option value="{{$v['id']}}" @if($team_id==$v['id']) selected @endif>{{$v['name']}}</option>
14
+                    @endforeach
15
+                </select>  
9 16
                 <input class="input-text" style="width:6%;text-align:center" type="text" value="所属销售"/>
10
-                <select style="width:10%;text-align:center" id='admin_id' name="admin_id">
17
+                <select style="width:8%;text-align:center" id='admin_id' name="admin_id">
11 18
                     <option value="0" @if($admin_id=='') selected @endif>-- 选择销售 --</option>
12 19
                     @foreach($adminlist as $v)
13 20
                         <option value="{{$v['id']}}" @if($admin_id==$v['id']) selected @endif>{{$v['realname']}}</option>
@@ -142,15 +149,17 @@
142 149
             var admin_id = $('#admin_id').val();
143 150
             var stime = $('#stime').val();
144 151
             var etime = $('#etime').val();
152
+            var team_id = $('#team_id').val();
145 153
             var page = {{$page}};
146
-            location.href = 'detailindex?page='+page+'&admin_id='+admin_id+'&stime='+stime+'&etime='+etime;
154
+            location.href = 'detailindex?page='+page+'&admin_id='+admin_id+'&stime='+stime+'&etime='+etime+'&team_id='+team_id;
147 155
         }
148 156
         //导出
149 157
         function custreport_export(){
150 158
             var admin_id = $('#admin_id').val();
151 159
             var stime = $('#stime').val();
152 160
             var etime = $('#etime').val();
153
-            location.href = '/admin/custreport/detail_export?admin_id='+admin_id+'&stime='+stime+'&etime='+etime;
161
+            var team_id = $('#team_id').val();
162
+            location.href = '/admin/custreport/detail_export?admin_id='+admin_id+'&stime='+stime+'&etime='+etime+'&team_id='+team_id;
154 163
         }
155 164
 
156 165
         /*弹出层-*/
@@ -171,11 +180,47 @@
171 180
             totalSize: {{$count}},
172 181
             callback: function(num) {
173 182
                 var admin_id = $('#admin_id').val();
183
+                var team_id = $('#team_id').val();
174 184
                 var stime = $('#stime').val();
175 185
                 var etime = $('#etime').val();
176
-                location.href='detailindex?page='+num+'&admin_id='+admin_id+'&stime='+stime+'&etime='+etime;
186
+                location.href='detailindex?page='+num+'&admin_id='+admin_id+'&stime='+stime+'&etime='+etime+'&team_id='+team_id;
177 187
             }
178 188
         })
189
+
190
+
191
+        $(function(){
192
+            getsale();
193
+        })
194
+
195
+        $('#team_id').change(function(){
196
+            getsale();            
197
+        })
198
+
199
+        function getsale(){
200
+            team = $('#team_id').val();
201
+            if(team=='0'){
202
+                return false;
203
+            }else{
204
+                $.ajax({
205
+                    'url':'/admin/order/teamAdmins/'+team,
206
+                    'type': 'get',
207
+                    'dataType':'json',
208
+                    'success' : function(data){
209
+                        admin_id = '{{$admin_id}}';
210
+                        str = '<option value=\'0\'>-- 选择销售 --<\/option>';
211
+                        $.each(data, function(i, va){
212
+                            sele = '';
213
+                            if(va.id == admin_id){
214
+                                sele = 'selected';
215
+                            }
216
+                            str += '<option value="'+va.id+'" '+sele+'>' + va.realname +'<\/option>';
217
+                        })
218
+                        
219
+                        $('#admin_id').html(str);
220
+                    }
221
+                });
222
+            }
223
+        }
179 224
         
180 225
     </script>
181 226