HomePageConfigController.php 3.5 KB

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