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.

228 lines
6.1 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. $store_info = $this->userInfoService->getStoreByUID($params['user_id']);
  109. $sp_info = $this->userInfoService->getServicePersonnelByUID($params['user_id']);
  110. $data['user']['store_info'] = $store_info;
  111. $data['user']['sp_info'] = $sp_info;
  112. $roles = [];
  113. //角色判断
  114. if($store_info){
  115. $roles[] = [
  116. 'key'=>'store',
  117. 'title'=>'商家',
  118. 'color'=>'#0091FF',
  119. 'data'=>$store_info,
  120. ];
  121. }
  122. if($sp_info){
  123. $roles[] = [
  124. 'key'=>'sp',
  125. 'title'=>'服务',
  126. 'color'=>'#0091FF',
  127. 'data'=>$sp_info,
  128. ];
  129. }
  130. $data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']);
  131. $data['user']['coupon_count'] = $this->couponService->countAvailableByUser($params['user_id']);
  132. $data['user']['role'] = $roles;
  133. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  134. $data['badge'] = [
  135. 'unpaid' => 0,
  136. 'receiving' => 0,
  137. 'completed' => 0,
  138. 'refund' => 0,
  139. ];
  140. $badge = $ssdb->exec('hgetall', SsdbKeys::USER_ORDER_BADGE.$params['user_id']);
  141. if (!empty($badge)) {
  142. $data['badge'] = array_merge($data['badge'], $badge);
  143. }
  144. $data['block'] = $this->userCenterBlockService->all($roles);
  145. return $this->success($data);
  146. }
  147. /**
  148. * 商家入口详情
  149. */
  150. public function storeIndex()
  151. {
  152. $data['detail'] = $this->storeService->detail(1);
  153. $data['order_online'] = [
  154. 'count' => 6549,
  155. 'total' => 12654.12
  156. ];
  157. $data['order_offline'] = [
  158. 'count' => 3639,
  159. 'total' => 89563.12
  160. ];
  161. $data['new_user'] = [
  162. 'day' => 10,
  163. 'week' => 15,
  164. 'month' => 25,
  165. 'all' => 50
  166. ];
  167. $data['badge'] = [
  168. 'unpaid' => 0,
  169. 'receiving' => 0,
  170. 'completed' => 0,
  171. 'refund' => 0,
  172. ];
  173. return $this->success($data);
  174. }
  175. /**
  176. * 关于懒族
  177. * about lanzu
  178. */
  179. public function aboutLanzu()
  180. {
  181. $data = [
  182. [
  183. 'id' => 1,
  184. 'title' => '关于懒族',
  185. 'sub_title' => '懒族生活678',
  186. 'path' => 'https://www.baidu.com/s?wd=%E6%87%92%E6%97%8F%E7%94%9F%E6%B4%BB',
  187. 'path_type' => 'webview'
  188. ],
  189. [
  190. 'id' => 1,
  191. 'title' => '隐私政策',
  192. 'sub_title' => '隐私政策123',
  193. 'path' => 'https://www.baidu.com/s?wd=%E9%9A%90%E7%A7%81%E6%94%BF%E7%AD%96',
  194. 'path_type' => 'webview'
  195. ]
  196. ];
  197. return $this->success(['data' => $data]);
  198. }
  199. }