HomeServices.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\activity\coupon\StoreCouponIssueServices;
  14. use app\services\BaseServices;
  15. use app\services\product\product\StoreCategoryServices;
  16. use app\services\product\product\StoreProductServices;
  17. use app\services\user\UserServices;
  18. class HomeServices extends BaseServices
  19. {
  20. /**
  21. * 首页分类商品
  22. * @param int $uid
  23. * @return array
  24. */
  25. public function getCategoryProduct(int $uid = 0)
  26. {
  27. /** @var StoreCategoryServices $category */
  28. $category = app()->make(StoreCategoryServices::class);
  29. /** @var StoreProductServices $product */
  30. $product = app()->make(StoreProductServices::class);
  31. $vip_user = $uid ? app()->make(UserServices::class)->value(['uid' => $uid], 'is_money_level') : 0;
  32. [$page, $limit] = $this->getPageValue();
  33. $list = $category->getCid($page, $limit);
  34. foreach ($list as $key => &$info) {
  35. $productList = $product->getSearchList(['cid' => $info['id'], 'star' => 1, 'is_show' => 1, 'is_del' => 0, 'vip_user' => $vip_user], 1, 8, ['id,store_name,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,ot_price,presale']);
  36. if (!count($productList)) unset($list[$key]);
  37. foreach ($productList as &$item) {
  38. if (count($item['star'])) {
  39. $item['star'] = bcdiv((string)array_sum(array_column($item['star'], 'product_score')), (string)count($item['star']), 1);
  40. } else {
  41. $item['star'] = '5.0';
  42. }
  43. $item['checkCoupon'] = app()->make(StoreCouponIssueServices::class)->checkProductCoupon($item['id']);
  44. }
  45. $info['productList'] = get_thumb_water($productList, 'big');
  46. }
  47. $data['list'] = array_merge($list);
  48. $data['count'] = $category->getCidCount();
  49. return $data;
  50. }
  51. }