Browse Source

销售复购数据

sunhao 5 years ago
parent
commit
93d1f563a4

+ 150 - 1
app/Http/Controllers/Admin/StatisticsController.php

@@ -19,6 +19,7 @@ use App\DistrictRoi15;
19 19
 use App\DistrictRoi45;
20 20
 use App\DistrictRoi60;
21 21
 use App\SalerTargets;
22
+use App\TemplatesLog;
22 23
 use App\RedisModel as Redis;
23 24
 use Illuminate\Http\Request;
24 25
 use Illuminate\Support\Facades\DB;
@@ -4330,9 +4331,157 @@ class StatisticsController extends Controller
4330 4331
         $filename = 'districtRoiAll_'.date('Y-m-d_H').'.xlsx';
4331 4332
         return Order::export_excel($result, $filename, $indexKey, $title);
4332 4333
     }
4334
+
4335
+    /**
4336
+     * 销售粉丝复购率
4337
+     */
4338
+    public function salerOrderFugou(Request $request){
4339
+        //获取销售
4340
+        $saler_id = (int)$request->input('admin_id');
4341
+        $team_id = (int)$request->input('team_id');
4342
+
4343
+        //假如有团队筛选,检索销售队员
4344
+        $saler_ids = null;
4345
+        if($saler_id>0){
4346
+            $saler_ids = [$saler_id];
4347
+        }elseif($team_id>0){
4348
+            $saler_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
4349
+        }else{
4350
+            $saler_ids = DB::table('admin')->whereIn('team_id', [1,3,5])->lists('id');
4351
+        }
4352
+
4353
+        $page = (int)$request->input('page');
4354
+        $pageSize = 20;
4355
+        if($page<=0){
4356
+            $page = 1;
4357
+        }
4358
+
4359
+        $offset = ($page-1) * $pageSize;
4360
+        $count = count($saler_ids);
4361
+        $saler_ids = array_slice($saler_ids, $offset, $pageSize);
4362
+
4363
+        $result = array();
4364
+        foreach($saler_ids as $k=>$admin_id){
4365
+            $result[$k]['admin_id'] = $admin_id;
4366
+            //pv
4367
+            $temp = TemplatesLog::select(DB::raw('count(1) as tcount, count(if(type=1,true,null)) as pv_count'))->where('admin_id',$admin_id)->first();
4368
+            $result[$k]['tcount'] = $temp->tcount;
4369
+            $result[$k]['pv_count'] = $temp->pv_count;
4370
+            //加粉
4371
+            $custDetail = CustDetail::select(DB::raw('sum(fan_add) as fan_add, admin_name'))->where('admin_id', $admin_id)->where('is_del', 0)->first();
4372
+            if(!empty($custDetail)){
4373
+                $result[$k]['fan_add'] = $custDetail->fan_add;             
4374
+                $result[$k]['admin_name'] = $custDetail->admin_name;
4375
+            }else{
4376
+                $result[$k]['fan_add'] = '';             
4377
+                $result[$k]['admin_name'] = DB::table('admin')->where('id', $admin_id)->pluck('realname');
4378
+            }
4379
+            $result[$k]['long_count'] = $result[$k]['tcount'] - $result[$k]['pv_count'];
4380
+
4381
+            //点击率
4382
+            $result[$k]['click_rate'] = $result[$k]['pv_count']>0 && $result[$k]['long_count']>0 ? round( $result[$k]['long_count'] / $result[$k]['pv_count'], 4 ) * 100 . '%' : '';
4383
+            $result[$k]['change_rate'] = $result[$k]['long_count']>0 && $result[$k]['fan_add']>0 ? round( $result[$k]['fan_add'] / $result[$k]['long_count'], 4 ) * 100 . '%' : '';
4384
+            //下单数据统计
4385
+            $order = Order::select(DB::raw('count(1) as order_count,sum(receivedAmount) as order_amount'))->where('admin_id', $admin_id)->first();
4386
+            $result[$k]['order_count'] = $order->order_count;
4387
+            $result[$k]['order_amount'] = $order->order_amount;
4388
+            //下单用户数
4389
+            $customer_count = DB::table('customers')->where('admin_id', $admin_id)->count();
4390
+            $customer_fugou_count = DB::table('customers')->where('is_fugou', 1)->where('admin_id', $admin_id)->count();
4391
+            //复购率
4392
+            $fugou_rate = $customer_count>0 ? round( $customer_fugou_count / $customer_count, 4 ) * 100 . '%' : '';
4393
+
4394
+            $result[$k]['customer_count'] = $customer_count;
4395
+            $result[$k]['fugou_rate'] = $fugou_rate;
4396
+
4397
+        }
4398
+
4399
+        if ($count > 1) {
4400
+            // 总页数
4401
+            $pages = ceil($count/$pageSize);
4402
+        }else{
4403
+            // 总页数
4404
+            $pages = 1;
4405
+        }
4406
+
4407
+        $teamList = DB::table('teams')->select('id', 'name')->get();
4408
+        $teamList = json_decode(json_encode($teamList), true);
4409
+        $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
4410
+        $adminList = json_decode(json_encode($adminList), true);
4411
+
4412
+        return view('statistics/salerOrderFugou', ['result' =>$result,
4413
+            'page'              =>$page,
4414
+            'count'             =>$count,
4415
+            'pages'             =>$pages,                                    
4416
+            'admin_id'          =>$saler_id,                                        
4417
+            'team_id'           =>$team_id,                                                                              
4418
+            'teamlist'           =>$teamList,                                                                              
4419
+            'adminlist'           =>$adminList,                                                                              
4420
+            ]);
4421
+
4422
+    }
4423
+
4424
+    /**
4425
+     * 销售粉丝复购率导出
4426
+     */
4427
+    public function salerOrderFugou_export(Request $request){
4428
+        //获取销售
4429
+        $saler_id = (int)$request->input('admin_id');
4430
+        $team_id = (int)$request->input('team_id');
4431
+
4432
+        //假如有团队筛选,检索销售队员
4433
+        $saler_ids = null;
4434
+        if($saler_id>0){
4435
+            $saler_ids = [$saler_id];
4436
+        }elseif($team_id>0){
4437
+            $saler_ids = DB::table('admin')->where('team_id', $team_id)->lists('id');
4438
+        }else{
4439
+            $saler_ids = DB::table('admin')->whereIn('team_id', [1,3,5])->lists('id');
4440
+        }
4441
+
4442
+        $result = array();
4443
+        foreach($saler_ids as $k=>$admin_id){
4444
+            $result[$k]['admin_id'] = $admin_id;
4445
+            //pv
4446
+            $temp = TemplatesLog::select(DB::raw('count(1) as tcount, count(if(type=1,true,null)) as pv_count'))->where('admin_id',$admin_id)->first();
4447
+            $result[$k]['tcount'] = $temp->tcount;
4448
+            $result[$k]['pv_count'] = $temp->pv_count;
4449
+            //加粉
4450
+            $custDetail = CustDetail::select(DB::raw('sum(fan_add) as fan_add, admin_name'))->where('admin_id', $admin_id)->where('is_del', 0)->first();
4451
+            if(!empty($custDetail)){
4452
+                $result[$k]['fan_add'] = $custDetail->fan_add;             
4453
+                $result[$k]['admin_name'] = $custDetail->admin_name;
4454
+            }else{
4455
+                $result[$k]['fan_add'] = '';             
4456
+                $result[$k]['admin_name'] = DB::table('admin')->where('id', $admin_id)->pluck('realname');
4457
+            }
4458
+            $result[$k]['long_count'] = $result[$k]['tcount'] - $result[$k]['pv_count'];
4459
+
4460
+            //点击率
4461
+            $result[$k]['click_rate'] = $result[$k]['pv_count']>0 && $result[$k]['long_count']>0 ? round( $result[$k]['long_count'] / $result[$k]['pv_count'], 4 ) * 100 . '%' : '';
4462
+            $result[$k]['change_rate'] = $result[$k]['long_count']>0 && $result[$k]['fan_add']>0 ? round( $result[$k]['fan_add'] / $result[$k]['long_count'], 4 ) * 100 . '%' : '';
4463
+            //下单数据统计
4464
+            $order = Order::select(DB::raw('count(1) as order_count,sum(receivedAmount) as order_amount'))->where('admin_id', $admin_id)->first();
4465
+            $result[$k]['order_count'] = $order->order_count;
4466
+            $result[$k]['order_amount'] = $order->order_amount;
4467
+            //下单用户数
4468
+            $customer_count = DB::table('customers')->where('admin_id', $admin_id)->count();
4469
+            $customer_fugou_count = DB::table('customers')->where('is_fugou', 1)->where('admin_id', $admin_id)->count();
4470
+            //复购率
4471
+            $fugou_rate = $customer_count>0 ? round( $customer_fugou_count / $customer_count, 4 ) * 100 . '%' : '';
4472
+
4473
+            $result[$k]['customer_count'] = $customer_count;
4474
+            $result[$k]['fugou_rate'] = $fugou_rate;
4475
+        }
4476
+
4477
+        $indexKey = ['admin_name','pv_count','long_count','fan_add','change_rate','customer_count','order_count','order_amount','fugou_rate'];
4478
+        $title = ['销售', 'PV量', '累计预估加粉数', '累计加粉数', '加粉转化率', '下单用户数', '累计下单数', '累计销售额', '复购率'];
4479
+        $filename = 'xiaoshoufugou_'.date('Y-m-d_H').'.xlsx';
4480
+        return Order::export_excel($result, $filename, $indexKey, $title);  
4481
+    }
4333 4482
                                                                                 
