HomePageConfigController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. if ($shopId <= 0) {
  37. Yii::info('shopId: ' . $shopId);
  38. }
  39. if ($mainId <= 0) {
  40. Yii::info('mainId: ' . $mainId);
  41. // $hd = HdClass::getByCondition(['shopId'=>$this->shopId, 'userId'=>$this->userId]);
  42. if (empty($hd)) {
  43. // 客户不存在
  44. }
  45. }
  46. util::success(HomePageDisplayClass::buildHome($mainId, $this->requireShopId()));
  47. }
  48. public function actionGetBanner()
  49. {
  50. util::success(HomePageDisplayClass::formatBanner(HomePageConfigClass::getBanner($this->requireMainId(), $this->requireShopId())));
  51. }
  52. public function actionGetNavGrid()
  53. {
  54. util::success(HomePageDisplayClass::formatNavGrid(HomePageModuleClass::getNavGrid($this->requireMainId(), $this->requireShopId())));
  55. }
  56. public function actionGetSeckill()
  57. {
  58. util::success(HomePageDisplayClass::formatActivity(HomePageModuleClass::getSeckill($this->requireMainId(), $this->requireShopId(), true)));
  59. }
  60. public function actionGetGroupBuy()
  61. {
  62. util::success(HomePageDisplayClass::formatActivity(HomePageModuleClass::getGroupBuy($this->requireMainId(), $this->requireShopId(), true)));
  63. }
  64. public function actionGetHot()
  65. {
  66. util::success(HomePageDisplayClass::formatGoodsSection($this->requireMainId(), $this->requireShopId(), 'hot'));
  67. }
  68. public function actionGetNew()
  69. {
  70. util::success(HomePageDisplayClass::formatGoodsSection($this->requireMainId(), $this->requireShopId(), 'new'));
  71. }
  72. public function actionGetPullGoods()
  73. {
  74. util::success(HomePageDisplayClass::formatGoodsSection($this->requireMainId(), $this->requireShopId(), 'pullGoods'));
  75. }
  76. /**
  77. * 首页模块「更多」商品列表分页
  78. * moduleKey: seckill|groupBuy|hot|new|pullGoods
  79. */
  80. public function actionGetSectionGoods()
  81. {
  82. $form = new GetSectionGoodsForm();
  83. $form->loadAndValidate();
  84. util::success(HomePageDisplayClass::getSectionGoodsPage(
  85. $this->requireMainId(),
  86. $this->requireShopId(),
  87. $form->moduleKey,
  88. (int)$form->page,
  89. (int)$form->pageSize
  90. ));
  91. }
  92. private function requireMainId()
  93. {
  94. $mainId = intval($this->mainId);
  95. if ($mainId <= 0) {
  96. util::fail('无效mainId');
  97. }
  98. return $mainId;
  99. }
  100. private function requireShopId()
  101. {
  102. $shopId = intval($this->shopId);
  103. if ($shopId <= 0) {
  104. util::fail('无效门店');
  105. }
  106. return $shopId;
  107. }
  108. }