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.

261 lines
10 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\StoreInfoServiceInterface;
  11. use App\Service\v3\Interfaces\UserCenterBlockServiceInterface;
  12. use App\Service\v3\Interfaces\UserInfoServiceInterface;
  13. use App\TaskWorker\SSDBTask;
  14. use Hyperf\Di\Annotation\Inject;
  15. use Hyperf\Utils\ApplicationContext;
  16. /**
  17. * 首页相关
  18. * Class HomeController
  19. * @package App\Controller\v3
  20. */
  21. class HomeController extends BaseController
  22. {
  23. /**
  24. * @Inject
  25. * @var UserInfoServiceInterface
  26. */
  27. protected $userInfoService;
  28. /**
  29. * @Inject
  30. * @var CollectStoreServiceInterface
  31. */
  32. protected $collectStoreService;
  33. /**
  34. * @Inject
  35. * @var CouponServiceInterface
  36. */
  37. protected $couponService;
  38. /**
  39. * @Inject
  40. * @var UserCenterBlockServiceInterface
  41. */
  42. protected $userCenterBlockService;
  43. /**
  44. * @Inject
  45. * @var StoreInfoServiceInterface
  46. */
  47. protected $storeInfoService;
  48. /**
  49. * 小程序首页,根据market_id
  50. * 1.banner数据
  51. * 2.一级分类
  52. * 3.活动数据(秒杀、团购、新品、无)
  53. * 4.tabs数据
  54. */
  55. public function appletIndex()
  56. {
  57. $seconds = 25600;
  58. $days = bcdiv($seconds, 86400);
  59. $leftSeconds = bcsub($seconds, bcmul($days,86400));
  60. $hours = bcdiv($leftSeconds,3600);
  61. $leftSeconds = bcsub($leftSeconds, bcmul($hours,3600));
  62. $minutes = bcdiv($leftSeconds,60);
  63. $leftSeconds = bcsub($leftSeconds, bcmul($minutes,60));
  64. return $this->success([
  65. 'banners' => [
  66. [
  67. 'id' => 2,
  68. 'img' => 'https://store.lanzu.vip/attachment/images/2/2020/06/nfXxIhEgH71hcSxSz2hHnaaEaF1g3A.jpg',
  69. 'title' => '懒族生活',
  70. 'subtitle' => '满足您的美味生活',
  71. 'redirect_type' => '',
  72. 'redirect_url' => '',
  73. ],
  74. [
  75. 'id' => 3,
  76. 'img' => 'http://lanzutest.lanzulive.com/attachment/images/2/2020/08/PY55Y3Mz17yJo17rv1Z7vImX1V5159.jpg',
  77. 'title' => '鲜菜有爱',
  78. 'subtitle' => '很实在',
  79. 'redirect_type' => 'page',
  80. 'redirect_url' => '/pages/index',
  81. ],
  82. ],
  83. 'categories' => [
  84. ['id' => 1, 'icon' => config('alioss.img_host').'/attachment/types/卤菜.png', 'name' => '卤菜'],
  85. ['id' => 2, 'icon' => config('alioss.img_host').'/attachment/types/水果.png', 'name' => '水果'],
  86. ['id' => 3, 'icon' => config('alioss.img_host').'/attachment/types/肉.png', 'name' => '肉'],
  87. ['id' => 4, 'icon' => config('alioss.img_host').'/attachment/types/蔬菜.png', 'name' => '蔬菜'],
  88. ['id' => 5, 'icon' => config('alioss.img_host').'/attachment/types/蔬菜.png', 'name' => '蔬菜'],
  89. ['id' => 6, 'icon' => config('alioss.img_host').'/attachment/types/肉.png', 'name' => '肉'],
  90. ['id' => 7, 'icon' => config('alioss.img_host').'/attachment/types/水果.png', 'name' => '水果'],
  91. ['id' => 8, 'icon' => config('alioss.img_host').'/attachment/types/卤菜.png', 'name' => '卤菜'],
  92. ],
  93. 'activity' => [
  94. 'type' => ActivityType::FLASH_SALE,
  95. 'goods' => [
  96. [
  97. 'id' => 1,
  98. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  99. 'name' => '【优质】大白菜',
  100. 'spec' => [
  101. ['key' => '净含量', 'value' => '500g']
  102. ],
  103. 'original_price' => 50.5,
  104. 'price' => 25.25,
  105. 'inventory' => 0,
  106. 'month_sales' => 20,
  107. 'total_sales' => 20,
  108. 'cart_num' => 0,
  109. 'is_effective' => 1,
  110. 'noneffective_note' => '已抢光',
  111. 'total_seconds' => $seconds,
  112. 'days' => $days,
  113. 'hours' => $hours,
  114. 'minutes' => $minutes,
  115. 'seconds' => $leftSeconds,
  116. ],[
  117. 'id' => 1,
  118. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  119. 'name' => '【优质】大白菜',
  120. 'spec' => [
  121. ['key' => '净含量', 'value' => '500g']
  122. ],
  123. 'original_price' => 50.5,
  124. 'price' => 25.25,
  125. 'inventory' => 0,
  126. 'month_sales' => 20,
  127. 'total_sales' => 20,
  128. 'cart_num' => 0,
  129. 'is_effective' => 1,
  130. 'noneffective_note' => '已抢光',
  131. 'total_seconds' => $seconds,
  132. 'days' => $days,
  133. 'hours' => $hours,
  134. 'minutes' => $minutes,
  135. 'seconds' => $leftSeconds,
  136. ],[
  137. 'id' => 1,
  138. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  139. 'name' => '【优质】大白菜',
  140. 'spec' => [
  141. ['key' => '净含量', 'value' => '500g']
  142. ],
  143. 'original_price' => 50.5,
  144. 'price' => 25.25,
  145. 'inventory' => 0,
  146. 'month_sales' => 20,
  147. 'total_sales' => 20,
  148. 'cart_num' => 0,
  149. 'is_effective' => 1,
  150. 'noneffective_note' => '已抢光',
  151. 'total_seconds' => $seconds,
  152. 'days' => $days,
  153. 'hours' => $hours,
  154. 'minutes' => $minutes,
  155. 'seconds' => $leftSeconds,
  156. ],[
  157. 'id' => 1,
  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. /**
  216. * 商家入口详情
  217. */
  218. public function storeIndex()
  219. {
  220. $data['detail'] = $this->storeInfoService->detail();
  221. $data['order_online'] = [
  222. 'count' => 6549,
  223. 'total' => 12654.12
  224. ];
  225. $data['order_offline'] = [
  226. 'count' => 3639,
  227. 'total' => 89563.12
  228. ];
  229. $data['new_user'] = [
  230. 'day' => 10,
  231. 'week' => 15,
  232. 'month' => 25,
  233. 'all' => 50
  234. ];
  235. $data['badge'] = [
  236. 'unpaid' => 0,
  237. 'receiving' => 0,
  238. 'completed' => 0,
  239. 'refund' => 0,
  240. ];
  241. return $this->success($data);
  242. }
  243. }