You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.2 KiB

6 years ago
  1. <?php
  2. namespace App\Controller\v3;
  3. use App\Constants\v3\ActivityType;
  4. use App\Constants\v3\Banner;
  5. use App\Constants\v3\SsdbKeys;
  6. use App\Constants\v3\Tabs;
  7. use App\Controller\BaseController;
  8. use App\Request\v3\UserIndexRequest;
  9. use App\Service\v3\Interfaces\ActivityServiceInterface;
  10. use App\Service\v3\Interfaces\BannerServiceInterface;
  11. use App\Service\v3\Interfaces\CategoryServiceInterface;
  12. use App\Service\v3\Interfaces\CollectStoreServiceInterface;
  13. use App\Service\v3\Interfaces\CouponServiceInterface;
  14. use App\Service\v3\Interfaces\UserCenterBlockServiceInterface;
  15. use App\Service\v3\Interfaces\UserInfoServiceInterface;
  16. use App\TaskWorker\SSDBTask;
  17. use Hyperf\Di\Annotation\Inject;
  18. use Hyperf\Utils\ApplicationContext;
  19. /**
  20. * 首页相关
  21. * Class HomeController
  22. * @package App\Controller\v3
  23. */
  24. class HomeController extends BaseController
  25. {
  26. /**
  27. * @Inject
  28. * @var UserInfoServiceInterface
  29. */
  30. protected $userInfoService;
  31. /**
  32. * @Inject
  33. * @var CollectStoreServiceInterface
  34. */
  35. protected $collectStoreService;
  36. /**
  37. * @Inject
  38. * @var CouponServiceInterface
  39. */
  40. protected $couponService;
  41. /**
  42. * @Inject
  43. * @var UserCenterBlockServiceInterface
  44. */
  45. protected $userCenterBlockService;
  46. /**
  47. * @Inject
  48. * @var BannerServiceInterface
  49. */
  50. protected $bannerService;
  51. /**
  52. * @Inject
  53. * @var CategoryServiceInterface
  54. */
  55. protected $categoryService;
  56. /**
  57. * @Inject
  58. * @var ActivityServiceInterface
  59. */
  60. protected $activityService;
  61. /**
  62. * 小程序首页,根据market_id
  63. * 1.banner数据
  64. * 2.一级分类
  65. * 3.活动数据(秒杀、团购、新品、无)
  66. * 4.tabs数据
  67. */
  68. public function appletIndex()
  69. {
  70. $marketId = $this->request->input('market_id', 0);
  71. $banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $marketId);
  72. $categories = $this->categoryService->allForAppletIndex();
  73. $activity = $this->activityService->allForAppletIndex(ActivityType::FLASH_SALE, $marketId);
  74. return $this->success([
  75. 'banners' => $banners,
  76. 'categories' => $categories,
  77. 'activity' => $activity,
  78. 'tabs' => [
  79. ['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '推荐', 'subtitle' => '猜你喜欢', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  80. ['tab' => Tabs::APPLET_INDEX_NEW, 'title' => '懒族上新', 'subtitle' => '买点不一样', 'badge' => '限时', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  81. ['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '实时鲜货', 'subtitle' => '今天辛苦了', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  82. ['tab' => Tabs::APPLET_INDEX_OFFICE, 'title' => '上班带餐', 'subtitle' => '轻奢快手菜', 'badge' => '不慌', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  83. ]
  84. ]);
  85. }
  86. /**
  87. * 用户首页,我的页面
  88. * 1、用户信息,id、昵称、名字、头像
  89. * 2、收藏、红包、积分
  90. * 3、badge角标,待付款、待收货、已完成、售后, SSDB维护
  91. * 4、为你推荐的商品列表
  92. * @param UserIndexRequest $request
  93. */
  94. public function userIndex(UserIndexRequest $request)
  95. {
  96. $params = $request->validated();
  97. $data['user'] = $this->userInfoService->detail($params['user_id']);
  98. $data['user']['role'] = '商家';
  99. $data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']);
  100. $data['user']['coupon_count'] = $this->couponService->countAvailableByUser($params['user_id']);
  101. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  102. $data['badge'] = [
  103. 'unpaid' => 0,
  104. 'receiving' => 0,
  105. 'completed' => 0,
  106. 'refund' => 0,
  107. ];
  108. $badge = $ssdb->exec('hgetall', SsdbKeys::USER_ORDER_BADGE.$params['user_id']);
  109. if (!empty($badge)) {
  110. $data['badge'] = array_merge($data['badge'], $badge);
  111. }
  112. $data['block'] = $this->userCenterBlockService->all();
  113. return $this->success($data);
  114. }
  115. }