From 2c1fba8da8e1ebf8361131494e0655a255c3f223 Mon Sep 17 00:00:00 2001 From: lanzu_qinsheng <334039090@qq.com> Date: Fri, 23 Oct 2020 16:03:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=A2=E5=8D=95=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=8A=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Common/Order.php | 26 ++++++++++++-------------- app/Providers/AppServiceProvider.php | 12 ++++++------ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/app/Admin/Common/Order.php b/app/Admin/Common/Order.php index 674a3ec..fd0dc3b 100644 --- a/app/Admin/Common/Order.php +++ b/app/Admin/Common/Order.php @@ -59,21 +59,19 @@ class Order }elseif ($params['data_type']=='amount'){//订单金额 $result = $buildData->sum('money'); }elseif ($params['data_type']=='shipping'){//配送方式 - $build1 = clone $buildData; - $build3 = clone $buildData; - $s1 = $build1->where('shipping_type',1)->count(); - $s3 = $build3->where('shipping_type',3)->count(); - $result = [$s1,$s3]; + $data = $buildData->selectRaw("count(*) as shipping,shipping_type")->whereIn('shipping_type',[1,3])->groupBy('shipping_type')->orderBy('shipping_type')->get()->toArray(); + + $result[0] = isset($data[0]['shipping'])&&($data[0]['shipping_type']=='1')?$data[0]['shipping']:0; + $result[1] = isset($data[1]['shipping'])&&($data[1]['shipping_type']=='3')?$data[1]['shipping']:0; }elseif ($params['data_type']=='distance'){ - $build1 = clone $buildData; - $build2 = clone $buildData; - $build3 = clone $buildData; - $build4 = clone $buildData; - $d1 = $build1->where('delivery_distance','<',1000)->count(); - $d2 = $build2->whereBetween('delivery_distance',[1000,3000])->count(); - $d3 = $build3->whereBetween('delivery_distance',[3000,5000])->count(); - $d4 = $build4->where('delivery_distance','>',5000)->count(); - $result = [$d1,$d2,$d3,$d4]; + $data = $buildData->selectRaw( + "ELT(INTERVAL(lanzu_order_main.delivery_distance,0,1000,3000,5000),'d1','d2','d3','d4') as delivery,count(lanzu_order_main.id) as num" + )->groupBy('delivery')->orderBy('delivery')->get()->toArray(); + + $result[0] = isset($data[0]['delivery'])&&($data[0]['delivery']=='d1')?$data[0]['num']:0; + $result[1] = isset($data[1]['delivery'])&&($data[1]['delivery']=='d2')?$data[1]['num']:0; + $result[2] = isset($data[2]['delivery'])&&($data[2]['delivery']=='d3')?$data[2]['num']:0; + $result[3] = isset($data[3]['delivery'])&&($data[3]['delivery']=='d4')?$data[3]['num']:0; }elseif ($params['data_type']=='order_count_user'){ $result = DB::table('lanzu_order_main') ->whereIn('state', [3, 4, 5, 10,11]) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index a888501..b89cb42 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -27,11 +27,11 @@ class AppServiceProvider extends ServiceProvider { // \Schema::defaultStringLength(191); -// DB::listen(function($query){ -// $sql = $query->sql; -// $bingings = $query->bindings; -// $time = $query->time; -// Log::debug(compact('sql','bingings','time')); -// }); + DB::listen(function($query){ + $sql = $query->sql; + $bingings = $query->bindings; + $time = $query->time; + Log::debug(compact('sql','bingings','time')); + }); } }