HomePageConfigController.php 3.7 KB

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