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.

227 lines
9.0 KiB

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