diff --git a/beike/Admin/Http/Controllers/HomeController.php b/beike/Admin/Http/Controllers/HomeController.php index 8d6514b1..73a9984b 100644 --- a/beike/Admin/Http/Controllers/HomeController.php +++ b/beike/Admin/Http/Controllers/HomeController.php @@ -10,10 +10,10 @@ class HomeController extends Controller public function index() { $data = [ - 'product' => DashboardRepo::getProductData(), - 'order' => DashboardRepo::getOrderData(), - 'customer' => DashboardRepo::getCustomerData(), - 'total' => DashboardRepo::getTotalData(), + 'views' => DashboardRepo::getCustomerViewData(), + 'orders' => DashboardRepo::getOrderData(), + 'customers' => DashboardRepo::getCustomerData(), + 'order_totals' => DashboardRepo::getTotalData(), ]; return view('admin::pages.home', $data); diff --git a/beike/Repositories/DashboardRepo.php b/beike/Repositories/DashboardRepo.php index 871895bf..b626d556 100644 --- a/beike/Repositories/DashboardRepo.php +++ b/beike/Repositories/DashboardRepo.php @@ -31,14 +31,15 @@ class DashboardRepo /** - * 获取订单基础统计, 总数和今日昨日比较 - * + * 获取客户访问统计今日昨日比较 * @return array + * @todo + * */ - public static function getOrderData(): array + public static function getCustomerViewData(): array { - $today = OrderRepo::getListBuilder(['start' => today(), 'end' => today()->addDay()])->count(); - $yesterday = OrderRepo::getListBuilder(['start' => today()->subDay(), 'end' => today()])->count(); + $today = 10; + $yesterday = 8; $difference = $today - $yesterday; if ($difference && $yesterday) { $percentage = round(($difference / $yesterday) * 100); @@ -47,21 +48,21 @@ class DashboardRepo } return [ - 'total' => quantity_format(Product::query()->count()), + 'total' => $today, 'percentage' => $percentage, ]; } /** - * 获取客户基础统计, 总数和今日昨日比较 + * 获取订单基础统计, 总数和今日昨日比较 * * @return array */ - public static function getCustomerData(): array + public static function getOrderData(): array { - $today = CustomerRepo::getListBuilder(['start' => today(), 'end' => today()->addDay()])->count(); - $yesterday = CustomerRepo::getListBuilder(['start' => today()->subDay(), 'end' => today()])->count(); + $today = OrderRepo::getListBuilder(['start' => today()->subDay(), 'end' => today()])->count(); + $yesterday = OrderRepo::getListBuilder(['start' => today()->subDays(2), 'end' => today()->subDay()])->count(); $difference = $today - $yesterday; if ($difference && $yesterday) { $percentage = round(($difference / $yesterday) * 100); @@ -70,7 +71,35 @@ class DashboardRepo } return [ - 'total' => quantity_format(Customer::query()->count()), + 'total' => $today, + 'percentage' => $percentage, + 'reports' => [ + 'latest_month' => '', + 'latest_week' => '', + 'latest_year' => '', + ] + ]; + } + + + /** + * 获取客户注册今日昨日比较 + * + * @return array + */ + public static function getCustomerData(): array + { + $today = CustomerRepo::getListBuilder(['start' => today()->subDay(), 'end' => today()])->count(); + $yesterday = CustomerRepo::getListBuilder(['start' => today()->subDays(2), 'end' => today()->subDay()])->count(); + $difference = $today - $yesterday; + if ($difference && $yesterday) { + $percentage = round(($difference / $yesterday) * 100); + } else { + $percentage = 0; + } + + return [ + 'total' => $today, 'percentage' => $percentage, ]; } @@ -83,8 +112,8 @@ class DashboardRepo */ public static function getTotalData(): array { - $today = OrderRepo::getListBuilder(['start' => today(), 'end' => today()->addDay()])->sum('total'); - $yesterday = OrderRepo::getListBuilder(['start' => today()->subDay(), 'end' => today()])->sum('total'); + $today = OrderRepo::getListBuilder(['start' => today()->subDay(), 'end' => today()])->sum('total'); + $yesterday = OrderRepo::getListBuilder(['start' => today()->subDays(2), 'end' => today()->subDay()])->sum('total'); $difference = $today - $yesterday; if ($difference && $yesterday) { $percentage = round(($difference / $yesterday) * 100); @@ -93,7 +122,7 @@ class DashboardRepo } return [ - 'total' => quantity_format(Customer::query()->count()), + 'total' => currency_format($today), 'percentage' => $percentage, ]; } diff --git a/resources/beike/admin/views/pages/home.blade.php b/resources/beike/admin/views/pages/home.blade.php index e4a4e87b..f15d012d 100644 --- a/resources/beike/admin/views/pages/home.blade.php +++ b/resources/beike/admin/views/pages/home.blade.php @@ -18,11 +18,11 @@ {{--
{{ __('admin/dashboard.customer_view') }}
--}}
-
{{ $product['total'] }}
+
{{ $views['total'] }}
{{--
--}}
-
-24 {{ __('admin/dashboard.day_before') }}
+
{{ $views['percentage'] }}% {{ __('admin/dashboard.day_before') }}
@@ -36,11 +36,11 @@ {{--
{{ __('admin/dashboard.order_total') }}
--}}
-
{{ $order['total'] }}
+
{{ $orders['total'] }}
{{--
--}}
-
-21% {{ __('admin/dashboard.day_before') }}
+
{{ $orders['percentage'] }}% {{ __('admin/dashboard.day_before') }}
@@ -54,11 +54,11 @@ {{--
{{ __('admin/dashboard.customer_new') }}
--}}
-
{{ $customer['total'] }}
+
{{ $customers['total'] }}
{{--
--}}
-
+30% {{ __('admin/dashboard.day_before') }}
+
{{ $customers['percentage'] }}% {{ __('admin/dashboard.day_before') }}
@@ -72,11 +72,11 @@ {{--
{{ __('admin/dashboard.order_amount') }}
--}}
-
{{ $total['total'] }}
+
{{ $order_totals['total'] }}
{{--
--}}
-
+140% {{ __('admin/dashboard.day_before') }}
+
{{ $order_totals['percentage'] }}% {{ __('admin/dashboard.day_before') }}
@@ -276,4 +276,4 @@ upDate(ordersChart, labels, data); }); -@endpush \ No newline at end of file +@endpush