sunhao %!s(int64=5) %!d(string=před) roky
rodič
revize
c0c003b96d

+ 105 - 0
app/Http/Controllers/Admin/StatisticsController.php

@@ -4956,6 +4956,111 @@ class StatisticsController extends Controller
4956 4956
         }
4957 4957
         return '';
4958 4958
     }
4959
+
4960
+    /**
4961
+     * 分团队每日roi汇总数据
4962
+     */
4963
+    public function dayGrandSalerTotal(Request $request){
4964
+        $team_id = (int)$request->input('team_id');
4965
+        $admin_id = (int)$request->input('admin_id');
4966
+        $stime = $request->input('stime');
4967
+        $etime = $request->input('etime');
4968
+        $page = (int)$request->input('page');
4969
+        $pageSize = 20;
4970
+        if($page<=0){
4971
+            $page = 1;
4972
+        }
4973
+        
4974
+        $offset = ($page-1) * $pageSize;
4975
+        
4976
+        //查询历史数据
4977
+        $count = DB::table('day_grand_saler_total')->where(function($query) use($team_id, $stime, $etime, $admin_id){
4978
+            if($team_id) $query->where('team_id', $team_id);
4979
+            if($admin_id) $query->where('admin_id', $admin_id);
4980
+            if($stime) $query->where('idate', '>=', $stime);
4981
+            if($etime) $query->where('idate', '<=', $etime);
4982
+        })->count();
4983
+        $teamArr = DB::table('teams')->lists('name', 'id');
4984
+        $adminArr = DB::table('admin')->lists('realname', 'id');
4985
+        $result = DB::table('day_grand_saler_total')->where(function($query) use($team_id, $stime, $etime, $admin_id){
4986
+            if($team_id) $query->where('team_id', $team_id);
4987
+            if($admin_id) $query->where('admin_id', $admin_id);
4988
+            if($stime) $query->where('idate', '>=', $stime);
4989
+            if($etime) $query->where('idate', '<=', $etime);
4990
+        })->orderBy('idate', 'desc')->offset($offset)->limit($pageSize)->get();
4991
+        $result = json_decode(json_encode($result), true);
4992
+        foreach($result as $k=>&$v){
4993
+            $v['roi'] = $v['throw_cost']>0 ? round($v['order_amount'] / $v['throw_cost'], 4) * 100 .'%' : '';
4994
+            $v['fugou_rate'] = $v['cust_count']>0 ? round($v['fugou_order_count'] / $v['cust_count'], 4) : '';
4995
+            $v['roi7'] = $v['cost7']>0?  round($v['order_amount7'] / $v['cost7'], 4) * 100 .'%' : '';
4996
+            $v['roi15'] = $v['cost15']>0?  round($v['order_amount15'] / $v['cost15'], 4) * 100 .'%' : '';
4997
+            $v['roi30'] = $v['cost30']>0?  round($v['order_amount30'] / $v['cost30'], 4) * 100 .'%' : '';
4998
+            $v['roi45'] = $v['cost45']>0?  round($v['order_amount45'] / $v['cost45'], 4) * 100 .'%' : '';
4999
+            $v['roi60'] = $v['cost60']>0?  round($v['order_amount60'] / $v['cost60'], 4) * 100 .'%' : '';
5000
+            $v['team_name'] = $teamArr[$v['team_id']];
5001
+            $v['admin_name'] = $adminArr[$v['admin_id']];
5002
+        }
5003
+
5004
+        if ($count > 1) {
5005
+            // 总页数
5006
+            $pages = ceil($count/20);
5007
+        }else{
5008
+            // 总页数
5009
+            $pages = 1;
5010
+        }
5011
+
5012
+        $teamList = DB::table('teams')->select('id', 'name')->get();
5013
+        $teamList = json_decode(json_encode($teamList), true);
5014
+        $adminList = DB::table('admin')->select('id', 'realname', 'username')->where('id','>', 1)->get();
5015
+        $adminList = json_decode(json_encode($adminList), true);
5016
+        return view('statistics/dayGrandSalerTotal', ['result' =>$result,
5017
+            'page'              =>$page,
5018
+            'count'             =>$count,
5019
+            'pages'             =>$pages,                                                                                                   
5020
+            'teamlist'          =>$teamList,                                                                                                   
5021
+            'adminlist'          =>$adminList,                                                                                                   
5022
+            'team_id'          =>$team_id,                                                                                                   
5023
+            'admin_id'          =>$admin_id,                                                                                                   
5024
+            'stime'          =>$stime,                                                                                                   
5025
+            'etime'          =>$etime,                                                                                                   
5026
+            ]);
5027
+    }
5028
+
5029
+    /**
5030
+     * 每日累计汇总数据导出
5031
+     */
5032
+    public function dayGrandSalerTotal_export(Request $request){
5033
+        $team_id = (int)$request->input('team_id');
5034
+        $admin_id = (int)$request->input('admin_id');
5035
+        $stime = $request->input('stime');
5036
+        $etime = $request->input('etime');
5037
+       
5038
+        $teamArr = DB::table('teams')->lists('name', 'id');
5039
+        $adminArr = DB::table('admin')->lists('realname', 'id');
5040
+        $result = DB::table('day_grand_saler_total')->where(function($query) use($team_id, $stime, $etime, $admin_id){
5041
+            if($team_id) $query->where('team_id', $team_id);
5042
+            if($admin_id) $query->where('admin_id', $admin_id);
5043
+            if($stime) $query->where('idate', '>=', $stime);
5044
+            if($etime) $query->where('idate', '<=', $etime);
5045
+        })->orderBy('idate', 'desc')->get();
5046
+        $result = json_decode(json_encode($result), true);
5047
+        foreach($result as $k=>&$v){
5048
+            $v['roi'] = $v['throw_cost']>0 ? round($v['order_amount'] / $v['throw_cost'], 4) * 100 .'%' : '';
5049
+            $v['fugou_rate'] = $v['cust_count']>0 ? round($v['fugou_order_count'] / $v['cust_count'], 4) : '';
5050
+            $v['roi7'] = $v['cost7']>0?  round($v['order_amount7'] / $v['cost7'], 4) * 100 .'%' : '';
5051
+            $v['roi15'] = $v['cost15']>0?  round($v['order_amount15'] / $v['cost15'], 4) * 100 .'%' : '';
5052
+            $v['roi30'] = $v['cost30']>0?  round($v['order_amount30'] / $v['cost30'], 4) * 100 .'%' : '';
5053
+            $v['roi45'] = $v['cost45']>0?  round($v['order_amount45'] / $v['cost45'], 4) * 100 .'%' : '';
5054
+            $v['roi60'] = $v['cost60']>0?  round($v['order_amount60'] / $v['cost60'], 4) * 100 .'%' : '';
5055
+            $v['team_name'] = $teamArr[$v['team_id']];
5056
+            $v['admin_name'] = $adminArr[$v['admin_id']];
5057
+        }
5058
+
5059
+        $indexKey = ['idate','admin_name','team_name','throw_cost','cust_count','order_count','order_amount','goods_cost', 'freight_cost', 'aftersale_cost', 'refund_fee', 'profit', 'roi', 'fan_count', 'new_order_count', 'old_order_count', 'fugou_order_count', 'fugou_rate', 'roi7', 'roi15', 'roi30', 'roi45', 'roi60'];
5060
+        $title = ['汇总日期','销售', '所属团队', '总投放', '总客户数', '总下单数', '总销售额', '总货品成本', '总运费成本', '总售后', '总退补', '总毛利', '累计ROI', '总加粉数', '总新粉单数', '总老粉单数', '总复购单数', '总复购率', '累计7日roi', '累计15日roi', '累计30日roi', '累计45日roi', '累计60日roi'];
5061
+        $filename = 'salerRoi_'.date('Y-m-d_H').'.xlsx';
5062
+        return Order::export_excel($result, $filename, $indexKey, $title); 
5063
+    }
4959 5064
                                                                                 
