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.

133 lines
4.3 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. use Psr\Http\Message\ResponseInterface;
  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 BannerServiceInterface
  50. */
  51. protected $bannerService;
  52. /**
  53. * @Inject
  54. * @var CategoryServiceInterface
  55. */
  56. protected $categoryService;
  57. /**
  58. * @Inject
  59. * @var ActivityServiceInterface
  60. */
  61. protected $activityService;
  62. /**
  63. * 小程序首页,根据market_id
  64. * 1.banner数据
  65. * 2.一级分类
  66. * 3.活动数据(秒杀、团购、新品、无)
  67. * 4.tabs数据
  68. */
  69. public function appletIndex()
  70. {
  71. $marketId = $this->request->input('market_id', 0);
  72. $banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $marketId);
  73. $categories = $this->categoryService->allForAppletIndex();
  74. $activity = $this->activityService->allForAppletIndex(ActivityType::FLASH_SALE, $marketId);
  75. return $this->success([
  76. 'banners' => $banners,
  77. 'categories' => $categories,
  78. 'activity' => ['type' => ActivityType::FLASH_SALE, 'goods' => $activity],
  79. 'tabs' => [
  80. ['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '推荐', 'subtitle' => '猜你喜欢', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  81. ['tab' => Tabs::APPLET_INDEX_NEW, 'title' => '懒族上新', 'subtitle' => '买点不一样', 'badge' => '限时', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  82. ['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '实时鲜货', 'subtitle' => '今天辛苦了', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  83. ['tab' => Tabs::APPLET_INDEX_OFFICE, 'title' => '上班带餐', 'subtitle' => '轻奢快手菜', 'badge' => '不慌', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  84. ]
  85. ]);
  86. }
  87. /**
  88. * 用户首页,我的页面
  89. * 1、用户信息,id、昵称、名字、头像
  90. * 2、收藏、红包、积分
  91. * 3、badge角标,待付款、待收货、已完成、售后, SSDB维护
  92. * 4、为你推荐的商品列表
  93. * @param UserIndexRequest $request
  94. * @return ResponseInterface
  95. */
  96. public function userIndex(UserIndexRequest $request)
  97. {
  98. $params = $request->validated();
  99. $data['user'] = $this->userInfoService->detail($params['user_id']);
  100. $data['user']['role'] = '商家';
  101. $data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']);
  102. $data['user']['coupon_count'] = $this->couponService->countAvailableByUser($params['user_id']);
  103. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  104. $data['badge'] = [
  105. 'unpaid' => 0,
  106. 'receiving' => 0,
  107. 'completed' => 0,
  108. 'refund' => 0,
  109. ];
  110. $badge = $ssdb->exec('hgetall', SsdbKeys::USER_ORDER_BADGE.$params['user_id']);
  111. if (!empty($badge)) {
  112. $data['badge'] = array_merge($data['badge'], $badge);
  113. }
  114. $data['block'] = $this->userCenterBlockService->all();
  115. return $this->success($data);
  116. }
  117. }