ItemController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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\item\classes\ItemClass;
  8. use bizMall\user\classes\UserClass;
  9. use common\components\imgUtil;
  10. use common\components\util;
  11. use Yii;
  12. class ItemController extends BaseController
  13. {
  14. public $guestAccess = ['show-info'];
  15. //散客查看花材详情 ssh 20230109
  16. public function actionGetMallItemInfo()
  17. {
  18. $get = Yii::$app->request->get();
  19. $id = $get['id'] ?? 0;
  20. $item = ItemClass::getById($id);
  21. $discountPrice = $item['discountPrice'] ?? 0;
  22. if ($discountPrice > 0) {
  23. $skMore = $item['skMore'] ?? 0;
  24. $skPrice = bcadd($skMore, $discountPrice, 2);
  25. $skPrice = floatval($skPrice);
  26. $item['skPrice'] = $skPrice;
  27. }
  28. $presell = $item['presell'] ?? 0;
  29. if ($presell == 1) {
  30. $preSellDate = $item['presellDate'] ?? '';
  31. $preSellDateShow = [];
  32. if (!empty($preSellDate)) {
  33. $dateArr = explode(',', trim($preSellDate));
  34. if (!empty($dateArr)) {
  35. foreach ($dateArr as $sellTime) {
  36. $showDate = date("n月j日", $sellTime);
  37. $preSellDateShow[] = $showDate;
  38. }
  39. }
  40. }
  41. $item['presellDateShow'] = $preSellDateShow;
  42. }
  43. $shortCover = $item['cover'] ?? '';
  44. $cover = imgUtil::groupImg($shortCover);
  45. $item['shortCover'] = $shortCover;
  46. $item['bigCover'] = $cover . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  47. $item['cover'] = $cover . "?x-oss-process=image/resize,m_fill,h_100,w_100";
  48. util::success(['info' => $item]);
  49. }
  50. //扫码看价格 ssh 20221008
  51. public function actionShowInfo()
  52. {
  53. $get = Yii::$app->request->get();
  54. $id = $get['id'] ?? 0;
  55. $item = ItemClass::getById($id, true);
  56. if (empty($item)) {
  57. util::stop('');
  58. }
  59. if (isset($item->discountPrice) && $item->discountPrice > 0) {
  60. $discountPrice = $item->discountPrice;
  61. $skMore = $item->skMore ?? 0;
  62. $addPrice = $item->addPrice ?? 0;
  63. $diff = bcsub($skMore, $addPrice, 2);
  64. if ($diff > 0) {
  65. $skPrice = bcadd($discountPrice, $diff, 2);
  66. $skPrice = floatval($skPrice);
  67. } else {
  68. $skPrice = floatval($discountPrice);
  69. }
  70. } else {
  71. $skPrice = $item->skPrice ?? 0;
  72. $skPrice = floatval($skPrice);
  73. }
  74. $name = $item->name ?? '';
  75. $classId = $item->classId ?? 0;
  76. $class = ItemClassClass::getById($classId, true);
  77. $className = $class->name ?? '';
  78. echo '<div style="font-size:80px;margin-top:80px;margin-left:60px;">' . $name . '</div>';
  79. echo '<div style="font-size:80px;margin-top:30px;margin-left:60px;color:red;">' . $skPrice . '元</div>';
  80. echo '<div style="font-size:60px;margin-top:50px;margin-left:60px;">' . $className . '</div>';
  81. }
  82. public function actionIndex()
  83. {
  84. $py = Yii::$app->request->get('py', '');
  85. //默认显示上架商品
  86. $status = Yii::$app->request->get('status', 1);
  87. //默认显示未删除商品
  88. $delStatus = Yii::$app->request->get('delStatus', 0);
  89. $shop = $this->shop;
  90. if (isset($shop->ptStyle) == false || $shop->ptStyle != 1) {
  91. util::fail('访问门店出错了');
  92. }
  93. //获取所有当前供货商的分类 (全部、常用)
  94. //根据分类组装分类下的花材信息
  95. //中央ID
  96. $classIds = ItemClassClass::getGhsItemClassAll($this->mainId);
  97. $where['mainId'] = $this->mainId;
  98. if ($py) {
  99. $pyName = strtolower($py);
  100. $where['py'] = $pyName;
  101. }
  102. if (!empty($status)) {
  103. $where['status'] = $status;
  104. }
  105. $where['delStatus'] = $delStatus;
  106. $where['frontHide'] = 0;
  107. $level = 0;
  108. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], "*");
  109. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  110. $data = ProductService::assembleData($classIds, $itemInfoData, true);
  111. CustomClass::buildRelation($this->shop, $this->user);
  112. util::success($data);
  113. }
  114. }