| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace mall\controllers;
- use bizHd\homePageConfig\classes\HomePageConfigClass;
- use bizHd\homePageConfig\classes\HomePageDisplayClass;
- use bizHd\homePageConfig\classes\HomePageModuleClass;
- use bizMall\hd\classes\HdClass;
- use common\components\util;
- use mall\models\homePageConfig\GetSectionGoodsForm;
- use Yii;
- /**
- * 商城端首页配置读取接口
- * mallApp 通过 account(shopId) 获取配置,与 hd 管理端共用 Redis。
- * 具体的格式化/真实商品解析逻辑统一收敛在 HomePageDisplayClass,
- * 保证与 app-hd 的预览接口返回结构完全一致。
- */
- class HomePageConfigController extends BaseController
- {
- public $guestAccess = [
- 'get-banner',
- 'get-nav-grid',
- 'get-seckill',
- 'get-group-buy',
- 'get-hot',
- 'get-new',
- 'get-pull-goods',
- 'get-home',
- 'get-section-goods',
- ];
- /**
- * 一次拉取首页全部模块配置,便于 mallApp 首页组装
- */
- public function actionGetHome()
- {
- $mainId = intval($this->mainId);
- $shopId = intval($this->shopId);
- Yii::info('shopId: ' . $shopId);
- Yii::info('mainId: ' . $mainId);
- if ($shopId <= 0) {
- Yii::info('shopId不存在: ' . $shopId);
- }
- if ($mainId <= 0) {
- Yii::info('mainId不存在: ' . $mainId);
- // $hd = HdClass::getByCondition(['shopId'=>$this->shopId, 'userId'=>$this->userId]);
- if (empty($hd)) {
- // 客户不存在
- }
- }
- util::success(HomePageDisplayClass::buildHome($mainId, $this->requireShopId()));
- }
- public function actionGetBanner()
- {
- util::success(HomePageDisplayClass::formatBanner(HomePageConfigClass::getBanner($this->requireMainId(), $this->requireShopId())));
- }
- public function actionGetNavGrid()
- {
- util::success(HomePageDisplayClass::formatNavGrid(HomePageModuleClass::getNavGrid($this->requireMainId(), $this->requireShopId())));
- }
- public function actionGetSeckill()
- {
- util::success(HomePageDisplayClass::formatActivity(HomePageModuleClass::getSeckill($this->requireMainId(), $this->requireShopId(), true)));
- }
- public function actionGetGroupBuy()
- {
- util::success(HomePageDisplayClass::formatActivity(HomePageModuleClass::getGroupBuy($this->requireMainId(), $this->requireShopId(), true)));
- }
- public function actionGetHot()
- {
- util::success(HomePageDisplayClass::formatGoodsSection($this->requireMainId(), $this->requireShopId(), 'hot'));
- }
- public function actionGetNew()
- {
- util::success(HomePageDisplayClass::formatGoodsSection($this->requireMainId(), $this->requireShopId(), 'new'));
- }
- public function actionGetPullGoods()
- {
- util::success(HomePageDisplayClass::formatGoodsSection($this->requireMainId(), $this->requireShopId(), 'pullGoods'));
- }
- /**
- * 首页模块「更多」商品列表分页
- * moduleKey: seckill|groupBuy|hot|new|pullGoods
- */
- public function actionGetSectionGoods()
- {
- $form = new GetSectionGoodsForm();
- $form->loadAndValidate();
- util::success(HomePageDisplayClass::getSectionGoodsPage(
- $this->requireMainId(),
- $this->requireShopId(),
- $form->moduleKey,
- (int)$form->page,
- (int)$form->pageSize
- ));
- }
- private function requireMainId()
- {
- $mainId = intval($this->mainId);
- if ($mainId <= 0) {
- util::fail('无效mainId');
- }
- return $mainId;
- }
- private function requireShopId()
- {
- $shopId = intval($this->shopId);
- if ($shopId <= 0) {
- util::fail('无效门店');
- }
- return $shopId;
- }
- }
|