sunhao преди 5 години
родител
ревизия
02013a2e9b

+ 77 - 0
app/Http/Controllers/Admin/TemplateController.php

@@ -13,6 +13,7 @@ use App\Templates;
13 13
 use App\TemplatesSalers;
14 14
 use App\AdminRole;
15 15
 use App\TemplatesLog;
16
+use App\CustDetail;
16 17
 use App\Services\OssServices as oss;
17 18
 use Illuminate\Support\Facades\DB;
18 19
 
@@ -254,5 +255,81 @@ class TemplateController extends Controller
254 255
             ]);
255 256
     }
256 257
 
258
+    /**
259
+     * 销售引流模板分配日志报表
260
+     */
261
+    public function templateLogReport(Request $request){
262
+        $admin_id = (int)$request->input('admin_id');
263
+        $team_id = (int)$request->input('team_id');
264
+        $stime = $request->input('stime');
265
+        $etime = $request->input('etime');
266
+
267
+        //假如有团队筛选,检索销售队员
268
+        $sale_ids = null;
269
+        if($team_id>0){
270
+            $sale_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
271
+        }
272
+
273
+        $page = (int)$request->input('page');
274
+        $pageSize = 20;
275
+        if($page<=0){
276
+            $page = 1;
277
+        }
278
+
279
+        $offset = ($page-1) * $pageSize;
280
+
281
+        $count = Templates::where('is_del',0)->count();
282
+        if ($count > 1) {
283
+            // 总页数
284
+            $pages = ceil($count/$pageSize);
285
+        }else{
286
+            // 总页数
287
+            $pages = 1;
288
+        }
289
+
290
+        $result = TemplatesLog::select(DB::raw('left(create_time,10) as day,admin_id,count(1) as tcount, count(if(type=1,true,null)) as pv_count'))->where(function($query) use($admin_id, $stime, $etime, $sale_ids){
291
+            if($admin_id>0) $query->where('admin_id', $admin_id);
292
+            if($stime) $query->where('create_time', '>=', $stime);
293
+            if($etime) $query->where('create_time', '<=', $etime. ' 23:59:59');
294
+            if($sale_ids !== null) $query->whereIn('admin_id', $sale_ids);
295
+        })->groupBy('day')->groupBy('admin_id')->orderBy('day', 'desc')->offset($offset)->limit($pageSize)->get();
296
+        $result = json_decode(json_encode($result), true);
297
+        foreach($result as $k=>&$v){
298
+            //获取销售当天加粉情况
299
+            $custDetail = CustDetail::select('fan_add', 'new_reply', 'new_consult', 'old_consult', 'admin_name')->where('dtime', $v['day'])->where('admin_id', $v['admin_id'])->where('is_del', 0)->first();
300
+            if(!empty($custDetail)){
301
+                $v['fan_add'] = $custDetail->fan_add;
302
+                $v['new_reply'] = $custDetail->new_reply;
303
+                $v['old_consult'] = $custDetail->old_consult;
304
+                $v['new_consult'] = $custDetail->new_consult;
305
+                $v['admin_name'] = $custDetail->admin_name;
306
+            }else{
307
+                $v['fan_add'] = '';
308
+                $v['new_reply'] = '';
309
+                $v['old_consult'] = '';
310
+                $v['new_consult'] = '';
311
+                $v['admin_name'] = DB::table('admin')->where('id', $v['admin_id'])->pluck('realname');
312
+            }
313
+            $v['long_count'] = $v['tcount'] - $v['pv_count'];
314
+        }
315
+
316
+        $teamList = DB::table('teams')->select('id', 'name')->get();
317
+        $teamList = json_decode(json_encode($teamList), true);
318
+        $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
319
+        $adminList = json_decode(json_encode($adminList), true);
320
+
321
+        return view('template/templateLogReport', ['result'=>$result,
322
+            'page'              =>$page,
323
+            'count'             =>$count,
324
+            'pages'             =>$pages,  
325
+            'teamlist'          =>$teamList,  
326
+            'adminlist'         =>$adminList,  
327
+            'team_id'           =>$team_id,  
328
+            'admin_id'          =>$admin_id,  
329
+            'stime'             =>$stime,  
330
+            'etime'             =>$etime,  
331
+        ]);
332
+    }
333
+
257 334
 
