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.

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