| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace mall\controllers;
- use bizHd\goods\classes\GoodsCategoryClass;
- use bizMall\goods\classes\GoodsClass;
- use bizMall\goods\classes\GoodsSettingClass;
- use bizMall\pictext\classes\PicTextGoodsClass;
- use bizMall\goods\classes\CategoryClass;
- use bizMall\pictext\classes\PicTextClass;
- use Yii;
- use common\components\util;
- /**
- * 商城商品接口
- * detail:允许游客浏览详情(需带 account 定位门店);加购/下单仍在前端弹登录
- */
- class GoodsController extends BaseController
- {
- /** 商品详情允许未登录读取,便于分享落地页浏览 */
- public $guestAccess = ['detail'];
- /**
- * 获取商品详情
- * GET /goods/detail?id=&account=&hdId=
- * 游客:不强制 custom,价格按散客/无会员价组装;customId 返回 0
- */
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id', 0);
- $shop = $this->shop;
- // 必须有店铺上下文,否则无法校验 mainId / 计价
- if (empty($shop) || empty($this->mainId)) {
- util::fail('访问门店出错了');
- }
- // 游客可浏览:custom 为空时 groupGoodsBaseInfo 按无会员价处理,不报「用户信息缺失」
- $custom = !empty($this->custom) ? $this->custom : [];
- $params = [];
- $goods = GoodsClass::getGoodsInfo($id, $shop, $custom, $params);
- if (empty($goods)) {
- util::fail('商品不存在');
- }
- if ($goods['mainId'] != $this->mainId) {
- util::fail('不是你的商品');
- }
- $goods = \bizHd\goods\classes\GoodsClass::appendUseCasesAndSpecs($goods, $this->mainId);
- // $setting = GoodsSettingClass::getByCondition(['mainId' => $this->mainId]);
- // $intro = $setting['goodsIntroduce'] ?? '';
- // $info['commonIntro'] = $intro;
- // 商品详情图文
- if (empty($goods['masterId'])) {
- $picTextGoodsId = $id;
- } else {
- $picTextGoodsId = $goods['masterId'];
- }
- $pixTextGoods = PicTextGoodsClass::getByCondition(['mainId' => $this->mainId, 'goodsId' => $picTextGoodsId], true);
- $goods['picTextGoods'] = $pixTextGoods;
- $categoryId = intval(Yii::$app->request->get('categoryId'));
- if ($categoryId <= 0 && $id > 0) {
- $categoryMap = GoodsCategoryClass::getGoodsHasCategoryIdsBatch([$picTextGoodsId]);
- $categoryIds = $categoryMap[$picTextGoodsId] ?? [];
- if (!empty($categoryIds)) {
- $categoryId = intval($categoryIds[0]);
- }
- }
- // 商品所属分类图文
- $goods['picText'] = [];
- $category = CategoryClass::getById($categoryId);
- if (!empty($category)) {
- $picTextId = $category['picTextId'];
- $picText = PicTextClass::getById($picTextId, true);
- $goods['picText'] = $picText;
- }
- $goods['customId'] = $this->customId ?: 0;
- util::success($goods);
- }
- }
|