4334 4483
 }
4335
-                                                                          
4484
+                                                                        
4336 4485
   
4337 4486
   
4338 4487
 

+ 3 - 0
app/Http/routes.php

@@ -210,6 +210,9 @@ Route::group(['prefix' => 'admin'], function(){
210 210
         //销售模板引流每日报表
211 211
         Route::get('template/templateLogReport',   'Admin\TemplateController@templateLogReport');
212 212
         Route::get('template/templateLogReport_export',   'Admin\TemplateController@templateLogReport_export');
213
+        //销售复购率
214
+        Route::get('statistics/salerOrderFugou',   'Admin\StatisticsController@salerOrderFugou');
215
+        Route::get('statistics/salerOrderFugou_export',   'Admin\StatisticsController@salerOrderFugou_export');
213 216
 
214 217
         Route::get('template/sourceindex',   'Admin\TemplateController@sourceindex');
215 218
         Route::get('template/sourcecreate',    'Admin\TemplateController@sourcecreate');

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

@@ -128,7 +128,8 @@
128 128
                    
129 129
                     <ul>                       
130 130
                         <li @if(!isset($res['statistics/districtRoi'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/districtRoi7day')}}" data-title="滚动地域ROI" href="javascript:void(0)">滚动地域ROI</a></li> 
131
-                        <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>                       
131
+                        <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> 
132
+                        <li @if(!isset($res['statistics/salerOrderFugou'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/salerOrderFugou')}}" data-title="销售粉丝复购报表" href="javascript:void(0)">销售粉丝复购报表</a></li>                        
132 133
                     </ul>
133 134
                    
134 135
                 </dd>

+ 143 - 0
resources/views/statistics/salerOrderFugou.blade.php

@@ -0,0 +1,143 @@
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
+                
22
+                <a class="btn btn-primary radius"  style="margin-left: 5px" onclick="user_search()" href="javascript:;">搜索</a>   
23
+                <a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont"></i> 导出数据</a>
24
+                
25
+            </div>
26
+        </div>
27
+        
28
+        <div class="mt-20">
29
+            <table class="table table-border table-bordered table-bg table-hover table-sort">
30
+                <thead>
31
+                <tr class="text-c">
32
+                    <th width="5%">销售</th>
33
+                    <th width="5%">PV量</th>
34
+                    <th width="5%">累计预估加粉数</th>
35
+                    <th width="5%">累计加粉数</th>
36
+                    <th width="5%">加粉转化率</th>
37
+                    <th width="5%">下单用户数</th>
38
+                    <th width="5%">累计下单数</th>
39
+                    <th width="5%">累计销售额</th>                                                
40
+                    <th width="5%">复购率</th>                                                
41
+                                              
42
+                </tr>
43
+                </thead>
44
+                <tbody>
45
+                @if($result)
46
+                    @foreach($result as $a)
47
+                        <tr class="text-c" style=" text-align:center;">                                                                                                             
48
+                            <td>{{$a['admin_name']}}</td>                                                                                   
49
+                            <td>{{$a['pv_count']}}</td>                                                                                   
50
+                            <td>{{$a['long_count']}}</td>                                                                                   
51
+                            <td>{{$a['fan_add']}}</td>                          
52
+                            <td>{{$a['change_rate']}}</td>                                                                                   
53
+                            <td>{{$a['customer_count']}}</td>                                                                                   
54
+                            <td>{{$a['order_count']}}</td>                                                                                   
55
+                            <td>{{$a['order_amount']}}</td>                                                                                   
56
+                            <td>{{$a['fugou_rate']}}</td>                                                                                   
57
+                           
58
+                        </tr>
59
+                    @endforeach
60
+                @endif
61
+                </tbody>
62
+            </table>
63
+        </div>
64
+        <div id="page" class="page_div"></div>
65
+    </div>
66
+    
67
+    <!--_footer 作为公共模版分离出去-->
68
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
69
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
70
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
71
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
72
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
73
+    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
74
+    <!--/_footer 作为公共模版分离出去-->
75
+    <!--/_footer 作为公共模版分离出去-->
76
+     <script type="text/javascript">
77
+        function user_search(){
78
+            var team_id = $('#team_id').val();
79
+            var admin_id = $('#admin_id').val();
80
+
81
+            location.href = 'salerOrderFugou?team_id='+team_id+'&admin_id='+admin_id;
82
+        }
83
+        //导出
84
+        function statistics_export(){
85
+            var team_id = $('#team_id').val();
86
+            var admin_id = $('#admin_id').val();
87
+
88
+            location.href = 'salerOrderFugou_export?team_id='+team_id+'&admin_id='+admin_id;
89
+        }
90
+       
91
+        /*分页*/
92
+            
93
+        $("#page").paging({
94
+            pageNo:{{$page}},
95
+            totalPage: {{$pages}},
96
+            totalSize: {{$count}},
97
+            callback: function(num) {
98
+                var team_id = $('#team_id').val();
99
+                var admin_id = $('#admin_id').val();
100
+                
101
+                location.href='salerOrderFugou?page='+num+'&team_id='+team_id+'&admin_id='+admin_id;
102
+            }
103
+        })
104
+
105
+        $(function(){
106
+            getsale();
107
+        })
108
+
109
+        $('#team_id').change(function(){
110
+            getsale();            
111
+        })
112
+
113
+        function getsale(){
114
+            team = $('#team_id').val();
115
+            if(team=='0'){
116
+                return false;
117
+            }else{
118
+                $.ajax({
119
+                    'url':'/admin/order/teamAdmins/'+team,
120
+                    'type': 'get',
121
+                    'dataType':'json',
122
+                    'success' : function(data){
123
+                        admin_id = '{{$admin_id}}';
124
+                        str = '<option value=\'0\'>-- 选择销售 --<\/option>';
125
+                        $.each(data, function(i, va){
126
+                            sele = '';
127
+                            if(va.id == admin_id){
128
+                                sele = 'selected';
129
+                            }
130
+                            str += '<option value="'+va.id+'" '+sele+'>' + va.realname +'<\/option>';
131
+                        })
132
+                        
133
+                        $('#admin_id').html(str);
134
+                    }
135
+                });
136
+            }
137
+        }
138
+        
139
+    </script>
140
+   
141
+    </body>
142
+
143
+@endsection