HomeServices.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\services\pc;
  13. use app\services\BaseServices;
  14. use app\services\product\product\StoreCategoryServices;
  15. use app\services\product\product\StoreProductServices;
  16. class HomeServices extends BaseServices
  17. {
  18. /**
  19. * 首页分类尚品
  20. * @return mixed
  21. */
  22. public function getCategoryProduct()
  23. {
  24. /** @var StoreCategoryServices $category */
  25. $category = app()->make(StoreCategoryServices::class);
  26. /** @var StoreProductServices $product */
  27. $product = app()->make(StoreProductServices::class);
  28. [$page, $limit] = $this->getPageValue();
  29. $list = $category->getCid($page, $limit);
  30. foreach ($list as &$info) {
  31. $productList = $product->getSearchList(['cid' => $info['id'], 'star' => 1, 'is_show' => 1, 'is_del' => 0], 1, 8, ['id,store_name,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,ot_price']);
  32. foreach ($productList as &$item) {
  33. if (count($item['star'])) {
  34. $item['star'] = bcdiv((string)array_sum(array_column($item['star'], 'product_score')), (string)count($item['star']), 1);
  35. } else {
  36. $item['star'] = '3.0';
  37. }
  38. }
  39. $info['productList'] = get_thumb_water($productList, 'mid');
  40. }
  41. $data['list'] = $list;
  42. $data['count'] = $category->getCidCount();
  43. return $data;
  44. }
  45. }