$where = ['recycle_user_id' => Auth::user()->user_id];
$today = [
Carbon::now()->startOfDay(),
Carbon::now()->endOfDay()
];
$seven = [
Carbon::now()->subDays(7),
Carbon::now()->startOfDay(),
];
$month = [
Carbon::now()->subDays(30),
Carbon::now()->startOfDay(),
];
$data = \DB::table('order')->select([
\DB::raw('sum(case when status = "create" then 1 else 0 end) as create_count '),
\DB::raw('sum(case when status = "finish" then 1 else 0 end) as finish_count '),
\DB::raw('sum(case when status = "buyer_cancle" or status = "close" then 1 else 0 end) as cancle_count '),
\DB::raw('sum(case when status = "create" or status = "finish" then 1 else 0 end) as all_count '),
])->where($where)->get()->toArray();
$data = (array)$data[0];
foreach (compact('today', 'seven', 'month') as $name => $between) {
$data[$name] = \App\Models\Order::query()->where($where)->whereNotIn('status', \App\Models\Order::$paymentStatus)->whereBetween('created_at', $between)->sum('amount');
}
return $data;