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.

170 lines
5.0 KiB

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