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.

172 lines
5.2 KiB

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