HomeServices.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\category\StoreProductCategoryServices;
  15. use app\services\product\product\StoreProductServices;
  16. use app\services\user\UserServices;
  17. class HomeServices extends BaseServices
  18. {
  19. /**
  20. * pc首页分类商品
  21. * @param int $uid
  22. * @return array
  23. */
  24. public function getCategoryProduct(int $uid = 0)
  25. {
  26. /** @var StoreProductCategoryServices $category */
  27. $category = app()->make(StoreProductCategoryServices::class);
  28. /** @var StoreProductServices $product */
  29. $product = app()->make(StoreProductServices::class);
  30. [$page, $limit] = $this->getPageValue();
  31. $list = $category->getCid($page, $limit);
  32. $where = ['type' => [0, 2], 'star' => 1, 'is_show' => 1, 'is_del' => 0];
  33. $where['is_vip_product'] = 0;
  34. if ($uid) {
  35. /** @var UserServices $userServices */
  36. $userServices = app()->make(UserServices::class);
  37. $is_vip = $userServices->value(['uid' => $uid], 'is_money_level');
  38. $where['is_vip_product'] = $is_vip ? -1 : 0;
  39. }
  40. $where['pid'] = 0;
  41. foreach ($list as &$info) {
  42. $productList = $product->getSearchList($where + ['cid' => $info['id']], 1, 8, ['id,store_name,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,ot_price']);
  43. foreach ($productList as &$item) {
  44. if (isset($item['star']) && count($item['star'])) {
  45. $item['star'] = bcdiv((string)array_sum(array_column($item['star'], 'product_score')), (string)count($item['star']), 1);
  46. } else {
  47. $item['star'] = config('admin.product_default_star');
  48. }
  49. }
  50. $info['productList'] = get_thumb_water($productList, 'mid');
  51. }
  52. $data['list'] = $list;
  53. $data['count'] = $category->getCidCount();
  54. return $data;
  55. }
  56. }