Browse Source

团队订单财务

sunhao 5 years ago
parent
commit
d586065696

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

@@ -1651,6 +1651,169 @@ class StatisticsController extends Controller
1651 1651
         $filename = 'district_roi_'.date('Y-m-d_H').'.xlsx';
1652 1652
         return Order::export_excel($result, $filename, $indexKey, $title);
1653 1653
     }
1654
+
1655
+
1656
+    /**
1657
+     * 团队订单财务明细
1658
+     */
1659
+    public function teamFinanceList(Request $request){
1660
+        $team_id = (int)$request->input('team_id');
1661
+        $stime = $request->input('stime');
1662
+        $etime = $request->input('etime');
1663
+        $page = (int)$request->input('page');
1664
+        $pageSize = 20;
1665
+        if($page<=0){
1666
+            $page = 1;
1667
+        }
1668
+        $offset = ($page-1) * $pageSize;
1669
+
1670
+        $count = Order::where(function($query) use($team_id, $stime, $etime){
1671
+            if($team_id) $query->where('team_id', $team_id);
1672
+            if($stime) $query->where('createTime', '>=', $stime);
1673
+            if($etime) $query->where('createTime', '<=', $etime. ' 23:59:59');
1674
+        })->where('is_del', 0)->count();
1675
+        if ($count > 1) {
1676
+            // 总页数
1677
+            $pages = ceil($count/$pageSize);
1678
+        }else{
1679
+            // 总页数
1680
+            $pages = 1;
1681
+        }
1682
+
1683
+        $teams = DB::table('teams')->lists('name', 'id');
1684
+        $result = Order::select('team_id', 'createTime', 'id', 'receivedAmount', 'aftersale_fee', 'refund_price', 'cost', 'freight_cost')->where(function($query) use($team_id, $stime, $etime){
1685
+            if($team_id) $query->where('team_id', $team_id);
1686
+            if($stime) $query->where('createTime', '>=', $stime);
1687
+            if($etime) $query->where('createTime', '<=', $etime. ' 23:59:59');
1688
+        })->where('is_del', 0)->orderBy('team_id', 'asc')->orderBy('createTime','desc')->offset($offset)->limit($pageSize)->get();
1689
+        $result = json_decode(json_encode($result), true);
1690
+        foreach($result as $k=>&$v){
1691
+            $v['team_name'] = $v['team_id']>0 ? $teams[$v['team_id']] : '';;
1692
+            $v['true_amount'] = $v['receivedAmount'] - $v['refund_price'] - $v['aftersale_fee'];
1693
+        }
1694
+
1695
+        $teamList = DB::table('teams')->select('id', 'name')->get();
1696
+        $teamList = json_decode(json_encode($teamList), true);
1697
+
1698
+        return view('/statistics/teamFinanceList',[
1699
+            'result'   =>   $result,
1700
+            'team_id'   =>   $team_id,
1701
+            'stime'   =>   $stime,
1702
+            'etime'   =>   $etime,
1703
+            'page'   =>   $page,
1704
+            'count'   =>   $count,
1705
+            'pages'   =>   $pages,
1706
+            'teamlist'   =>   $teamList,
1707
+        ]);
1708
+    } 
1709
+
1710
+    /**
1711
+     * 团队订单财务汇总列表
1712
+     */
1713
+    public function teamFinanceTotal(Request $request){
1714
+        $team_id = (int)$request->input('team_id');
1715
+        $stime = $request->input('stime');
1716
+        $etime = $request->input('etime');
1717
+        $page = (int)$request->input('page');
1718
+        $pageSize = 20;
1719
+        if($page<=0){
1720
+            $page = 1;
1721
+        }
1722
+        $offset = ($page-1) * $pageSize;
1723
+
1724
+        $count = Order::select(DB::raw('left(createTime, 10) as ctime, team_id'))->where(function($query) use($team_id, $stime, $etime){
1725
+            if($team_id) $query->where('team_id', $team_id);
1726
+            if($stime) $query->where('createTime', '>=', $stime);
1727
+            if($etime) $query->where('createTime', '<=', $etime.' 23:59:59');
1728
+        })->where('is_del', 0)->groupBy('team_id')->groupBy('ctime')->get();
1729
+        $count = count($count);
1730
+        if ($count > 1) {
1731
+            // 总页数
1732
+            $pages = ceil($count/$pageSize);
1733
+        }else{
1734
+            // 总页数
1735
+            $pages = 1;
1736
+        }
1737
+
1738
+        $teams = DB::table('teams')->lists('name', 'id');
1739
+        $result = Order::select(DB::raw('left(createTime, 10) as ctime, team_id, count(1) as order_count, sum(receivedAmount) as receivedAmount, sum(aftersale_fee) as aftersale_fee, sum(refund_price) as refund_price, sum(cost) as cost, sum(freight_cost) as freight_cost'))->where(function($query) use($team_id, $stime, $etime){
1740
+            if($team_id) $query->where('team_id', $team_id);
1741
+            if($stime) $query->where('createTime', '>=', $stime);
1742
+            if($etime) $query->where('createTime', '<=', $etime.' 23:59:59');
1743
+        })->where('is_del', 0)->groupBy('team_id')->groupBy('ctime')->orderBy('team_id', 'asc')->orderBy('createTime','desc')->offset($offset)->limit($pageSize)->get();
1744
+        $result = json_decode(json_encode($result), true);
1745
+        foreach($result as $k=>&$v){
1746
+            $v['team_name'] = $v['team_id']>0 ? $teams[$v['team_id']] : '';
1747
+            $v['true_amount'] = $v['receivedAmount'] - $v['refund_price'] - $v['aftersale_fee'];
1748
+        }
1749
+
1750
+        $teamList = DB::table('teams')->select('id', 'name')->get();
1751
+        $teamList = json_decode(json_encode($teamList), true);
1752
+        return view('/statistics/teamFinanceTotal',[
1753
+            'result'   =>   $result,
1754
+            'team_id'   =>   $team_id,
1755
+            'stime'   =>   $stime,
1756
+            'etime'   =>   $etime,
1757
+            'page'   =>   $page,
1758
+            'count'   =>   $count,
1759
+            'pages'   =>   $pages,
1760
+            'teamlist'   =>   $teamList,
1761
+        ]);
1762
+
1763
+    }
1764
+
1765
+    /**
1766
+     * 团队财务明细导出
1767
+     */
1768
+    public function teamFinanceList_export(Request $request){
1769
+        $team_id = (int)$request->input('team_id');
1770
+        $stime = $request->input('stime');
1771
+        $etime = $request->input('etime');
1772
+       
1773
+        $teams = DB::table('teams')->lists('name', 'id');
1774
+        $result = Order::select('team_id', 'createTime', 'id', 'receivedAmount', 'aftersale_fee', 'refund_price', 'cost', 'freight_cost')->where(function($query) use($team_id, $stime, $etime){
1775
+            if($team_id) $query->where('team_id', $team_id);
1776
+            if($stime) $query->where('createTime', '>=', $stime);
1777
+            if($etime) $query->where('createTime', '<=', $etime. ' 23:59:59');
1778
+        })->where('is_del', 0)->orderBy('team_id', 'asc')->orderBy('createTime','desc')->get();
1779
+        $result = json_decode(json_encode($result), true);
1780
+        foreach($result as $k=>&$v){
1781
+            $v['team_name'] = $v['team_id']>0 ? $teams[$v['team_id']] : '';;
1782
+            $v['true_amount'] = $v['receivedAmount'] - $v['refund_price'] - $v['aftersale_fee'];
1783
+        }
1784
+
1785
+        $indexKey = ['team_name','createTime','id','receivedAmount','aftersale_fee','refund_price','true_amount','cost','freight_cost'];
1786
+        $title = ['团队', '时间', '订单编号', '成交金额', '售后', '退补差价', '实际金额', '供应商成本', '物流成本'];
1787
+        $filename = 'teamFinanceList_'.date('Y-m-d_H').'.xlsx';
1788
+        return Order::export_excel($result, $filename, $indexKey, $title);
1789
+    }
1790
+
1791
+    /**
1792
+     * 团队财务明细导出
1793
+     */
1794
+    public function teamFinanceTotal_export(Request $request){
1795
+        $team_id = (int)$request->input('team_id');
1796
+        $stime = $request->input('stime');
1797
+        $etime = $request->input('etime');
1798
+       
1799
+        $teams = DB::table('teams')->lists('name', 'id');
1800
+        $result = Order::select(DB::raw('left(createTime, 10) as ctime, team_id, count(1) as order_count, sum(receivedAmount) as receivedAmount, sum(aftersale_fee) as aftersale_fee, sum(refund_price) as refund_price, sum(cost) as cost, sum(freight_cost) as freight_cost'))->where(function($query) use($team_id, $stime, $etime){
1801
+            if($team_id) $query->where('team_id', $team_id);
1802
+            if($stime) $query->where('createTime', '>=', $stime);
1803
+            if($etime) $query->where('createTime', '<=', $etime.' 23:59:59');
1804
+        })->where('is_del', 0)->groupBy('team_id')->groupBy('ctime')->orderBy('team_id', 'asc')->orderBy('createTime','desc')->get();
1805
+        $result = json_decode(json_encode($result), true);
1806
+        foreach($result as $k=>&$v){
1807
+            $v['team_name'] = $v['team_id']>0 ? $teams[$v['team_id']] : '';
1808
+            $v['true_amount'] = $v['receivedAmount'] - $v['refund_price'] - $v['aftersale_fee'];
1809
+        }
1810
+
1811
+        $indexKey = ['team_name','ctime','order_count','receivedAmount','aftersale_fee','refund_price','true_amount','cost','freight_cost'];
1812
+        $title = ['团队', '时间', '总单数', '成交金额', '售后', '退补差价', '实际金额', '供应商成本', '物流成本'];
1813
+        $filename = 'teamFinanceTotal_'.date('Y-m-d_H').'.xlsx';
1814
+        return Order::export_excel($result, $filename, $indexKey, $title);
1815
+    }
1654 1816
 }
