HomePageConfigController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace mall\controllers;
  3. use bizHd\homePageConfig\classes\HomePageConfigClass;
  4. use bizHd\homePageConfig\classes\HomePageDisplayClass;
  5. use bizHd\homePageConfig\classes\HomePageModuleClass;
  6. use common\components\util;
  7. use mall\models\homePageConfig\GetSectionGoodsForm;
  8. /**
  9. * 商城端首页配置读取接口
  10. * mallApp 通过 account(shopId) 获取配置,与 hd 管理端共用 Redis。
  11. * 具体的格式化/真实商品解析逻辑统一收敛在 HomePageDisplayClass,
  12. * 保证与 app-hd 的预览接口返回结构完全一致。
  13. */
  14. class HomePageConfigController extends BaseController
  15. {
  16. public $guestAccess = [
  17. 'get-banner',
  18. 'get-nav-grid',
  19. 'get-seckill',
  20. 'get-group-buy',
  21. 'get-hot',
  22. 'get-new',
  23. 'get-pull-goods',
  24. 'get-home',
  25. 'get-section-goods',
  26. ];
  27. /**
  28. * 一次拉取首页全部模块配置,便于 mallApp 首页组装
  29. */
  30. public function actionGetHome()
  31. {
  32. util::success(HomePageDisplayClass::buildHome($this->requireMainId(), $this->requireShopId()));
  33. }
  34. public function actionGetBanner()
  35. {
  36. util::success(HomePageDisplayClass::formatBanner(HomePageConfigClass::getBanner($this->requireMainId(), $this->requireShopId())));
  37. }
  38. public function actionGetNavGrid()
  39. {
  40. util::success(HomePageDisplayClass::formatNavGrid(HomePageModuleClass::getNavGrid($this->requireMainId(), $this->requireShopId())));
  41. }
  42. public function actionGetSeckill()
  43. {
  44. util::success(HomePageDisplayClass::formatActivity(HomePageModuleClass::getSeckill($this->requireMainId(), $this->requireShopId(), true)));
  45. }
  46. public function actionGetGroupBuy()
  47. {
  48. util::success(HomePageDisplayClass::formatActivity(HomePageModuleClass::getGroupBuy($this->requireMainId(), $this->requireShopId(), true)));
  49. }
  50. public function actionGetHot()
  51. {
  52. util::success(HomePageDisplayClass::formatGoodsSection($this->requireMainId(), $this->requireShopId(), 'hot'));
  53. }
  54. public function actionGetNew()
  55. {
  56. util::success(HomePageDisplayClass::formatGoodsSection($this->requireMainId(), $this->requireShopId(), 'new'));
  57. }
  58. public function actionGetPullGoods()
  59. {
  60. util::success(HomePageDisplayClass::formatGoodsSection($this->requireMainId(), $this->requireShopId(), 'pullGoods'));
  61. }
  62. /**
  63. * 首页模块「更多」商品列表分页
  64. * moduleKey: seckill|groupBuy|hot|new|pullGoods
  65. */
  66. public function actionGetSectionGoods()
  67. {
  68. $form = new GetSectionGoodsForm();
  69. $form->loadAndValidate();
  70. util::success(HomePageDisplayClass::getSectionGoodsPage(
  71. $this->requireMainId(),
  72. $this->requireShopId(),
  73. $form->moduleKey,
  74. (int)$form->page,
  75. (int)$form->pageSize
  76. ));
  77. }
  78. private function requireMainId()
  79. {
  80. $mainId = intval($this->mainId);
  81. if ($mainId <= 0) {
  82. util::fail('无效mainId');
  83. }
  84. return $mainId;
  85. }
  86. private function requireShopId()
  87. {
  88. $shopId = intval($this->shopId);
  89. if ($shopId <= 0) {
  90. util::fail('无效门店');
  91. }
  92. return $shopId;
  93. }
  94. }