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.

222 lines
9.4 KiB

  1. <?php
  2. namespace App\Controller\v3;
  3. use App\Constants\v3\ActivityType;
  4. use App\Constants\v3\SsdbKeys;
  5. use App\Constants\v3\Tabs;
  6. use App\Controller\BaseController;
  7. use App\Request\v3\UserIndexRequest;
  8. use App\Service\v3\Interfaces\CollectStoreServiceInterface;
  9. use App\Service\v3\Interfaces\CouponServiceInterface;
  10. use App\Service\v3\Interfaces\UserCenterBlockServiceInterface;
  11. use App\Service\v3\Interfaces\UserInfoServiceInterface;
  12. use App\TaskWorker\SSDBTask;
  13. use Hyperf\Di\Annotation\Inject;
  14. use Hyperf\Utils\ApplicationContext;
  15. /**
  16. * 首页相关
  17. * Class HomeController
  18. * @package App\Controller\v3
  19. */
  20. class HomeController extends BaseController
  21. {
  22. /**
  23. * @Inject
  24. * @var UserInfoServiceInterface
  25. */
  26. protected $userInfoService;
  27. /**
  28. * @Inject
  29. * @var CollectStoreServiceInterface
  30. */
  31. protected $collectStoreService;
  32. /**
  33. * @Inject
  34. * @var CouponServiceInterface
  35. */
  36. protected $couponService;
  37. /**
  38. * @Inject
  39. * @var UserCenterBlockServiceInterface
  40. */
  41. protected $userCenterBlockService;
  42. /**
  43. * 小程序首页,根据market_id
  44. * 1.banner数据
  45. * 2.一级分类
  46. * 3.活动数据(秒杀、团购、新品、无)
  47. * 4.tabs数据
  48. */
  49. public function appletIndex()
  50. {
  51. $seconds = 25600;
  52. $days = bcdiv($seconds, 86400);
  53. $leftSeconds = bcsub($seconds, bcmul($days,86400));
  54. $hours = bcdiv($leftSeconds,3600);
  55. $leftSeconds = bcsub($leftSeconds, bcmul($hours,3600));
  56. $minutes = bcdiv($leftSeconds,60);
  57. $leftSeconds = bcsub($leftSeconds, bcmul($minutes,60));
  58. return $this->success([
  59. 'banners' => [
  60. [
  61. 'id' => 2,
  62. 'img' => 'https://store.lanzu.vip/attachment/images/2/2020/06/nfXxIhEgH71hcSxSz2hHnaaEaF1g3A.jpg',
  63. 'title' => '懒族生活',
  64. 'subtitle' => '满足您的美味生活',
  65. 'redirect_type' => '',
  66. 'redirect_url' => '',
  67. ],
  68. [
  69. 'id' => 3,
  70. 'img' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg',
  71. 'title' => '鲜菜有爱',
  72. 'subtitle' => '很实在',
  73. 'redirect_type' => 'page',
  74. 'redirect_url' => '/pages/index',
  75. ],
  76. ],
  77. 'categories' => [
  78. ['id' => 1, 'icon' => config('alioss.img_host').'/attachment/types/卤菜.png', 'name' => '卤菜'],
  79. ['id' => 2, 'icon' => config('alioss.img_host').'/attachment/types/水果.png', 'name' => '水果'],
  80. ['id' => 3, 'icon' => config('alioss.img_host').'/attachment/types/肉.png', 'name' => '肉'],
  81. ['id' => 4, 'icon' => config('alioss.img_host').'/attachment/types/蔬菜.png', 'name' => '蔬菜'],
  82. ['id' => 5, 'icon' => config('alioss.img_host').'/attachment/types/蔬菜.png', 'name' => '蔬菜'],
  83. ['id' => 6, 'icon' => config('alioss.img_host').'/attachment/types/肉.png', 'name' => '肉'],
  84. ['id' => 7, 'icon' => config('alioss.img_host').'/attachment/types/水果.png', 'name' => '水果'],
  85. ['id' => 8, 'icon' => config('alioss.img_host').'/attachment/types/卤菜.png', 'name' => '卤菜'],
  86. ],
  87. 'activity' => [
  88. 'type' => ActivityType::FLASH_SALE,
  89. 'goods' => [
  90. [
  91. 'id' => 1,
  92. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  93. 'name' => '【优质】大白菜',
  94. 'spec' => [
  95. ['key' => '净含量', 'value' => '500g']
  96. ],
  97. 'original_price' => 50.5,
  98. 'price' => 25.25,
  99. 'inventory' => 0,
  100. 'month_sales' => 20,
  101. 'total_sales' => 20,
  102. 'cart_num' => 0,
  103. 'is_effective' => 1,
  104. 'noneffective_note' => '已抢光',
  105. 'total_seconds' => $seconds,
  106. 'days' => $days,
  107. 'hours' => $hours,
  108. 'minutes' => $minutes,
  109. 'seconds' => $leftSeconds,
  110. ],[
  111. 'id' => 1,
  112. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  113. 'name' => '【优质】大白菜',
  114. 'spec' => [
  115. ['key' => '净含量', 'value' => '500g']
  116. ],
  117. 'original_price' => 50.5,
  118. 'price' => 25.25,
  119. 'inventory' => 0,
  120. 'month_sales' => 20,
  121. 'total_sales' => 20,
  122. 'cart_num' => 0,
  123. 'is_effective' => 1,
  124. 'noneffective_note' => '已抢光',
  125. 'total_seconds' => $seconds,
  126. 'days' => $days,
  127. 'hours' => $hours,
  128. 'minutes' => $minutes,
  129. 'seconds' => $leftSeconds,
  130. ],[
  131. 'id' => 1,
  132. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  133. 'name' => '【优质】大白菜',
  134. 'spec' => [
  135. ['key' => '净含量', 'value' => '500g']
  136. ],
  137. 'original_price' => 50.5,
  138. 'price' => 25.25,
  139. 'inventory' => 0,
  140. 'month_sales' => 20,
  141. 'total_sales' => 20,
  142. 'cart_num' => 0,
  143. 'is_effective' => 1,
  144. 'noneffective_note' => '已抢光',
  145. 'total_seconds' => $seconds,
  146. 'days' => $days,
  147. 'hours' => $hours,
  148. 'minutes' => $minutes,
  149. 'seconds' => $leftSeconds,
  150. ],[
  151. 'id' => 1,
  152. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  153. 'name' => '【优质】大白菜',
  154. 'spec' => [
  155. ['key' => '净含量', 'value' => '500g']
  156. ],
  157. 'original_price' => 50.5,
  158. 'price' => 25.25,
  159. 'inventory' => 0,
  160. 'month_sales' => 20,
  161. 'total_sales' => 20,
  162. 'cart_num' => 0,
  163. 'is_effective' => 1,
  164. 'noneffective_note' => '已抢光',
  165. 'total_seconds' => $seconds,
  166. 'days' => $days,
  167. 'hours' => $hours,
  168. 'minutes' => $minutes,
  169. 'seconds' => $leftSeconds,
  170. ],
  171. ]
  172. ],
  173. 'tabs' => [
  174. ['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '推荐', 'subtitle' => '猜你喜欢', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  175. ['tab' => Tabs::APPLET_INDEX_NEW, 'title' => '懒族上新', 'subtitle' => '买点不一样', 'badge' => '限时', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  176. ['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '实时鲜货', 'subtitle' => '今天辛苦了', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  177. ['tab' => Tabs::APPLET_INDEX_OFFICE, 'title' => '上班带餐', 'subtitle' => '轻奢快手菜', 'badge' => '不慌', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  178. ]
  179. ]);
  180. }
  181. /**
  182. * 用户首页,我的页面
  183. * 1、用户信息,id、昵称、名字、头像
  184. * 2、收藏、红包、积分
  185. * 3、badge角标,待付款、待收货、已完成、售后, SSDB维护
  186. * 4、为你推荐的商品列表
  187. * @param UserIndexRequest $request
  188. */
  189. public function userIndex(UserIndexRequest $request)
  190. {
  191. $params = $request->validated();
  192. $data['user'] = $this->userInfoService->detail($params['user_id']);
  193. $data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']);
  194. $data['user']['coupon_count'] = $this->couponService->countAvailableByUser($params['user_id']);
  195. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  196. $data['badge'] = [
  197. 'unpaid' => 0,
  198. 'receiving' => 0,
  199. 'completed' => 0,
  200. 'refund' => 0,
  201. ];
  202. $badge = $ssdb->exec('hgetall', SsdbKeys::USER_ORDER_BADGE.$params['user_id']);
  203. if (!empty($badge)) {
  204. $data['badge'] = array_merge($data['badge'], $badge);
  205. }
  206. $data['block'] = $this->userCenterBlockService->all();
  207. return $this->success($data);
  208. }
  209. }