diff --git a/beike/Admin/Http/Controllers/HomeController.php b/beike/Admin/Http/Controllers/HomeController.php index 1f6f55cb..ca35f378 100644 --- a/beike/Admin/Http/Controllers/HomeController.php +++ b/beike/Admin/Http/Controllers/HomeController.php @@ -11,7 +11,8 @@ class HomeController extends Controller public function index() { $data = [ - 'views' => DashboardRepo::getCustomerViewData(), + 'products' => DashboardRepo::getProductData(), + // 'views' => DashboardRepo::getCustomerViewData(), 'orders' => DashboardRepo::getOrderData(), 'customers' => DashboardRepo::getCustomerData(), 'order_totals' => DashboardRepo::getTotalData(), diff --git a/beike/Admin/Repositories/DashboardRepo.php b/beike/Admin/Repositories/DashboardRepo.php index a963e354..8d5d598e 100644 --- a/beike/Admin/Repositories/DashboardRepo.php +++ b/beike/Admin/Repositories/DashboardRepo.php @@ -11,9 +11,9 @@ namespace Beike\Admin\Repositories; -use Beike\Models\Product; use Beike\Repositories\CustomerRepo; use Beike\Repositories\OrderRepo; +use Beike\Repositories\ProductRepo; class DashboardRepo { @@ -21,12 +21,22 @@ class DashboardRepo * 获取商品总数 * * @return array + * @throws \Exception */ public static function getProductData(): array { + $today = ProductRepo::getBuilder(['created_start' => today()->subDay(), 'created_end' => today()])->count(); + $yesterday = ProductRepo::getBuilder(['created_start' => today()->subDays(2), 'created_end' => today()->subDay()])->count(); + $difference = $today - $yesterday; + if ($difference && $yesterday) { + $percentage = round(($difference / $yesterday) * 100); + } else { + $percentage = 0; + } + return [ - 'total' => quantity_format(Product::query()->count()), - 'percentage' => 0, + 'total' => $today, + 'percentage' => $percentage, ]; } diff --git a/beike/Repositories/ProductRepo.php b/beike/Repositories/ProductRepo.php index 8cf4feb2..ebc044fb 100644 --- a/beike/Repositories/ProductRepo.php +++ b/beike/Repositories/ProductRepo.php @@ -55,7 +55,7 @@ class ProductRepo */ public static function getProductsByCategory($categoryId, $filterData) { - $builder = self::getBuilder(array_merge(['category_id' => $categoryId, 'active' => 1], $filterData)); + $builder = self::getBuilder(array_merge(['category_id' => $categoryId, 'active' => 1], $filterData)); return $builder->with('inCurrentWishlist') ->paginate($filterData['per_page'] ?? perPage()) @@ -81,10 +81,11 @@ class ProductRepo /** * 获取商品筛选对象 * - * @param array $data + * @param array $filters * @return Builder + * @throws \Exception */ - public static function getBuilder(array $data = []): Builder + public static function getBuilder(array $filters = []): Builder { $builder = Product::query()->with('description', 'skus', 'masterSku', 'attributes'); @@ -98,17 +99,17 @@ class ProductRepo }); $builder->select(['products.*', 'pd.name', 'pd.content', 'pd.meta_title', 'pd.meta_description', 'pd.meta_keywords', 'pd.name', 'product_skus.price']); - if (isset($data['category_id'])) { - $builder->whereHas('categories', function ($query) use ($data) { - if (is_array($data['category_id'])) { - $query->whereIn('category_id', $data['category_id']); + if (isset($filters['category_id'])) { + $builder->whereHas('categories', function ($query) use ($filters) { + if (is_array($filters['category_id'])) { + $query->whereIn('category_id', $filters['category_id']); } else { - $query->where('category_id', $data['category_id']); + $query->where('category_id', $filters['category_id']); } }); } - $productIds = $data['product_ids'] ?? []; + $productIds = $filters['product_ids'] ?? []; if ($productIds) { $builder->whereIn('products.id', $productIds); $productIds = implode(',', $productIds); @@ -116,8 +117,8 @@ class ProductRepo } // attr 格式:attr=10:10,13|11:34,23|3:4 - if (isset($data['attr']) && $data['attr']) { - $attributes = self::parseFilterParamsAttr($data['attr']); + if (isset($filters['attr']) && $filters['attr']) { + $attributes = self::parseFilterParamsAttr($filters['attr']); foreach ($attributes as $attribute) { $builder->whereHas('attributes', function ($query) use ($attribute) { $query->where('attribute_id', $attribute['attr']) @@ -126,21 +127,21 @@ class ProductRepo } } - if (isset($data['sku']) || isset($data['model'])) { - $builder->whereHas('skus', function ($query) use ($data) { - if (isset($data['sku'])) { - $query->where('sku', 'like', "%{$data['sku']}%"); + if (isset($filters['sku']) || isset($filters['model'])) { + $builder->whereHas('skus', function ($query) use ($filters) { + if (isset($filters['sku'])) { + $query->where('sku', 'like', "%{$filters['sku']}%"); } - if (isset($data['model'])) { - $query->where('model', 'like', "%{$data['model']}%"); + if (isset($filters['model'])) { + $query->where('model', 'like', "%{$filters['model']}%"); } }); } - if (isset($data['price']) && $data['price']) { - $builder->whereHas('skus', function ($query) use ($data) { + if (isset($filters['price']) && $filters['price']) { + $builder->whereHas('skus', function ($query) use ($filters) { // price 格式:price=30-100 - $prices = explode('-', $data['price']); + $prices = explode('-', $filters['price']); if (! $prices[1]) { $query->where('price', '>', $prices[0] ?: 0)->where('is_default', 1); } else { @@ -149,11 +150,11 @@ class ProductRepo }); } - if (isset($data['name'])) { - $builder->where('pd.name', 'like', "%{$data['name']}%"); + if (isset($filters['name'])) { + $builder->where('pd.name', 'like', "%{$filters['name']}%"); } - $keyword = trim($data['keyword'] ?? ''); + $keyword = trim($filters['keyword'] ?? ''); if ($keyword) { $keywords = explode(' ', $keyword); $keywords = array_unique($keywords); @@ -175,17 +176,25 @@ class ProductRepo }); } - if (isset($data['active'])) { - $builder->where('active', (int) $data['active']); + if (isset($filters['created_start'])) { + $builder->where('products.created_at', '>', $filters['created_start']); + } + + if (isset($filters['created_end'])) { + $builder->where('products.created_at', '>', $filters['created_end']); + } + + if (isset($filters['active'])) { + $builder->where('active', (int) $filters['active']); } // 回收站 - if (isset($data['trashed']) && $data['trashed']) { + if (isset($filters['trashed']) && $filters['trashed']) { $builder->onlyTrashed(); } - $sort = $data['sort'] ?? 'products.position'; - $order = $data['order'] ?? 'desc'; + $sort = $filters['sort'] ?? 'products.position'; + $order = $filters['order'] ?? 'desc'; $builder->orderBy($sort, $order); return $builder; diff --git a/beike/Shop/Services/TotalService.php b/beike/Shop/Services/TotalService.php index b1030322..d0f2f836 100644 --- a/beike/Shop/Services/TotalService.php +++ b/beike/Shop/Services/TotalService.php @@ -113,7 +113,7 @@ class TotalService $maps = []; foreach (self::TOTAL_CODES as $code) { $serviceName = Str::studly($code) . 'Service'; - $maps[$code] = "\Beike\\Shop\\Services\\TotalServices\\{$serviceName}"; + $maps[$code] = "\Beike\\Shop\\Services\\TotalServices\\{$serviceName}"; } return hook_filter('service.total.maps', $maps); diff --git a/resources/beike/admin/views/pages/home.blade.php b/resources/beike/admin/views/pages/home.blade.php index 50226a89..f2a5b3ff 100644 --- a/resources/beike/admin/views/pages/home.blade.php +++ b/resources/beike/admin/views/pages/home.blade.php @@ -13,18 +13,17 @@
- {{ __('admin/dashboard.customer_view') }} + {{ __('admin/dashboard.product_total') }} {{ __('admin/dashboard.yesterday') }}
- {{--
{{ __('admin/dashboard.customer_view') }}
--}}
-
{{ $views['total'] }}
+
{{ $products['total'] }}
- {{--
--}}
-
{{ $views['percentage'] }}% {{ __('admin/dashboard.day_before') }}
+
{{ $products['percentage'] }}% + {{ __('admin/dashboard.day_before') }}
@@ -35,14 +34,13 @@ {{ __('admin/dashboard.yesterday') }}
- {{--
{{ __('admin/dashboard.order_total') }}
--}}
{{ $orders['total'] }}
- {{--
--}}
-
{{ $orders['percentage'] }}% {{ __('admin/dashboard.day_before') }}
+
{{ $orders['percentage'] }}% + {{ __('admin/dashboard.day_before') }}
@@ -53,14 +51,13 @@ {{ __('admin/dashboard.yesterday') }}
- {{--
{{ __('admin/dashboard.customer_new') }}
--}}
{{ $customers['total'] }}
- {{--
--}}
-
{{ $customers['percentage'] }}% {{ __('admin/dashboard.day_before') }}
+
{{ $customers['percentage'] }}% + {{ __('admin/dashboard.day_before') }}
@@ -71,15 +68,14 @@ {{ __('admin/dashboard.yesterday') }}
- {{--
{{ __('admin/dashboard.order_amount') }}
--}}
{{ $order_totals['total'] }}
- {{--
--}}
-
{{ $order_totals['percentage'] }}% {{ __('admin/dashboard.day_before') }}
+
{{ $order_totals['percentage'] }}% + {{ __('admin/dashboard.day_before') }}
diff --git a/resources/lang/en/admin/multi_filter.php b/resources/lang/en/admin/multi_filter.php index 1f5988b6..5189aeac 100644 --- a/resources/lang/en/admin/multi_filter.php +++ b/resources/lang/en/admin/multi_filter.php @@ -10,5 +10,5 @@ */ return [ - 'price_filter' => 'Price Filter', + 'price_filter' => 'Price Filter', ]; diff --git a/resources/lang/zh_cn/admin/dashboard.php b/resources/lang/zh_cn/admin/dashboard.php index df39070f..e2fcece1 100644 --- a/resources/lang/zh_cn/admin/dashboard.php +++ b/resources/lang/zh_cn/admin/dashboard.php @@ -10,6 +10,7 @@ */ return [ + 'product_total' => '产品总数', 'customer_view' => '用户访问量', 'order_total' => '订单量', 'customer_new' => '新增用户', diff --git a/resources/lang/zh_cn/admin/multi_filter.php b/resources/lang/zh_cn/admin/multi_filter.php index f3537ec8..34f77da3 100644 --- a/resources/lang/zh_cn/admin/multi_filter.php +++ b/resources/lang/zh_cn/admin/multi_filter.php @@ -10,5 +10,5 @@ */ return [ - 'price_filter' => '价格筛选', + 'price_filter' => '价格筛选', ]; diff --git a/resources/lang/zh_cn/admin/product.php b/resources/lang/zh_cn/admin/product.php index 5e08e793..7c9eb6e6 100644 --- a/resources/lang/zh_cn/admin/product.php +++ b/resources/lang/zh_cn/admin/product.php @@ -10,14 +10,14 @@ */ return [ - 'products_index' => '商品列表', - 'products_create' => '创建商品', - 'products_show' => '商品详情', - 'products_update' => '更新商品', - 'products_delete' => '删除商品', - 'products_trashed' => '回收站', - 'products_restore' => '恢复回收站', - 'clear_restore' => '清空回收站', + 'products_index' => '商品列表', + 'products_create' => '创建商品', + 'products_show' => '商品详情', + 'products_update' => '更新商品', + 'products_delete' => '删除商品', + 'products_trashed' => '回收站', + 'products_restore' => '恢复回收站', + 'clear_restore' => '清空回收站', 'products_filter_index' => '查看高级筛选', 'products_filter_update' => '修改高级筛选', diff --git a/resources/lang/zh_hk/admin/multi_filter.php b/resources/lang/zh_hk/admin/multi_filter.php index 7c961e58..53a92d95 100644 --- a/resources/lang/zh_hk/admin/multi_filter.php +++ b/resources/lang/zh_hk/admin/multi_filter.php @@ -10,5 +10,5 @@ */ return [ - 'price_filter' => '價格篩選', + 'price_filter' => '價格篩選', ];