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
9.7 KiB

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