HdController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * 商城端花店接口:列表、详情、删除/恢复,以及首页展示模式。
  4. * mallApp 首页 recent 调用;home-mode 用于分阶段开放花店列表。
  5. */
  6. namespace mall\controllers;
  7. use bizHd\recharge\classes\RechargeShbClass;
  8. use bizHd\recharge\classes\RechargeSqClass;
  9. use bizMall\hd\classes\HdClass;
  10. use common\components\imgUtil;
  11. use common\components\util;
  12. use bizHd\custom\classes\CustomClass;
  13. use Yii;
  14. class HdController extends BaseController
  15. {
  16. public $guestAccess = ['list', 'info', 'home-mode'];
  17. /**
  18. * 首页展示模式:1 会员服务说明,0 花店列表。
  19. * 改 .env 的 MALL_HOME_MODE 即可切换,不必重发前端。
  20. */
  21. public function actionHomeMode()
  22. {
  23. $homeMode = HdClass::getHomeMode($this->userId);
  24. util::success(['homeMode' => $homeMode]);
  25. }
  26. public function actionRecover()
  27. {
  28. $get = Yii::$app->request->get();
  29. $id = $get['id'] ?? 0;
  30. $hd = HdClass::getById($id, true);
  31. if (empty($hd)) {
  32. util::fail('没有花店信息');
  33. }
  34. if ($hd['userId'] != $this->userId) {
  35. util::fail('不是你的店');
  36. }
  37. $hd->delStatus = 0;
  38. $hd->save();
  39. util::complete('已恢复');
  40. }
  41. public function actionDel()
  42. {
  43. $get = Yii::$app->request->get();
  44. $id = $get['id'] ?? 0;
  45. $hd = HdClass::getById($id, true);
  46. if (empty($hd)) {
  47. util::fail('没有花店信息');
  48. }
  49. if ($hd['userId'] != $this->userId) {
  50. util::fail('不是你的店');
  51. }
  52. $hd->delStatus = 1;
  53. $hd->save();
  54. util::complete('删除成功');
  55. }
  56. //花店详情 ssh 20250627
  57. public function actionDetail()
  58. {
  59. $get = Yii::$app->request->get();
  60. $id = $get['id'] ?? 0;
  61. $hd = HdClass::getById($id);
  62. if (empty($hd)) {
  63. util::fail('没有花店信息');
  64. }
  65. if ($hd['userId'] != $this->userId) {
  66. util::fail('不是你的店');
  67. }
  68. $shortAvatar = !empty($val['avatar']) ? $val['avatar'] : 'hhb_small.png';
  69. $smallAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  70. $bigAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  71. $hd['shortAvatar'] = $shortAvatar;
  72. $hd['smallAvatar'] = $smallAvatar;
  73. $hd['bigAvatar'] = $bigAvatar;
  74. util::success($hd);
  75. }
  76. //花店信息 ssh 20230111
  77. public function actionInfo()
  78. {
  79. $get = Yii::$app->request->get();
  80. $id = $get['id'] ?? 0;
  81. $user = $this->user;
  82. $shop = $this->shop;
  83. if (empty($user)) {
  84. $hd = [];
  85. if (!empty($shop)) {
  86. $sjName = $shop->merchantName ?? '';
  87. $name = $shop->shopName == '首店' ? $sjName : $sjName . ' ' . $shop->shopName;
  88. $hd = ['name' => $name];
  89. }
  90. $custom = [];
  91. util::success(['hd' => $hd, 'custom' => $custom]);
  92. } else {
  93. if (empty($id)) {
  94. $respond = CustomClass::buildRelation($shop, $user);
  95. $hd = $respond['hd'];
  96. $custom = $respond['custom'];
  97. } else {
  98. $hd = HdClass::getById($id, true);
  99. $customId = $hd->customId;
  100. $custom = \bizMall\custom\classes\CustomClass::getById($customId, true);
  101. }
  102. $itemType = '';
  103. $itemList = [];
  104. // 根据 xhShop 中的 `rechargeWeal`来选择返回快捷充值选项
  105. if ($shop->rechargeWeal == 1) {
  106. $itemType = 'money'; //送钱
  107. $weal = RechargeSqClass::getAllByCondition(['mainId' => $shop->mainId], 'recharge asc', '*', null, true);
  108. if (!empty($weal)) {
  109. foreach ($weal as $key => $val) {
  110. $recharge = floatval($val->recharge);
  111. $give = floatval($val->give);
  112. $itemList[] = ['recharge' => $recharge, 'give' => $give];
  113. }
  114. }
  115. } else if ($shop->rechargeWeal == 2 || $shop->rechargeWeal == 3) {
  116. $itemType = 'hb'; //送红包
  117. $itemList = RechargeShbClass::getList('*', ['shopId' => $shop->id]);
  118. }
  119. util::success(['hd' => $hd, 'custom' => $custom, 'itemType' => $itemType, 'itemList' => $itemList]);
  120. }
  121. }
  122. public function actionList()
  123. {
  124. $get = Yii::$app->request->get();
  125. $delStatus = $get['delStatus'] ?? 0;
  126. $userId = $this->userId;
  127. $respond = ['list' => [],'moreData'=>0,'totalNum'=>0,'totalPage'=>0];
  128. if ($userId > 0) {
  129. $mallUpgrading = getenv('MALL_UPGRADING') == false ? 0 : getenv('MALL_UPGRADING');
  130. if ($mallUpgrading == 1) {
  131. $allowShopAdminIdsStr = getenv('MALL_UPGRADE_ALLOW_USER_IDS') ?: '';
  132. $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
  133. if (!in_array($userId, $allowShopAdminIds)) {
  134. util::fail('系统升级中,稍后再试,编号:' . $userId);
  135. }
  136. }
  137. $where = [];
  138. $where['userId'] = $userId;
  139. $where['delStatus'] = $delStatus;
  140. $respond = HdClass::getHdList($where);
  141. }
  142. util::success($respond);
  143. }
  144. }