4960 5065
 }
4961 5066
                                                                           

+ 3 - 0
app/Http/routes.php

@@ -241,6 +241,9 @@ Route::group(['prefix' => 'admin'], function(){
241 241
         Route::get('statistics/dayGrandTeamTotal',   'Admin\StatisticsController@dayGrandTeamTotal');
242 242
         Route::get('statistics/dayGrandTeamTotal_export',   'Admin\StatisticsController@dayGrandTeamTotal_export');
243 243
 
244
+        Route::get('statistics/dayGrandSalerTotal',   'Admin\StatisticsController@dayGrandSalerTotal');
245
+        Route::get('statistics/dayGrandSalerTotal_export',   'Admin\StatisticsController@dayGrandSalerTotal_export');
246
+
244 247
         //充值
245 248
         Route::get('deposit/index', 'Admin\CustomerDepositController@index');  //充值记录
246 249
         Route::get('deposit/consumList', 'Admin\CustomerDepositController@consumList'); //消费记录

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

@@ -152,6 +152,9 @@
152 152
                         <li @if(!isset($res['statistics/volumeRank'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/volumeRank')}}" data-title="近30日商品售卖排行榜" href="javascript:void(0)">近30日商品售卖排行榜</a></li>
153 153
 
154 154
                         <li @if(!isset($res['statistics/dayGrandTeamTotal'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/dayGrandTeamTotal')}}" data-title="团队ROI每日汇总报表" href="javascript:void(0)">团队ROI每日汇总报表</a></li>
155
+
156
+                        <li @if(!isset($res['statistics/dayGrandSalerTotal'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/dayGrandSalerTotal')}}" data-title="销售ROI每日汇总报表" href="javascript:void(0)">销售ROI每日汇总报表</a></li>
157
+                   
155 158
                     </ul>
156 159
                     <ul>
157 160
                         <li @if(!isset($res['statistics/customerOrder'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/customerOrder')}}" data-title="用户订单统计" href="javascript:void(0)">用户订单统计</a></li>

+ 182 - 0
resources/views/statistics/dayGrandSalerTotal.blade.php

@@ -0,0 +1,182 @@
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
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="开始时间"/>
23
+                <input id="stime" type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" class="input-text Wdate" autocomplete="off" style="width:12%;text-align:center;margin-left: -5px" name="stime" value="{{$stime?$stime:''}}">
24
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="结束时间"/>
25
+                <input id="etime"type="text" onfocus="WdatePicker({ dateFmt:'yyyy-MM-dd' })" class="input-text Wdate" autocomplete="off" style="width:12%;text-align:center;margin-left: -5px" name="etime" value="{{$etime?$etime:''}}">
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="4%">汇总日期</th>
38
+                    <th width="4%">销售</th>
39
+                    <th width="4%">所属团队</th>
40
+                    <th width="4%">总投放</th>
41
+                    <th width="4%">总客户数</th>
42
+                    <th width="4%">总下单数</th>                  
43
+                    <th width="4%">总销售额</th>
44
+                    <th width="4%">总货品成本</th>                                                
45
+                    <th width="4%">总运费成本</th>                                                
46
+                    <th width="4%">总售后</th>  
47
+                    <th width="4%">总退补</th>  
48
+                    <th width="4%">总毛利</th>                                                                                            
49
+                    <th width="4%">累计roi</th>                                                                                            
50
+                    <th width="4%">总加粉数</th>                                                                                            
51
+                    <th width="4%">总新粉下单</th>                                                                                            
52
+                    <th width="4%">总老粉下单</th>                                                                                            
53
+                    <th width="4%">总复购单数</th>                                                                                            
54
+                    <th width="4%">总复购率</th>                                                                                            
55
+                    <th width="4%">累计7日roi</th>                                                                                            
56
+                    <th width="4%">累计15日roi</th>                                                                                            
57
+                    <th width="4%">累计30日roi</th>                                                                                            
58
+                    <th width="4%">累计45日roi</th>                                                                                            
59
+                    <th width="4%">累计60日roi</th>                                                                                            
60
+                                             
61
+                </tr>
62
+                </thead>
63
+                <tbody>
64
+                @if($result)
65
+                    @foreach($result as $a)
66
+                        <tr class="text-c" style=" text-align:center;">                                               
67
+                            <td>{{$a['idate']}}</td>                                                                                   
68
+                            <td>{{$a['admin_name']}}</td>                                                                                   
69
+                            <td>{{$a['team_name']}}</td>                                                                                   
70
+                            <td>{{$a['throw_cost']}}</td>                                                                                   
71
+                            <td>{{$a['cust_count']}}</td>                                                                                   
72
+                            <td>{{$a['order_count']}}</td>                                                                                   
73
+                            <td>{{$a['order_amount']}}</td>                                                                                   
74
+                            <td>{{$a['goods_cost']}}</td>                                                                                   
75
+                            <td>{{$a['freight_cost']}}</td>  
76
+                            <td>{{$a['aftersale_cost']}}</td>                                                                                 
77
+                            <td>{{$a['refund_fee']}}</td>                                                                                 
78
+                            <td>{{$a['profit']}}</td>                                                                                   
79
+                            <td>{{$a['roi']}}</td>                                                                                   
80
+                            <td>{{$a['fan_count']}}</td>                                                                                   
81
+                            <td>{{$a['new_order_count']}}</td>                                                                                   
82
+                            <td>{{$a['old_order_count']}}</td>                                                                                   
83
+                            <td>{{$a['fugou_order_count']}}</td>                                                                                   
84
+                            <td>{{$a['fugou_rate']}}</td>                                                                                   
85
+                            <td>{{$a['roi7']}}</td>                                                                                   
86
+                            <td>{{$a['roi15']}}</td>                                                                                   
87
+                            <td>{{$a['roi30']}}</td>                                                                                   
88
+                            <td>{{$a['roi45']}}</td>                                                                                   
89
+                            <td>{{$a['roi60']}}</td>                                                                                   
90
+                           
91
+                        </tr>
92
+                    @endforeach
93
+                @endif
94
+                </tbody>
95
+            </table>
96
+        </div>
97
+        <div id="page" class="page_div"></div>
98
+    </div>
99
+    
100
+    <!--_footer 作为公共模版分离出去-->
101
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
102
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
103
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
104
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
105
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
106
+    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
107
+    <!--/_footer 作为公共模版分离出去-->
108
+    <!--/_footer 作为公共模版分离出去-->
109
+     <script type="text/javascript">
110
+        function user_search(){
111
+            var stime = $('#stime').val();
112
+            var etime = $('#etime').val();
113
+            var team_id = $('#team_id').val();
114
+            var admin_id = $('#admin_id').val();
115
+
116
+            location.href = 'dayGrandSalerTotal?stime='+stime+'&etime='+etime+'&team_id='+team_id+'&admin_id='+admin_id;
117
+        }
118
+        //导出
119
+        function statistics_export(){
120
+            var stime = $('#stime').val();
121
+            var etime = $('#etime').val();
122
+            var team_id = $('#team_id').val();
123
+            var admin_id = $('#admin_id').val();
124
+
125
+            location.href = '/admin/statistics/dayGrandSalerTotal_export?stime='+stime+'&etime='+etime+'&team_id='+team_id+'&admin_id='+admin_id;
126
+        }
127
+       
128
+        /*分页*/
129
+            
130
+        $("#page").paging({
131
+            pageNo:{{$page}},
132
+            totalPage: {{$pages}},
133
+            totalSize: {{$count}},
134
+            callback: function(num) {
135
+                var stime = $('#stime').val();
136
+                var etime = $('#etime').val();
137
+                var team_id = $('#team_id').val();
138
+                var admin_id = $('#admin_id').val();
139
+                
140
+                location.href='dayGrandSalerTotal?page='+num+'&stime='+stime+'&etime='+etime+'&team_id='+team_id+'&admin_id='+admin_id;
141
+            }
142
+        })
143
+
144
+        $(function(){
145
+            getsale();
146
+        })
147
+
148
+        $('#team_id').change(function(){
149
+            getsale();            
150
+        })
151
+
152
+        function getsale(){
153
+            team = $('#team_id').val();
154
+            if(team=='0'){
155
+                return false;
156
+            }else{
157
+                $.ajax({
158
+                    'url':'/admin/order/teamAdmins/'+team,
159
+                    'type': 'get',
160
+                    'dataType':'json',
161
+                    'success' : function(data){
162
+                        admin_id = '{{$admin_id}}';
163
+                        str = '<option value=\'0\'>-- 选择销售 --<\/option>';
164
+                        $.each(data, function(i, va){
165
+                            sele = '';
166
+                            if(va.id == admin_id){
167
+                                sele = 'selected';
168
+                            }
169
+                            str += '<option value="'+va.id+'" '+sele+'>' + va.realname +'<\/option>';
170
+                        })
171
+                        
172
+                        $('#admin_id').html(str);
173
+                    }
174
+                });
175
+            }
176
+        }
177
+        
178
+    </script>
179
+   
180
+    </body>
181
+
182
+@endsection