258 335
 }

+ 2 - 0
app/Http/routes.php

@@ -198,6 +198,8 @@ Route::group(['prefix' => 'admin'], function(){
198 198
         Route::get('template/getAssigns',   'Admin\TemplateController@getAssigns');
199 199
         Route::post('template/assignSalers',   'Admin\TemplateController@assignSalers');
200 200
         Route::get('template/logindex',   'Admin\TemplateController@logindex');
201
+        //销售模板引流每日报表
202
+        Route::get('template/templateLogReport',   'Admin\TemplateController@templateLogReport');
201 203
     });
202 204
     
203 205
 });

+ 1 - 0
resources/views/admin/index.blade.php

@@ -42,6 +42,7 @@
42 42
                     <ul>
43 43
                         <li @if(!isset($res['template/manage'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/template/index')}}" data-title="模板列表" href="javascript:void(0)">模板列表</a></li>
44 44
                         <li @if(!isset($res['template/manage'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/template/logindex')}}" data-title="模板点击日志" href="javascript:void(0)">模板点击日志</a></li>
45
+                        <li @if(!isset($res['template/manage'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/template/templateLogReport')}}" data-title="销售模板导粉报表" href="javascript:void(0)">销售模板导粉报表</a></li>
45 46
                         
46 47
                     </ul>
47 48
               

+ 152 - 0
resources/views/template/templateLogReport.blade.php

@@ -0,0 +1,152 @@
1
+@extends('admin/master')
2
+@section('content')
3
+    <body>
4
+    <div class="page-container">
5
+        <div>
6
+            <div>
7
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="所属团队"/> 
8
+                <select style="width:10%;text-align:center" id='team_id' name="team_id">
9
+                    <option value="0" @if($team_id=='') selected @endif>-- 选择团队 --</option>
10
+                    @foreach($teamlist as $v)
11
+                        <option value="{{$v['id']}}" @if($team_id==$v['id']) selected @endif>{{$v['name']}}</option>
12
+                    @endforeach
13
+                </select>  
14
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="所属销售"/>
15
+                <select style="width:8%;text-align:center" id='admin_id' name="admin_id">
16
+                    <option value="0" @if($admin_id=='') selected @endif>-- 选择销售 --</option>
17
+                    @foreach($adminlist as $v)
18
+                        <option value="{{$v['id']}}" @if($admin_id==$v['id']) selected @endif>{{$v['realname']}}</option>
19
+                    @endforeach
20
+                </select>                        
21
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="开始时间"/>
22
+                <input id="stime" type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" class="input-text Wdate" style="width:12%;text-align:center;margin-left: -5px" name="stime" value="{{$stime?$stime:''}}">
23
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="结束时间"/>
24
+                <input id="etime"type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" class="input-text Wdate" style="width:12%;text-align:center;margin-left: -5px" name="etime" value="{{$etime?$etime:''}}">
25
+               
26
+                
27
+                <a class="btn btn-primary radius"  style="margin-left: 5px" onclick="user_search()" href="javascript:;">搜索</a>   
28
+                <a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont"></i> 导出数据</a>
29
+                
30
+            </div>
31
+        </div>
32
+        
33
+        <div class="mt-20">
34
+            <table class="table table-border table-bordered table-bg table-hover table-sort">
35
+                <thead>
36
+                <tr class="text-c">
37
+                    <th width="5%">日期</th>
38
+                    <th width="5%">销售名</th>
39
+                    <th width="5%">PV量</th>
40
+                    <th width="5%">长按次数</th>
41
+                    <th width="5%">加粉数</th>
42
+                    <th width="5%">新粉回复数</th>
43
+                    <th width="5%">新粉询价数</th>
44
+                    <th width="5%">老粉询价数</th>                                                
45
+                                              
46
+                </tr>
47
+                </thead>
48
+                <tbody>
49
+                @if($result)
50
+                    @foreach($result as $a)
51
+                        <tr class="text-c" style=" text-align:center;">                           
52
+                            <td>{{$a['day']}}</td>                                                                                   
53
+                            <td>{{$a['admin_name']}}</td>                                                                                   
54
+                            <td>{{$a['pv_count']}}</td>                                                                                   
55
+                            <td>{{$a['long_count']}}</td>                                                                                   
56
+                            <td>{{$a['fan_add']}}</td>                                                                                   
57
+                            <td>{{$a['new_reply']}}</td>                                                                                   
58
+                            <td>{{$a['new_consult']}}</td>                                                                                   
59
+                            <td>{{$a['old_consult']}}</td>                                                                                   
60
+                           
61
+                        </tr>
62
+                    @endforeach
63
+                @endif
64
+                </tbody>
65
+            </table>
66
+        </div>
67
+        <div id="page" class="page_div"></div>
68
+    </div>
69
+    
70
+    <!--_footer 作为公共模版分离出去-->
71
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
72
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
73
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
74
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
75
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
76
+    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
77
+    <!--/_footer 作为公共模版分离出去-->
78
+    <!--/_footer 作为公共模版分离出去-->
79
+     <script type="text/javascript">
80
+        function user_search(){
81
+            var stime = $('#stime').val();
82
+            var etime = $('#etime').val();
83
+            var team_id = $('#team_id').val();
84
+            var admin_id = $('#admin_id').val();
85
+
86
+            location.href = 'templateLogReport?stime='+stime+'&etime='+etime+'&team_id='+team_id+'&admin_id='+admin_id;
87
+        }
88
+        //导出
89
+        function statistics_export(){
90
+            var stime = $('#stime').val();
91
+            var etime = $('#etime').val();
92
+            var team_id = $('#team_id').val();
93
+            var admin_id = $('#admin_id').val();
94
+
95
+            location.href = 'templateLogReport_export?stime='+stime+'&etime='+etime+'&team_id='+team_id+'&admin_id='+admin_id;
96
+        }
97
+       
98
+        /*分页*/
99
+            
100
+        $("#page").paging({
101
+            pageNo:{{$page}},
102
+            totalPage: {{$pages}},
103
+            totalSize: {{$count}},
104
+            callback: function(num) {
105
+                var stime = $('#stime').val();
106
+                var etime = $('#etime').val();
107
+                var team_id = $('#team_id').val();
108
+                var admin_id = $('#admin_id').val();
109
+                
110
+                location.href='templateLogReport?page='+num+'&stime='+stime+'&etime='+etime+'&team_id='+team_id+'&admin_id='+admin_id;
111
+            }
112
+        })
113
+
114
+        $(function(){
115
+            getsale();
116
+        })
117
+
118
+        $('#team_id').change(function(){
119
+            getsale();            
120
+        })
121
+
122
+        function getsale(){
123
+            team = $('#team_id').val();
124
+            if(team=='0'){
125
+                return false;
126
+            }else{
127
+                $.ajax({
128
+                    'url':'/admin/order/teamAdmins/'+team,
129
+                    'type': 'get',
130
+                    'dataType':'json',
131
+                    'success' : function(data){
132
+                        admin_id = '{{$admin_id}}';
133
+                        str = '<option value=\'0\'>-- 选择销售 --<\/option>';
134
+                        $.each(data, function(i, va){
135
+                            sele = '';
136
+                            if(va.id == admin_id){
137
+                                sele = 'selected';
138
+                            }
139
+                            str += '<option value="'+va.id+'" '+sele+'>' + va.realname +'<\/option>';
140
+                        })
141
+                        
142
+                        $('#admin_id').html(str);
143
+                    }
144
+                });
145
+            }
146
+        }
147
+        
148
+    </script>
149
+   
150
+    </body>
151
+
152
+@endsection