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.

76 lines
2.5 KiB

5 years ago
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. use App\Model\v3\Goods;
  6. /**
  7. * 推荐商品相关
  8. * Class GoodsRecommend
  9. * @package App\Controller\v3
  10. */
  11. class GoodsRecommendController extends BaseController
  12. {
  13. /**
  14. * 获取首页tabs推荐商品列表
  15. * 1、前端上传tab标识
  16. * 2、根据tab标识从Elasticsearch中获取商品IDs
  17. * 3、根据IDs获取商品数据
  18. * 4、返回数据,id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
  19. */
  20. public function getByTabsForAppletIndex()
  21. {
  22. $tab = $this->request->input('tab', '');
  23. $marketId = $this->request->input('market_id', 0);
  24. $page = $this->request->input('page', 1);
  25. $pagesize = $this->request->input('pagesize', 10);
  26. $builder = Goods::query()->with('store')->where('market_id', $marketId);
  27. switch ($tab) {
  28. case Tabs::APPLET_INDEX_RECOMMEND:
  29. $builder = $builder->orderBy('sales', 'desc');
  30. break;
  31. case Tabs::APPLET_INDEX_NEW:
  32. $builder = $builder->orderBy('created_at', 'desc');
  33. break;
  34. case Tabs::APPLET_INDEX_FRESH:
  35. $builder = $builder->orderBy('price', 'asc');
  36. break;
  37. case Tabs::APPLET_INDEX_OFFICE:
  38. $builder = $builder->whereIn('category_id', [142,146]);
  39. break;
  40. }
  41. $paginate = $builder->paginate($pagesize);
  42. $goods = $paginate->toArray();
  43. return $this->success(['has_more_pages' => $paginate->hasMorePages(), 'tab_data' => $goods['data']]);
  44. }
  45. /**
  46. * 获取推荐商品列表
  47. * 1、前端上传标识
  48. * recommend_search_goods
  49. * recommend_search_stores
  50. * recommend_user_index
  51. * 2、根据标识从Elasticsearch中获取商品IDs
  52. * 3、根据IDs获取商品数据
  53. * 4、返回数据,id、封面图、名称、原价、现价、库存、月销、tag、规格、购物车相关、商户id、商户avatar、商户名
  54. */
  55. public function getByTab()
  56. {
  57. $marketId = $this->request->input('market_id', 0);
  58. $goods = Goods::query()
  59. ->with(['store'])
  60. ->where('market_id', $marketId)
  61. ->inRandomOrder()
  62. ->limit(20)
  63. ->get()->toArray();
  64. return $this->success(['has_more_pages' => false, 'tab_data' => $goods]);
  65. }
  66. }