GoodsController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace mall\controllers;
  3. use bizHd\goods\classes\GoodsCategoryClass;
  4. use bizMall\goods\classes\GoodsClass;
  5. use bizMall\goods\classes\GoodsSettingClass;
  6. use bizMall\pictext\classes\PicTextGoodsClass;
  7. use bizMall\goods\classes\CategoryClass;
  8. use bizMall\pictext\classes\PicTextClass;
  9. use Yii;
  10. use common\components\util;
  11. class GoodsController extends BaseController
  12. {
  13. //获取商品详情 ssh 2019.12.3
  14. public function actionDetail()
  15. {
  16. $id = Yii::$app->request->get('id', 0);
  17. $custom = $this->custom;
  18. if (empty($custom)) {
  19. util::fail('用户信息缺失');
  20. }
  21. $shop = $this->shop;
  22. $params = [];
  23. $goods = GoodsClass::getGoodsInfo($id, $shop, $custom, $params);
  24. if ($goods['mainId'] != $this->mainId) {
  25. util::fail('不是你的商品');
  26. }
  27. $goods = \bizHd\goods\classes\GoodsClass::appendUseCasesAndSpecs($goods, $this->mainId);
  28. // $setting = GoodsSettingClass::getByCondition(['mainId' => $this->mainId]);
  29. // $intro = $setting['goodsIntroduce'] ?? '';
  30. // $info['commonIntro'] = $intro;
  31. // 商品详情图文
  32. if (empty($goods['masterId'])) {
  33. $picTextGoodsId = $id;
  34. } else {
  35. $picTextGoodsId = $goods['masterId'];
  36. }
  37. $pixTextGoods = PicTextGoodsClass::getByCondition(['mainId' => $this->mainId, 'goodsId' => $picTextGoodsId], true);
  38. $goods['picTextGoods'] = $pixTextGoods;
  39. $categoryId = intval(Yii::$app->request->get('categoryId'));
  40. if ($categoryId <= 0 && $id > 0) {
  41. $categoryMap = GoodsCategoryClass::getGoodsHasCategoryIdsBatch([$picTextGoodsId]);
  42. $categoryIds = $categoryMap[$picTextGoodsId] ?? [];
  43. if (!empty($categoryIds)) {
  44. $categoryId = intval($categoryIds[0]);
  45. }
  46. }
  47. // 商品所属分类图文
  48. $goods['picText'] = [];
  49. $category = CategoryClass::getById($categoryId);
  50. if (!empty($category)) {
  51. $picTextId = $category['picTextId'];
  52. $picText = PicTextClass::getById($picTextId, true);
  53. $goods['picText'] = $picText;
  54. }
  55. $goods['customId'] = $this->customId;
  56. util::success($goods);
  57. }
  58. }