1655 1817
 
1656 1818
 
1819
+

+ 5 - 0
app/Http/routes.php

@@ -125,6 +125,11 @@ Route::group(['prefix' => 'admin'], function(){
125 125
         Route::get('/statistics/districtRoi', 'Admin\StatisticsController@districtRoi');
126 126
         //地域roi导出
127 127
         Route::get('/statistics/districtRoi_export', 'Admin\StatisticsController@districtRoi_export');
128
+        //团队财务报表
129
+        Route::get('/statistics/teamFinanceList', 'Admin\StatisticsController@teamFinanceList');
130
+        Route::get('/statistics/teamFinanceList_export', 'Admin\StatisticsController@teamFinanceList_export');
131
+        Route::get('/statistics/teamFinanceTotal', 'Admin\StatisticsController@teamFinanceTotal');
132
+        Route::get('/statistics/teamFinanceTotal_export', 'Admin\StatisticsController@teamFinanceTotal_export');
128 133
 
129 134
     });
130 135
     

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

@@ -113,6 +113,12 @@
113 113
                     <ul>                       
114 114
                         <li @if(!isset($res['statistics/districtRoi'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/districtRoi')}}" data-title="地域ROI统计" href="javascript:void(0)">地域ROI统计</a></li>                        
115 115
                     </ul>
116
+                    <ul>                       
117
+                        <li @if(!isset($res['statistics/teamFinanceList'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/teamFinanceList')}}" data-title="团队订单财务明细" href="javascript:void(0)">团队订单财务明细</a></li>                        
118
+                    </ul>
119
+                    <ul>                       
120
+                        <li @if(!isset($res['statistics/teamFinanceTotal'])) style="display:none;list-style-type:none;" @endif><a data-href="{{url('admin/statistics/teamFinanceTotal')}}" data-title="团队订单财务汇总" href="javascript:void(0)">团队订单财务汇总</a></li>                        
121
+                    </ul>
116 122
                    
117 123
                 </dd>
118 124
             </dl>

+ 106 - 0
resources/views/statistics/teamFinanceList.blade.php

@@ -0,0 +1,106 @@
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
+                <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:''}}">
16
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="结束时间"/>
17
+                <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:''}}">
18
+                              
19
+                <a class="btn btn-primary radius"  style="margin-left: 5px" onclick="user_search()" href="javascript:;">搜索</a>
20
+                <a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont"></i> 导出数据</a>
21
+                
22
+            </div>
23
+        </div>
24
+        
25
+        <div class="mt-20">
26
+            <table class="table table-border table-bordered table-bg table-hover table-sort">
27
+                <thead>
28
+                <tr class="text-c">
29
+                    <th width="5%">团队</th>
30
+                    <th width="5%">时间</th>
31
+                    <th width="5%">订单编号</th>
32
+                    <th width="5%">成交金额</th>
33
+                    <th width="5%">售后</th>
34
+                    <th width="5%">退补差价</th>
35
+                    <th width="5%">实际金额</th>
36
+                    <th width="5%">供应商成本</th>
37
+                    <th width="5%">物流成本</th>                                                
38
+                </tr>
39
+                </thead>
40
+                <tbody>
41
+                @if($result)
42
+                    @foreach($result as $a)
43
+                        <tr class="text-c" style=" text-align:center;">                           
44
+                            <td>{{$a['team_name']}}</td>                            
45
+                            <td>{{$a['createTime']}}</td>
46
+                            <td>{{$a['id']}}</td>
47
+                            <td>{{$a['receivedAmount']}}</td>
48
+                            <td>{{$a['aftersale_fee']}}</td>
49
+                            <td>{{$a['refund_price']}}</td>
50
+                            <td>{{$a['true_amount']}}</td>
51
+                            <td>{{$a['cost']}}</td>
52
+                            <td>{{$a['freight_cost']}}</td>
53
+
54
+                        </tr>
55
+                    @endforeach
56
+                @endif
57
+                </tbody>
58
+            </table>
59
+        </div>
60
+        <div id="page" class="page_div"></div>
61
+    </div>
62
+    
63
+    <!--_footer 作为公共模版分离出去-->
64
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
65
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
66
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
67
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
68
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
69
+    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
70
+    <!--/_footer 作为公共模版分离出去-->
71
+    <!--/_footer 作为公共模版分离出去-->
72
+     <script type="text/javascript">
73
+        function user_search(){
74
+            var stime = $('#stime').val();
75
+            var etime = $('#etime').val();
76
+            var team_id = $('#team_id').val();
77
+            //var page = {{$page}};
78
+            location.href = 'teamFinanceList?stime='+stime+'&etime='+etime+'&team_id='+team_id;
79
+        }
80
+        //导出
81
+        function statistics_export(){
82
+            var stime = $('#stime').val();
83
+            var etime = $('#etime').val();
84
+            var team_id = $('#team_id').val();
85
+            location.href = '/admin/statistics/teamFinanceList_export?stime='+stime+'&etime='+etime+'&team_id='+team_id;
86
+        }
87
+       
88
+        /*分页*/
89
+            
90
+        $("#page").paging({
91
+            pageNo:{{$page}},
92
+            totalPage: {{$pages}},
93
+            totalSize: {{$count}},
94
+            callback: function(num) {
95
+                var stime = $('#stime').val();
96
+                var etime = $('#etime').val();
97
+                var team_id = $('#team_id').val();
98
+                location.href='teamFinanceList?page='+num+'&stime='+stime+'&etime='+etime+'&team_id='+team_id;
99
+            }
100
+        })
101
+        
102
+    </script>
103
+   
104
+    </body>
105
+
106
+@endsection

+ 106 - 0
resources/views/statistics/teamFinanceTotal.blade.php

@@ -0,0 +1,106 @@
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
+                <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:''}}">
16
+                <input class="input-text" style="width:6%;text-align:center" type="text" value="结束时间"/>
17
+                <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:''}}">
18
+                              
19
+                <a class="btn btn-primary radius"  style="margin-left: 5px" onclick="user_search()" href="javascript:;">搜索</a>
20
+                <a class="btn btn-primary radius" onclick="statistics_export()" href="javascript:;"><i class="Hui-iconfont"></i> 导出数据</a>
21
+                
22
+            </div>
23
+        </div>
24
+        
25
+        <div class="mt-20">
26
+            <table class="table table-border table-bordered table-bg table-hover table-sort">
27
+                <thead>
28
+                <tr class="text-c">
29
+                    <th width="5%">团队</th>
30
+                    <th width="5%">时间</th>
31
+                    <th width="5%">总单数</th>
32
+                    <th width="5%">成交金额</th>
33
+                    <th width="5%">售后</th>
34
+                    <th width="5%">退补差价</th>
35
+                    <th width="5%">实际金额</th>
36
+                    <th width="5%">供应商成本</th>
37
+                    <th width="5%">物流成本</th>                                                
38
+                </tr>
39
+                </thead>
40
+                <tbody>
41
+                @if($result)
42
+                    @foreach($result as $a)
43
+                        <tr class="text-c" style=" text-align:center;">                           
44
+                            <td>{{$a['team_name']}}</td>                            
45
+                            <td>{{$a['ctime']}}</td>
46
+                            <td>{{$a['order_count']}}</td>
47
+                            <td>{{$a['receivedAmount']}}</td>
48
+                            <td>{{$a['aftersale_fee']}}</td>
49
+                            <td>{{$a['refund_price']}}</td>
50
+                            <td>{{$a['true_amount']}}</td>
51
+                            <td>{{$a['cost']}}</td>
52
+                            <td>{{$a['freight_cost']}}</td>
53
+
54
+                        </tr>
55
+                    @endforeach
56
+                @endif
57
+                </tbody>
58
+            </table>
59
+        </div>
60
+        <div id="page" class="page_div"></div>
61
+    </div>
62
+    
63
+    <!--_footer 作为公共模版分离出去-->
64
+    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
65
+    <script type="text/javascript" src="/admin/lib/layer/2.4/layer.js"></script>
66
+    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
67
+    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
68
+    <script type="text/javascript" src="/admin/lib/page/paging.js"></script>
69
+    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
70
+    <!--/_footer 作为公共模版分离出去-->
71
+    <!--/_footer 作为公共模版分离出去-->
72
+     <script type="text/javascript">
73
+        function user_search(){
74
+            var stime = $('#stime').val();
75
+            var etime = $('#etime').val();
76
+            var team_id = $('#team_id').val();
77
+            //var page = {{$page}};
78
+            location.href = 'teamFinanceTotal?stime='+stime+'&etime='+etime+'&team_id='+team_id;
79
+        }
80
+        //导出
81
+        function statistics_export(){
82
+            var stime = $('#stime').val();
83
+            var etime = $('#etime').val();
84
+            var team_id = $('#team_id').val();
85
+            location.href = '/admin/statistics/teamFinanceTotal_export?stime='+stime+'&etime='+etime+'&team_id='+team_id;
86
+        }
87
+       
88
+        /*分页*/
89
+            
90
+        $("#page").paging({
91
+            pageNo:{{$page}},
92
+            totalPage: {{$pages}},
93
+            totalSize: {{$count}},
94
+            callback: function(num) {
95
+                var stime = $('#stime').val();
96
+                var etime = $('#etime').val();
97
+                var team_id = $('#team_id').val();
98
+                location.href='teamFinanceTotal?page='+num+'&stime='+stime+'&etime='+etime+'&team_id='+team_id;
99
+            }
100
+        })
101
+        
102
+    </script>
103
+   
104
+    </body>
105
+
106
+@endsection