Browse Source

优化订单数据报表

master
lanzu_qinsheng 5 years ago
parent
commit
2c1fba8da8
  1. 26
      app/Admin/Common/Order.php
  2. 12
      app/Providers/AppServiceProvider.php

26
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])

12
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'));
});
}
}
Loading…
Cancel
Save