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.

226 lines
9.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  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. 'store_id' => 111,
  93. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  94. 'name' => '【优质】大白菜',
  95. 'spec' => [
  96. ['key' => '净含量', 'value' => '500g']
  97. ],
  98. 'original_price' => 50.5,
  99. 'price' => 25.25,
  100. 'inventory' => 0,
  101. 'month_sales' => 20,
  102. 'total_sales' => 20,
  103. 'cart_num' => 0,
  104. 'is_effective' => 1,
  105. 'noneffective_note' => '已抢光',
  106. 'total_seconds' => $seconds,
  107. 'days' => $days,
  108. 'hours' => $hours,
  109. 'minutes' => $minutes,
  110. 'seconds' => $leftSeconds,
  111. ],[
  112. 'id' => 1,
  113. 'store_id' => 111,
  114. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  115. 'name' => '【优质】大白菜',
  116. 'spec' => [
  117. ['key' => '净含量', 'value' => '500g']
  118. ],
  119. 'original_price' => 50.5,
  120. 'price' => 25.25,
  121. 'inventory' => 0,
  122. 'month_sales' => 20,
  123. 'total_sales' => 20,
  124. 'cart_num' => 0,
  125. 'is_effective' => 1,
  126. 'noneffective_note' => '已抢光',
  127. 'total_seconds' => $seconds,
  128. 'days' => $days,
  129. 'hours' => $hours,
  130. 'minutes' => $minutes,
  131. 'seconds' => $leftSeconds,
  132. ],[
  133. 'id' => 1,
  134. 'store_id' => 111,
  135. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  136. 'name' => '【优质】大白菜',
  137. 'spec' => [
  138. ['key' => '净含量', 'value' => '500g']
  139. ],
  140. 'original_price' => 50.5,
  141. 'price' => 25.25,
  142. 'inventory' => 0,
  143. 'month_sales' => 20,
  144. 'total_sales' => 20,
  145. 'cart_num' => 0,
  146. 'is_effective' => 1,
  147. 'noneffective_note' => '已抢光',
  148. 'total_seconds' => $seconds,
  149. 'days' => $days,
  150. 'hours' => $hours,
  151. 'minutes' => $minutes,
  152. 'seconds' => $leftSeconds,
  153. ],[
  154. 'id' => 1,
  155. 'store_id' => 111,
  156. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  157. 'name' => '【优质】大白菜',
  158. 'spec' => [
  159. ['key' => '净含量', 'value' => '500g']
  160. ],
  161. 'original_price' => 50.5,
  162. 'price' => 25.25,
  163. 'inventory' => 0,
  164. 'month_sales' => 20,
  165. 'total_sales' => 20,
  166. 'cart_num' => 0,
  167. 'is_effective' => 1,
  168. 'noneffective_note' => '已抢光',
  169. 'total_seconds' => $seconds,
  170. 'days' => $days,
  171. 'hours' => $hours,
  172. 'minutes' => $minutes,
  173. 'seconds' => $leftSeconds,
  174. ],
  175. ]
  176. ],
  177. 'tabs' => [
  178. ['tab' => Tabs::APPLET_INDEX_RECOMMEND, 'title' => '推荐', 'subtitle' => '猜你喜欢', 'badge' => '', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  179. ['tab' => Tabs::APPLET_INDEX_NEW, 'title' => '懒族上新', 'subtitle' => '买点不一样', 'badge' => '限时', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  180. ['tab' => Tabs::APPLET_INDEX_FRESH, 'title' => '实时鲜货', 'subtitle' => '今天辛苦了', 'badge' => '好新鲜', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  181. ['tab' => Tabs::APPLET_INDEX_OFFICE, 'title' => '上班带餐', 'subtitle' => '轻奢快手菜', 'badge' => '不慌', 'bg_color' => '#FF0000', 'font_color' => '#FFFFFF'],
  182. ]
  183. ]);
  184. }
  185. /**
  186. * 用户首页,我的页面
  187. * 1、用户信息,id、昵称、名字、头像
  188. * 2、收藏、红包、积分
  189. * 3、badge角标,待付款、待收货、已完成、售后, SSDB维护
  190. * 4、为你推荐的商品列表
  191. * @param UserIndexRequest $request
  192. */
  193. public function userIndex(UserIndexRequest $request)
  194. {
  195. $params = $request->validated();
  196. $data['user'] = $this->userInfoService->detail($params['user_id']);
  197. $data['user']['collection_count'] = $this->collectStoreService->countByUser($params['user_id']);
  198. $data['user']['coupon_count'] = $this->couponService->countAvailableByUser($params['user_id']);
  199. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  200. $data['badge'] = [
  201. 'unpaid' => 0,
  202. 'receiving' => 0,
  203. 'completed' => 0,
  204. 'refund' => 0,
  205. ];
  206. $badge = $ssdb->exec('hgetall', SsdbKeys::USER_ORDER_BADGE.$params['user_id']);
  207. if (!empty($badge)) {
  208. $data['badge'] = array_merge($data['badge'], $badge);
  209. }
  210. $data['block'] = $this->userCenterBlockService->all();
  211. return $this->success($data);
  212. }
  213. }