xieruidong 2 years ago
parent
commit
154366e5ee

+ 35 - 0
application/admin/controller/seller/MyTeam.php

@@ -69,4 +69,39 @@ class MyTeam extends Backend
         $this->assign('sale',$sale);
         return $this->fetch();
     }
+    public function order_num_amount_rank(){
+        list($date,$dateArr)=$this->rangeTime('date');
+        if($this->request->isAjax()){
+            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+            $type=input('type',1);
+            if($type==1){
+                $list=Orders::filterDate($dateArr)
+                    ->where('admin_id',$this->admin('id'))
+                    ->group('user_id')
+                    ->field('count(id) as num,user_id')
+                    ->order('num','desc')
+                    ->paginate(1000000);
+            }else{
+                $list=Orders::filterDate($dateArr)
+                    ->where('admin_id',$this->admin('id'))
+                    ->group('user_id')
+                    ->field('sum(amount_pay) as num,user_id')
+                    ->order('num','desc')
+                    ->paginate(1000000);
+            }
+            $all=0;
+            foreach ($list as $k=>&$item){
+                $item['nickname']=\app\admin\model\User::where('id',$item['user_id'])->value('nickname');
+                $all+=$item['num'];
+            }
+            $this->addRank($list);
+            return json([
+                'rows'=>$list->items(),
+                'total'=>$list->total(),
+                'all'=>$all,
+            ]);
+        }
+        $this->assign('date',$date);
+        return $this->fetch();
+    }
 }

+ 51 - 0
application/admin/view/seller/my_team/order_num_amount_rank.html

@@ -0,0 +1,51 @@
+<style>
+    .content{
+        background: white;
+    }
+    #charts1,#charts2{
+        display: inline-block;
+        width: 48%;
+        height: 500px;
+    }
+</style>
+<form class="form-inline form" role="form">
+    <div class="form-group">
+        <label for="time">时间段</label>
+        <input type="text" name="date" value="{$date}" class="form-control datetimerange" id="time" placeholder="选择时间" style="width: 300px;">
+    </div>
+    <div class="form-group" style="text-align: right">
+        <button type="submit" class="btn btn-primary doSearch">确定</button>
+    </div>
+    <input type="hidden" name="dialog" value="{:input('dialog')}">
+</form>
+<div style="margin: 20px 0;">
+    <div id="charts1"></div>
+    <div id="charts2"></div>
+</div>
+<div class="col-md-12">
+    <div class="panel panel-default panel-intro panel-nav">
+        <div class="panel-heading">
+            <ul class="nav nav-tabs">
+                <li class="active"><a href="#one" data-toggle="tab"><i class="fa fa-magic"></i> 用户订单量排名</a></li>
+                <li><a href="#two" data-toggle="tab"><i class="fa fa-search"></i> 用户总金额排名</a></li>
+            </ul>
+        </div>
+        <div class="panel-body">
+            <div id="myTabContent" class="tab-content">
+                <div class="tab-pane fade active in" id="one">
+                    <div class="widget-body no-padding">
+                        <table id="table" class="table table-striped table-bordered table-hover table-nowrap" width="100%"></table>
+                    </div>
+                </div>
+                <div class="tab-pane fade in" id="two">
+                    <div class="widget-body no-padding">
+                        <table id="table1" class="table table-striped table-bordered table-hover table-nowrap" width="100%"></table>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script>
+    let defDate='{$date}';
+</script>

+ 9 - 0
application/common/controller/Backend.php

@@ -635,4 +635,13 @@ class Backend extends Controller
         $timeArr[1]=strtotime($timeArr[1]);
         return [$time,$timeArr];
     }
+    protected function addRank(&$list){
+        $offset=input('offset',0);
+        $limit=input('limit',20);
+        $page=$offset/$limit+1;
+        $index=$list->listRows()*$list->currentPage()-$list->listRows();
+        foreach ($list as $idx=>&$item){
+            $item['rank']=$index+$idx+1;
+        }
+    }
 }

+ 113 - 0
public/assets/js/backend/seller/my_team.js

@@ -117,5 +117,118 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echart
         profit_static() {
             Form.events.daterangepicker($('.form'))
         },
+        order_num_amount_rank(){
+            Form.events.daterangepicker($('.form'))
+            Table.api.init()
+            var table = $("#table");
+            var table1 = $("#table1");
+            // 初始化表格
+            table.bootstrapTable({
+                url: location.href+'&type=1',
+                pk: 'id',
+                sortName: 'id',
+                searchFormVisible: false,
+                showExport: true,
+                commonSearch: false,
+                search: false,
+                columns: [
+                    [
+                        {field: 'rank', title: __('排名'), operate: false,},
+                        {field: 'nickname', title: __('用户名'), operate: false,},
+                        {field: 'num', title: __('数量'), operate: false,},
+                    ]
+                ],
+                onLoadSuccess(row){
+                    let a=Echarts.init(document.getElementById('charts1'))
+                    let items=[]
+                    row.rows.forEach(item=>{
+                        items.push({value:item.num,name:item.nickname})
+                    })
+                    console.log(items)
+                    a.setOption({
+                        title: {
+                            text: '用户订单量排名',
+                            left: 'center'
+                        },
+                        tooltip: {
+                            trigger: 'item'
+                        },
+                        legend: {
+                            orient: 'vertical',
+                            left: 'left'
+                        },
+                        series: [
+                            {
+                                name: '品类',
+                                type: 'pie',
+                                radius: '50%',
+                                data: items,
+                                emphasis: {
+                                    itemStyle: {
+                                        shadowBlur: 10,
+                                        shadowOffsetX: 0,
+                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
+                                    }
+                                }
+                            }
+                        ]
+                    })
+                }
+            });
+            table1.bootstrapTable({
+                url: location.href+'&type=2',
+                pk: 'id',
+                sortName: 'id',
+                searchFormVisible: false,
+                showExport: true,
+                commonSearch: false,
+                search: false,
+                columns: [
+                    [
+                        {field: 'rank', title: __('排名'), operate: false,},
+                        {field: 'nickname', title: __('用户名'), operate: false,},
+                        {field: 'num', title: __('金额'), operate: false,},
+                    ]
+                ],
+                onLoadSuccess(row){
+                    let a=Echarts.init(document.getElementById('charts2'))
+                    let items=[]
+                    row.rows.forEach(item=>{
+                        items.push({value:item.num,name:item.nickname})
+                    })
+                    console.log(items)
+                    a.setOption({
+                        title: {
+                            text: '用户订单金额排名',
+                            left: 'center'
+                        },
+                        tooltip: {
+                            trigger: 'item'
+                        },
+                        legend: {
+                            orient: 'vertical',
+                            left: 'left'
+                        },
+                        series: [
+                            {
+                                name: '品类',
+                                type: 'pie',
+                                radius: '50%',
+                                data: items,
+                                emphasis: {
+                                    itemStyle: {
+                                        shadowBlur: 10,
+                                        shadowOffsetX: 0,
+                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
+                                    }
+                                }
+                            }
+                        ]
+                    })
+                }
+            });
+            Table.api.bindevent(table);
+            Table.api.bindevent(table1);
+        }
     };
 });