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.

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