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.

240 lines
9.4 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\Tabs;
  4. use App\Controller\BaseController;
  5. use App\Model\v3\Goods;
  6. /**
  7. * 推荐商品相关
  8. * Class GoodsRecommend
  9. * @package App\Controller\v3
  10. */
  11. class GoodsRecommendController extends BaseController
  12. {
  13. protected $data;
  14. public function __construct()
  15. {
  16. $this->data = [
  17. [
  18. 'goods' => [
  19. 'id' => 1,
  20. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  21. 'name' => '【优质】大白菜11',
  22. 'spec' => [
  23. ['key' => '净含量', 'value' => '500g']
  24. ],
  25. 'tags' => ['限时', '折扣'],
  26. 'original_price' => 50.5,
  27. 'price' => 25.25,
  28. 'inventory' => 10,
  29. 'month_sales' => 20,
  30. 'total_sales' => 20,
  31. 'cart_num' => 0,
  32. 'is_effective' => 2,
  33. 'noneffective_note' => '已卖完',
  34. 'store' => ['id' => 1, 'logo' => '', 'name' => '我是一个商家']
  35. ],
  36. ],
  37. [
  38. 'goods' => [
  39. 'id' => 2,
  40. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  41. 'name' => '【优质】大白菜11',
  42. 'spec' => [
  43. ['key' => '净含量', 'value' => '500g']
  44. ],
  45. 'tags' => ['限时', '折扣'],
  46. 'original_price' => 50.5,
  47. 'price' => 25.25,
  48. 'inventory' => 10,
  49. 'month_sales' => 20,
  50. 'total_sales' => 20,
  51. 'cart_num' => 0,
  52. 'is_effective' => 2,
  53. 'noneffective_note' => '已卖完',
  54. 'store' => ['id' => 222, 'logo' => '', 'name' => '我是一个商家222']
  55. ],
  56. ],
  57. [
  58. 'goods' => [
  59. 'id' => 3,
  60. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  61. 'name' => '【优质】大白菜11',
  62. 'spec' => [
  63. ['key' => '净含量', 'value' => '500g']
  64. ],
  65. 'tags' => ['限时', '折扣'],
  66. 'original_price' => 50.5,
  67. 'price' => 25.25,
  68. 'inventory' => 10,
  69. 'month_sales' => 20,
  70. 'total_sales' => 20,
  71. 'cart_num' => 0,
  72. 'is_effective' => 2,
  73. 'noneffective_note' => '已卖完',
  74. 'store' => ['id' => 2, 'logo' => '', 'name' => '我是一个商家333']
  75. ],
  76. ],
  77. [
  78. 'goods' => [
  79. 'id' => 4,
  80. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  81. 'name' => '【优质】大白菜11',
  82. 'spec' => [
  83. ['key' => '净含量', 'value' => '500g']
  84. ],
  85. 'tags' => ['限时', '折扣'],
  86. 'original_price' => 50.5,
  87. 'price' => 25.25,
  88. 'inventory' => 10,
  89. 'month_sales' => 20,
  90. 'total_sales' => 20,
  91. 'cart_num' => 0,
  92. 'is_effective' => 2,
  93. 'noneffective_note' => '已卖完',
  94. ],
  95. 'store' => ['id' => 3, 'logo' => '', 'name' => '我是一个商家444']
  96. ]
  97. ];
  98. parent::__construct();
  99. }
  100. /**
  101. * 获取首页tabs推荐商品列表
  102. * 1、前端上传tab标识
  103. * 2、根据tab标识从Elasticsearch中获取商品IDs
  104. * 3、根据IDs获取商品数据
  105. * 4、返回数据,id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
  106. */
  107. public function getByTabsForAppletIndex()
  108. {
  109. $tabsData = [
  110. Tabs::APPLET_INDEX_RECOMMEND => [
  111. [
  112. 'goods' => [
  113. 'id' => 1,
  114. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  115. 'name' => '【优质】大白菜11',
  116. 'spec' => [
  117. ['key' => '净含量', 'value' => '500g']
  118. ],
  119. 'tags' => ['限时', '折扣'],
  120. 'original_price' => 50.5,
  121. 'price' => 25.25,
  122. 'inventory' => 10,
  123. 'month_sales' => 20,
  124. 'total_sales' => 20,
  125. 'cart_num' => 0,
  126. 'is_effective' => 2,
  127. 'noneffective_note' => '已卖完',
  128. ],
  129. 'store' => ['id' => 1, 'logo' => '', 'name' => '我是一个商家']
  130. ],
  131. ],
  132. Tabs::APPLET_INDEX_NEW => [
  133. [
  134. 'goods' => [
  135. 'id' => 2,
  136. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  137. 'name' => '【优质】大白菜11',
  138. 'spec' => [
  139. ['key' => '净含量', 'value' => '500g']
  140. ],
  141. 'tags' => ['限时', '折扣'],
  142. 'original_price' => 50.5,
  143. 'price' => 25.25,
  144. 'inventory' => 10,
  145. 'month_sales' => 20,
  146. 'total_sales' => 20,
  147. 'cart_num' => 0,
  148. 'is_effective' => 2,
  149. 'noneffective_note' => '已卖完',
  150. ],
  151. 'store' => ['id' => 2, 'logo' => '', 'name' => '我是一个商家222']
  152. ],
  153. ],
  154. Tabs::APPLET_INDEX_FRESH => [
  155. [
  156. 'goods' => [
  157. 'id' => 3,
  158. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  159. 'name' => '【优质】大白菜11',
  160. 'spec' => [
  161. ['key' => '净含量', 'value' => '500g']
  162. ],
  163. 'tags' => ['限时', '折扣'],
  164. 'original_price' => 50.5,
  165. 'price' => 25.25,
  166. 'inventory' => 10,
  167. 'month_sales' => 20,
  168. 'total_sales' => 20,
  169. 'cart_num' => 0,
  170. 'is_effective' => 2,
  171. 'noneffective_note' => '已卖完',
  172. ],
  173. 'store' => ['id' => 3, 'logo' => '', 'name' => '我是一个商家333']
  174. ],
  175. ],
  176. Tabs::APPLET_INDEX_OFFICE => [
  177. [
  178. 'goods' => [
  179. 'id' => 4,
  180. 'cover_img' => config('alioss.img_host').'/attachment/types/c9b656181bbbc463624ca3803c5be7539f2fd62253f9a-cwVLri.png',
  181. 'name' => '【优质】大白菜11',
  182. 'spec' => [
  183. ['key' => '净含量', 'value' => '500g']
  184. ],
  185. 'tags' => ['限时', '折扣'],
  186. 'original_price' => 50.5,
  187. 'price' => 25.25,
  188. 'inventory' => 10,
  189. 'month_sales' => 20,
  190. 'total_sales' => 20,
  191. 'cart_num' => 0,
  192. 'is_effective' => 2,
  193. 'noneffective_note' => '已卖完',
  194. ],
  195. 'store' => ['id' => 4, 'logo' => '', 'name' => '我是一个商家444']
  196. ],
  197. ]
  198. ];
  199. $goods = Goods::query()
  200. ->with(['store'])
  201. ->forPage($this->request->input('page', 1), $this->request->input('pagesize', 15))
  202. ->get()->toArray();
  203. return $this->success(['tab_data' => $goods]);
  204. return $this->success([
  205. 'tab_data' => $tabsData[$this->request->post('tab', 'applet_index_recommend')]
  206. ]);
  207. }
  208. /**
  209. * 获取搜索页推荐商品列表
  210. * 1、前端上传标识
  211. * recommend_search_goods
  212. * recommend_search_stores
  213. * recommend_user_index
  214. * 2、根据标识从Elasticsearch中获取商品IDs
  215. * 3、根据IDs获取商品数据
  216. * 4、返回数据,id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
  217. */
  218. public function getByTab()
  219. {
  220. $goods = Goods::query()
  221. ->with(['store'])
  222. ->limit(6)
  223. ->get()->toArray();
  224. return $this->success(['tab_data' => $goods]);
  225. }
  226. }