From f3962dbc4f1ee7a25cb8c2309d7b02ab459a60f5 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Wed, 6 Dec 2023 12:03:17 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=95=B0=E6=8D=AE=E4=B9=8B=E7=9C=BC-?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E5=95=86=E5=93=81/=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E6=8E=92=E8=A1=8C=EF=BC=8C=E5=9C=B0=E6=96=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/dataview/Order.php | 51 +++++++++++++++++++++++++-- route/api.php | 1 + 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/app/controller/api/dataview/Order.php b/app/controller/api/dataview/Order.php index c8b52a1e..c5b811be 100755 --- a/app/controller/api/dataview/Order.php +++ b/app/controller/api/dataview/Order.php @@ -46,7 +46,7 @@ class Order extends BaseController ->leftJoin('product_order_log og', 'o.order_id = og.order_id') ->leftJoin('merchant m', 'o.mer_id = m.mer_id') ->leftJoin('store_order_product op', 'o.order_id = op.order_id') - ->leftJoin('product_library p', 'op.product_id = p.id') + ->leftJoin('store_product p', 'op.product_id = p.product_id') ->whereDay('og.create_time', $day) ->where('o.paid', 1) ->whereNotNull('o.pay_time'); @@ -288,7 +288,7 @@ class Order extends BaseController ->leftJoin('product_order_log og', 'o.order_id = og.order_id') ->leftJoin('merchant m', 'o.mer_id = m.mer_id') ->leftJoin('store_order_product op', 'o.order_id = op.order_id') - ->leftJoin('product_library p', 'op.product_id = p.id') + ->leftJoin('store_product p', 'op.product_id = p.product_id') ->whereTime('og.create_time', 'between', $timeRange) // whereTime('create_time', 'between', [$a[0],$a[1]]); ->where('o.paid', 1) ->whereNotNull('o.pay_time'); @@ -376,4 +376,51 @@ class Order extends BaseController unset($street); return \app('json')->success(compact('list')); } + + // 平台商品/店铺销量排行 + public function salesRanking() + { + $list = []; + + // 商品销量排行榜 + $productRankingList = Db::name('store_product')->alias('p') + ->field('p.product_id, p.store_name, p.image, COUNT(o.`order_id`) AS total_sales') + ->join('store_order_product op', 'p.product_id = op.product_id') + ->join('store_order o', 'op.order_id = o.order_id') + ->group('p.product_id') + ->order('total_sales DESC') + ->limit(10) + ->select()->toArray(); + + $productRankingTotal = 0; + foreach ($productRankingList as $k => $v) { + $productRankingTotal += $v['total_sales']; + } + + // 店铺销量排行榜 + $merchantRankingList = Db::name('store_order')->alias('o') + ->field('m.`mer_id`, m.`mer_name`, m.mini_banner, COUNT(o.`order_id`) AS total_sales') + ->join('merchant m', 'o.`mer_id` = m.`mer_id`') + ->group('m.mer_id') + ->order('total_sales DESC') + ->limit(10) + ->select()->toArray(); + + $merchantRankingTotal = 0; + foreach ($merchantRankingList as $k => $v) { + $merchantRankingTotal += $v['total_sales']; + } + + // 统计每个镇的商品数 + $townProductCountList = []; + $geoStreetList = Db::name('geo_street')->field('street_name, street_code')->where('area_code',$this->areaCode)->select()->toArray(); + foreach ($geoStreetList as $k => $street) { + $street['product_count'] = Db::name('merchant')->alias('m')->field('p.`product_id`') + ->join('store_product p', 'm.mer_id = p.mer_id') + ->where('m.street_id', $street['street_code']) + ->count(); + $townProductCountList[] = $street; + } + return \app('json')->success(compact('productRankingTotal','productRankingList', 'merchantRankingTotal','merchantRankingList', 'townProductCountList')); + } } \ No newline at end of file diff --git a/route/api.php b/route/api.php index 5e55bc18..cd1f7aa7 100644 --- a/route/api.php +++ b/route/api.php @@ -733,6 +733,7 @@ Route::group('api/', function () { /**---------------------数据之眼可视化大屏api------------------- start */ Route::get('user_merchat_count', 'User/userMerchantCount'); Route::get('order_statistics', 'Order/orderStatistics'); + Route::get('sales_ranking', 'Order/salesRanking'); /**---------------------数据之眼可视化大屏api-------------------- end */