xieruidong 2 年之前
父节点
当前提交
dd39b203ad

+ 29 - 0
application/admin/controller/Goods.php

@@ -268,4 +268,33 @@ class Goods extends Backend
         }
         return $this->view->fetch();
     }
+    #订单金额排序
+    public function order_amount_rank($ids){
+        $row=$this->model->find($ids);
+        //当前是否为关联查询
+        $this->relationSearch = false;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+
+            $list=\app\admin\model\Orders::payed()
+                ->hasGoods($row['id'])
+                ->field('user_id,SUM(amount_pay) as amount,order_no')
+                ->order('amount','desc')
+                ->paginate($limit);
+
+            $userNames=User::whereIn('id',array_column($list->items(),'user_id'))->column('nickname','id');
+            $index=$list->listRows()*$list->currentPage()-$list->listRows();
+            foreach ($list as $idx=>$item){
+                $item['nickname']=$userNames[$item['user_id']]??'-';
+                $item['rank']=$index+$idx+1;
+            }
+
+            $result = array("total" => $list->total(), "rows" => $list->items());
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
 }

+ 1 - 5
application/admin/view/goods/goods_buy_rank.html

@@ -14,8 +14,4 @@
 
         </div>
     </div>
-</div>
-<script>
-    var goodsStatus={:json_encode($status)};
-    var category={:json_encode(array_column($category,'name','id'))};
-</script>
+</div>

+ 1 - 0
application/admin/view/goods/index.html

@@ -25,6 +25,7 @@
                            data-operate-edit="{:$auth->check('goods/edit')}" 
                            data-operate-del="{:$auth->check('goods/del')}" 
                            data-operate-buy_rank="{:$auth->check('goods/goods_buy_rank')}"
+                           data-operate-order_amount_rank="{:$auth->check('goods/order_amount_rank')}"
                            data-operate-bind_goods="{:$auth->check('goods/bind_goods')}"
                            width="100%">
                     </table>

+ 17 - 0
application/admin/view/goods/order_amount_rank.html

@@ -0,0 +1,17 @@
+<div class="panel panel-default panel-intro">
+    <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">
+                    <div id="toolbar" class="toolbar">
+                        <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 6 - 0
application/common/model/Orders.php

@@ -12,6 +12,7 @@ use Yansongda\Supports\Arr;
  * @property bool is_wait_pay
  * @property Payment payment
  * @method static static payed()
+ * @method static hasGoods($goods_id)
  */
 class Orders extends Model
 {
@@ -260,6 +261,11 @@ class Orders extends Model
     public function scopePayed(Query $query){
         $query->whereNotIn('status',[self::S_CANCEL,self::S_WAIT_PAY]);
     }
+    public function scopeHasGoods(Query $query,$goods_id){
+        $query->whereExists(
+            OrderInfo::whereRaw("orders.id=order_info.order_id and order_info.goods_id={$goods_id}")->buildSql()
+        );
+    }
 
 
 

+ 39 - 6
public/assets/js/backend/goods.js

@@ -14,6 +14,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     bind_url: 'goods/bind_goods',
                     statistics_url: 'goods/goods_statistics',
                     amount_rank_url: 'goods/goods_buy_rank',
+                    order_amount_rank_url: 'goods/order_amount_rank',
                     table: 'goods',
                 }
             });
@@ -83,6 +84,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                         return table.data('operate-buy_rank');
                                     }
                                 },
+                                {
+                                    name: 'detail',
+                                    text: __('订单金额排名'),
+                                    title: __('订单金额排名'),
+                                    classname: 'btn btn-xs btn-info btn-dialog',
+                                    icon: 'fa',
+                                    url: extend.order_amount_rank_url,
+                                    extend:`data-area='["800px","80%"]'`,
+                                    callback: function (data) {
+                                    },
+                                    visible: function (row) {
+                                        return table.data('operate-order_amount_rank');
+                                    }
+                                },
                             ]}
                     ]
                 ],
@@ -134,12 +149,30 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'nickname', title: __('用户名')},
                         {field: 'amount', title: __('金额')},
                     ]
-                ],
-                onLoadSuccess(){
-                    setTimeout(()=>{
-                        $('.btn-editone').attr('data-area','["100%","100%"]')
-                    },100)
-                }
+                ]
+            });
+            Table.api.bindevent(table);
+        },
+        order_amount_rank(){
+            Table.api.init()
+            var table = $("#table");
+            // 初始化表格
+            table.bootstrapTable({
+                url: location.href,
+                pk: 'id',
+                sortName: 'id',
+                searchFormVisible:false,
+                showExport:false,
+                commonSearch:false,
+                search:false,
+                columns: [
+                    [
+                        {field: 'rank', title: __('排名')},
+                        {field: 'order_no', title: __('订单号')},
+                        {field: 'nickname', title: __('用户名')},
+                        {field: 'amount', title: __('金额')},
+                    ]
+                ]
             });
             Table.api.bindevent(table);
         },