ItemController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace mall\controllers;
  3. use bizGhs\item\classes\ItemClassClass;
  4. use bizGhs\product\classes\ProductClass;
  5. use bizGhs\product\services\ProductService;
  6. use bizHd\custom\classes\CustomClass;
  7. use bizMall\pictext\classes\PicTextGhsItemClass;
  8. use bizMall\item\classes\ItemClass;
  9. use common\components\imgUtil;
  10. use common\components\util;
  11. use Yii;
  12. class ItemController extends BaseController
  13. {
  14. /** 游客可看:扫码价、分类列表、花材详情;加购/购买由前端按需登录 */
  15. public $guestAccess = ['show-info', 'index', 'get-mall-item-info'];
  16. public function actionAll()
  17. {
  18. $where = [];
  19. $where['mainId'] = $this->mainId;
  20. $classId = Yii::$app->request->get('classId', 0);
  21. if (!empty($classId)) {
  22. $where['classId'] = $classId;
  23. }
  24. $status = Yii::$app->request->get('status', 0);
  25. if (!empty($status)) {
  26. $where['status'] = $status;
  27. }
  28. $delStatus = Yii::$app->request->get('delStatus', 0);
  29. if ($delStatus != 2) {
  30. $where['delStatus'] = $delStatus;
  31. }
  32. //输出标准会员价,即批发价,默认显示的是批发价
  33. $level = 0;
  34. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  35. $data = ProductClass::groupProductInfo($data, $level);
  36. util::success(['list' => $data]);
  37. }
  38. /**
  39. * 散客/游客查看花材详情(guestAccess:get-mall-item-info)
  40. * 不强制登录;加购、购买、购物车由前端弹 wangCg 后再调需登录接口
  41. */
  42. public function actionGetMallItemInfo()
  43. {
  44. $get = Yii::$app->request->get();
  45. $id = $get['id'] ?? 0;
  46. $item = ItemClass::getById($id);
  47. $discountPrice = $item['discountPrice'] ?? 0;
  48. if ($discountPrice > 0) {
  49. $skDiscountPrice = $item['skDiscountPrice'] ?? 0;
  50. $item['skPrice'] = $skDiscountPrice;
  51. }
  52. $presell = $item['presell'] ?? 0;
  53. if ($presell == 1) {
  54. $preSellDate = $item['presellDate'] ?? '';
  55. $preSellDateShow = [];
  56. if (!empty($preSellDate)) {
  57. $dateArr = explode(',', trim($preSellDate));
  58. if (!empty($dateArr)) {
  59. foreach ($dateArr as $sellTime) {
  60. $showDate = date("n.j", $sellTime);
  61. $preSellDateShow[] = $showDate;
  62. }
  63. }
  64. }
  65. $item['presellDateShow'] = $preSellDateShow;
  66. }
  67. $shortCover = $item['cover'] ?? '';
  68. $cover = imgUtil::groupImg($shortCover);
  69. $item['shortCover'] = $shortCover;
  70. $item['bigCover'] = $cover . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  71. $item['cover'] = $cover . "?x-oss-process=image/resize,m_fill,h_100,w_100";
  72. $pixTextGoods = PicTextGhsItemClass::getByCondition(['mainId' => $item['mainId'], 'ghsItemId' => $id], true);
  73. $item['picTextGoods'] = $pixTextGoods;
  74. // 封面图与多花材图片的兼容处理
  75. if ($item['images'] == '' && $item['shortCover'] != '') {
  76. $item['images'] = $item['shortCover'];
  77. }
  78. util::success(['info' => $item]);
  79. }
  80. //扫码看价格 ssh 20221008
  81. public function actionShowInfo()
  82. {
  83. $get = Yii::$app->request->get();
  84. $id = $get['id'] ?? 0;
  85. $item = ItemClass::getById($id, true);
  86. if (empty($item)) {
  87. util::stop('');
  88. }
  89. if (isset($item->skDiscountPrice) && $item->skDiscountPrice > 0) {
  90. $skPrice = $item->skDiscountPrice;
  91. } else {
  92. $skPrice = $item->skPrice ?? 0;
  93. }
  94. $skPrice = floatval($skPrice);
  95. $name = $item->name ?? '';
  96. $classId = $item->classId ?? 0;
  97. $class = ItemClassClass::getById($classId, true);
  98. $className = $class->name ?? '';
  99. echo '<div style="font-size:80px;margin-top:80px;margin-left:60px;">' . $name . '</div>';
  100. echo '<div style="font-size:80px;margin-top:30px;margin-left:60px;color:red;">' . $skPrice . '元</div>';
  101. echo '<div style="font-size:60px;margin-top:50px;margin-left:60px;">' . $className . '</div>';
  102. }
  103. /**
  104. * 花材分类+商品(商城分类页)
  105. * 游客可浏览:guestAccess 含 index;无店铺或非零售店直接失败/空;buildRelation 对空 user 不建客
  106. */
  107. public function actionIndex()
  108. {
  109. $py = Yii::$app->request->get('py', '');
  110. //默认显示上架商品
  111. $status = Yii::$app->request->get('status', 1);
  112. //默认显示未删除商品
  113. $delStatus = Yii::$app->request->get('delStatus', 0);
  114. $shop = $this->shop;
  115. // 未登录时若未带 account,shop 为空;避免对 null 取 ptStyle 报错
  116. if (empty($shop) || !isset($shop->ptStyle) || $shop->ptStyle != 1) {
  117. util::fail('访问门店出错了');
  118. }
  119. if (empty($this->mainId)) {
  120. util::success([]);
  121. }
  122. //普莲花艺、叶上花、丰行、小武鲜花、九江云朵、源花汇、紫荆不能在花卉宝下单,多处要同步修改,关键词ls_mall_not_open
  123. $mainId = $this->mainId;
  124. if (getenv('YII_ENV') == 'production') {
  125. if (in_array($mainId, [40057, 7779, 42940, 26374, 10536, 65381])) {
  126. util::fail('暂时无法访问');
  127. }
  128. } else {
  129. if (in_array($mainId, [0, 1])) {
  130. util::fail('暂时无法访问');
  131. }
  132. }
  133. //获取所有当前供货商的分类 (全部、常用)
  134. //根据分类组装分类下的花材信息
  135. //中央ID
  136. $classIds = ItemClassClass::getGhsItemClassAll($this->mainId);
  137. $where['mainId'] = $this->mainId;
  138. if ($py) {
  139. $pyName = strtolower($py);
  140. $where['py'] = $pyName;
  141. }
  142. if (!empty($status)) {
  143. $where['status'] = $status;
  144. }
  145. $where['delStatus'] = $delStatus;
  146. //批发端没有隐藏
  147. //$where['frontHide'] = 0;
  148. //零售端没有隐藏
  149. $where['frontUse'] = 0;
  150. // level=0:游客/无会员用标准批发价展示,不依赖 custom
  151. $level = 0;
  152. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*");
  153. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  154. $respond = ProductService::assembleData($classIds, $itemInfoData, true);
  155. $data = $respond['classItem'] ?? [];
  156. CustomClass::buildRelation($this->shop, $this->user);
  157. util::success($data);
  158. }
  159. }