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.

211 lines
5.7 KiB

5 years ago
5 years ago
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\StoreServiceInterface;
  15. use App\Service\v3\Interfaces\TabsServiceInterface;
  16. use App\Service\v3\Interfaces\UserCenterBlockServiceInterface;
  17. use App\Service\v3\Interfaces\UserInfoServiceInterface;
  18. use App\TaskWorker\SSDBTask;
  19. use Hyperf\Di\Annotation\Inject;
  20. use Hyperf\Utils\ApplicationContext;
  21. use Psr\Http\Message\ResponseInterface;
  22. /**
  23. * 首页相关
  24. * Class HomeController
  25. * @package App\Controller\v3
  26. */
  27. class HomeController extends BaseController
  28. {
  29. /**
  30. * @Inject
  31. * @var UserInfoServiceInterface
  32. */
  33. protected $userInfoService;
  34. /**
  35. * @Inject
  36. * @var CollectStoreServiceInterface
  37. */
  38. protected $collectStoreService;
  39. /**
  40. * @Inject
  41. * @var CouponServiceInterface
  42. */
  43. protected $couponService;
  44. /**
  45. * @Inject
  46. * @var UserCenterBlockServiceInterface
  47. */
  48. protected $userCenterBlockService;
  49. /**
  50. * @Inject
  51. * @var StoreServiceInterface
  52. */
  53. protected $storeService;
  54. /**
  55. * @Inject
  56. * @var BannerServiceInterface
  57. */
  58. protected $bannerService;
  59. /**
  60. * @Inject
  61. * @var CategoryServiceInterface
  62. */
  63. protected $categoryService;
  64. /**
  65. * @Inject
  66. * @var ActivityServiceInterface
  67. */
  68. protected $activityService;
  69. /**
  70. * @Inject
  71. * @var TabsServiceInterface
  72. */
  73. protected $tabsService;
  74. /**
  75. * 小程序首页,根据market_id
  76. * 1.banner数据
  77. * 2.一级分类
  78. * 3.活动数据(秒杀、团购、新品、无)
  79. * 4.tabs数据
  80. */
  81. public function appletIndex()
  82. {
  83. $marketId = $this->request->input('market_id', -1);
  84. $banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $marketId);
  85. $categories = $this->categoryService->allForAppletIndex();
  86. $activity = $this->activityService->allForAppletIndex(env('APPLET_INDEX_ACTIVITY_TYPE'), $marketId);
  87. $tabs = $this->tabsService->allForAppletIndex();
  88. return $this->success([
  89. 'banners' => $banners,
  90. 'categories' => $categories,
  91. 'activity' => ['type' => ActivityType::FLASH_SALE, 'goods' => $activity],
  92. 'tabs' => $tabs,
  93. ]);
  94. }
  95. /**
  96. * 用户首页,我的页面
  97. * 1、用户信息,id、昵称、名字、头像
  98. * 2、收藏、红包、积分
  99. * 3、badge角标,待付款、待收货、已完成、售后, SSDB维护
  100. * 4、为你推荐的商品列表
  101. * @param UserIndexRequest $request
  102. * @return ResponseInterface
  103. */
  104. public function userIndex(UserIndexRequest $request)
  105. {
  106. $params = $request->validated();
  107. $data['user'] = $this->userInfoService->detail($params['user_id']);
  108. $data['user']['store_info'] = $this->userInfoService->getStoreByUID($params['user_id']);
  109. $data['user']['role'] = [
  110. [
  111. 'title'=>'商家',
  112. 'color'=>'#0091FF'
  113. ],
  114. [
  115. 'title'=>'骑手',
  116. 'color'=>'#009100'
  117. ],
  118. ];
  119. $data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']);
  120. $data['user']['coupon_count'] = $this->couponService->countAvailableByUser($params['user_id']);
  121. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  122. $data['badge'] = [
  123. 'unpaid' => 0,
  124. 'receiving' => 0,
  125. 'completed' => 0,
  126. 'refund' => 0,
  127. ];
  128. $badge = $ssdb->exec('hgetall', SsdbKeys::USER_ORDER_BADGE.$params['user_id']);
  129. if (!empty($badge)) {
  130. $data['badge'] = array_merge($data['badge'], $badge);
  131. }
  132. $data['block'] = $this->userCenterBlockService->all();
  133. return $this->success($data);
  134. }
  135. /**
  136. * 商家入口详情
  137. */
  138. public function storeIndex()
  139. {
  140. $data['detail'] = $this->storeService->detail(1);
  141. $data['order_online'] = [
  142. 'count' => 6549,
  143. 'total' => 12654.12
  144. ];
  145. $data['order_offline'] = [
  146. 'count' => 3639,
  147. 'total' => 89563.12
  148. ];
  149. $data['new_user'] = [
  150. 'day' => 10,
  151. 'week' => 15,
  152. 'month' => 25,
  153. 'all' => 50
  154. ];
  155. $data['badge'] = [
  156. 'unpaid' => 0,
  157. 'receiving' => 0,
  158. 'completed' => 0,
  159. 'refund' => 0,
  160. ];
  161. return $this->success($data);
  162. }
  163. /**
  164. * 关于懒族
  165. * about lanzu
  166. */
  167. public function aboutLanzu()
  168. {
  169. $data = [
  170. [
  171. 'id' => 1,
  172. 'title' => '关于懒族',
  173. 'sub_title' => '懒族生活678',
  174. 'path' => 'https://www.baidu.com/s?wd=%E6%87%92%E6%97%8F%E7%94%9F%E6%B4%BB',
  175. 'path_type' => 'webview'
  176. ],
  177. [
  178. 'id' => 1,
  179. 'title' => '隐私政策',
  180. 'sub_title' => '隐私政策123',
  181. 'path' => 'https://www.baidu.com/s?wd=%E9%9A%90%E7%A7%81%E6%94%BF%E7%AD%96',
  182. 'path_type' => 'webview'
  183. ]
  184. ];
  185. return $this->success(['data' => $data]);
  186. }
  187. }