ShopController.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. namespace mall\controllers;
  3. use biz\shop\classes\ShopExtClass;
  4. use bizHd\stat\classes\StatVisitClass;
  5. use bizHd\custom\classes\CustomClass;
  6. use bizHd\custom\classes\HdClass;
  7. use bizMall\invite\services\InviteService;
  8. use bizMall\user\services\UserService;
  9. use common\components\dict;
  10. use common\components\imgUtil;
  11. use Yii;
  12. use common\components\util;
  13. class ShopController extends BaseController
  14. {
  15. public $guestAccess = ['info', 'search', 'recommend'];
  16. /**
  17. * 未登录首页「推荐花店」:内容后端写死,按 YII_ENV 区分测试/正式
  18. * 返回 shopId、名称、地址、营业时间、封面完整 URL;进店用 account=shopId
  19. */
  20. public function actionRecommend()
  21. {
  22. $isProd = getenv('YII_ENV') === 'production';
  23. // 测试 / 正式各写死 3 家;shopId 请换成真实 xhShop.id(ptStyle=1)
  24. $rows = $isProd
  25. ? [
  26. [
  27. 'shopId' => 2,
  28. 'name' => '龙岩花掌柜',
  29. 'address' => '龙岩市交易城C区',
  30. 'businessHours' => '09:00-22:00',
  31. 'cover' => 'hhb/images/guest/shop1.jpg',
  32. ],
  33. [
  34. 'shopId' => 501,
  35. 'name' => '楼兰花艺',
  36. 'address' => '厦门市集美区凤林前山路147号',
  37. 'businessHours' => '09:00-22:00',
  38. 'cover' => 'shop/wsf_ll.png',
  39. ]
  40. ]
  41. : [
  42. [
  43. 'shopId' => 36523,
  44. 'name' => '好运鲜花批发',
  45. 'address' => '厦门市集美区凤林前山路147号',
  46. 'businessHours' => '09:00-22:00',
  47. 'cover' => 'hhb/images/guest/shop1.jpg',
  48. ],
  49. [
  50. 'shopId' => 37064,
  51. 'name' => '楼兰鲜花',
  52. 'address' => '福州市仓山区浦上大道339-30号',
  53. 'businessHours' => '09:00-22:00',
  54. 'cover' => 'hhb/images/guest/shop2.jpg',
  55. ],
  56. [
  57. 'shopId' => 36548,
  58. 'name' => '花夕花艺',
  59. 'address' => '漳州市龙海区鸿江路15号',
  60. 'businessHours' => '09:00-22:00',
  61. 'cover' => 'hhb/images/guest/shop3.jpg',
  62. ]
  63. ];
  64. $list = [];
  65. foreach ($rows as $row) {
  66. $shopId = (int)($row['shopId'] ?? 0);
  67. $list[] = [
  68. 'shopId' => $shopId,
  69. 'account' => $shopId,
  70. 'id' => $shopId,
  71. 'name' => (string)($row['name'] ?? ''),
  72. 'address' => (string)($row['address'] ?? ''),
  73. 'businessHours' => (string)($row['businessHours'] ?? ''),
  74. 'cover' => imgUtil::groupImg($row['cover'] ?? ''),
  75. 'avatar' => imgUtil::groupImg($row['cover'] ?? ''),
  76. ];
  77. }
  78. util::success([
  79. 'banner' => imgUtil::groupImg('hhb/images/guest/banner.jpg'),
  80. 'list' => $list,
  81. ]);
  82. }
  83. /**
  84. * 未登录首页按花店名称搜索(xhShop.ptStyle=1 零售花店)
  85. * 仅匹配 shopName / merchantName,不按城市搜
  86. */
  87. public function actionSearch()
  88. {
  89. $keyword = trim((string)Yii::$app->request->get('keyword', ''));
  90. if ($keyword === '') {
  91. util::success(['list' => []]);
  92. }
  93. // 限制长度,避免超长 like 拖垮查询
  94. if (mb_strlen($keyword) > 30) {
  95. $keyword = mb_substr($keyword, 0, 30);
  96. }
  97. $ptStyle = (int)dict::getDict('ptStyle', 'hd'); // 1=零售花店
  98. $rows = \biz\shop\models\Shop::find()
  99. ->select(['id', 'shopName', 'merchantName', 'city', 'address', 'floor', 'avatar', 'openStartTime', 'openEndTime', 'open'])
  100. ->where(['ptStyle' => $ptStyle])
  101. ->andWhere([
  102. 'or',
  103. ['like', 'shopName', $keyword],
  104. ['like', 'merchantName', $keyword],
  105. ])
  106. ->orderBy(['id' => SORT_DESC])
  107. ->limit(30)
  108. ->asArray()
  109. ->all();
  110. $list = [];
  111. foreach ($rows as $row) {
  112. $shopName = trim((string)($row['shopName'] ?? ''));
  113. $merchantName = trim((string)($row['merchantName'] ?? ''));
  114. // 展示名:首店只显示商家名,否则「商家名 店名」
  115. $name = ($shopName === '' || $shopName === '首店')
  116. ? ($merchantName !== '' ? $merchantName : $shopName)
  117. : ($merchantName !== '' ? ($merchantName . ' ' . $shopName) : $shopName);
  118. $avatarShort = $row['avatar'] ?? '';
  119. $start = trim((string)($row['openStartTime'] ?? ''));
  120. $end = trim((string)($row['openEndTime'] ?? ''));
  121. $hours = '';
  122. if ($start !== '' && $end !== '') {
  123. $hours = $start . '-' . $end;
  124. }
  125. $list[] = [
  126. 'id' => (int)$row['id'],
  127. 'account' => (int)$row['id'],
  128. 'name' => $name,
  129. 'address' => trim(($row['city'] ?? '') . ($row['address'] ?? '') . ($row['floor'] ?? '')),
  130. 'avatar' => empty($avatarShort)
  131. ? ''
  132. : imgUtil::groupImg($avatarShort) . '?x-oss-process=image/resize,m_fill,h_200,w_200',
  133. 'businessHours' => $hours,
  134. 'open' => isset($row['open']) ? (int)$row['open'] : 1,
  135. ];
  136. }
  137. util::success(['list' => $list]);
  138. }
  139. //门店详情 ssh 20230210
  140. public function actionInfo()
  141. {
  142. $get = Yii::$app->request->get();
  143. $hdId = $get['hdId'] ?? 0;
  144. $shop = $this->shop;
  145. $info = !empty($shop) ? $shop->attributes : [];
  146. if (isset($info['superWx'])) {
  147. $superWx = $info['superWx'];
  148. $info['superWx'] = imgUtil::groupImg($superWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  149. } else {
  150. $info['superWx'] = '';
  151. }
  152. $shortAvatar = $info['avatar'] ?? '';
  153. $avatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_300,w_300";
  154. $info['avatar'] = $avatar;
  155. $info['shortAvatar'] = $shortAvatar;
  156. // 合并 xhShopExt 客服电话/微信二维码,供商城客服页展示与拨号
  157. $ext = !empty($shop) ? ShopExtClass::getByCondition(['shopId' => $shop->id], true) : null;
  158. $shortServiceWx = !empty($ext) ? ($ext->serviceWx ?? '') : '';
  159. $info['serviceMobile'] = !empty($ext) ? ($ext->serviceMobile ?? '') : '';
  160. $info['shortServiceWx'] = $shortServiceWx;
  161. $info['serviceWx'] = empty($shortServiceWx)
  162. ? ''
  163. : imgUtil::groupImg($shortServiceWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  164. $user = $this->user;
  165. $hd = [];
  166. $custom = [];
  167. $inviteBound = 0;
  168. if (!empty($user)) {
  169. if (empty($hdId)) {
  170. $inviterCustomId = isset($get['inviterCustomId']) ? (int)$get['inviterCustomId'] : 0;
  171. $respond = CustomClass::buildRelation($shop, $user, $inviterCustomId);
  172. $hd = $respond['hd'];
  173. $custom = $respond['custom'];
  174. $inviteBound = !empty($respond['inviteBound']) ? (int)$respond['inviteBound'] : 0;
  175. } else {
  176. $hd = HdClass::getById($hdId, true);
  177. if (!empty($hd)) {
  178. $customId = $hd->customId;
  179. $custom = CustomClass::getById($customId, true);
  180. if (!empty($custom)) {
  181. $custom->visitTime = date("Y-m-d H:i:s");
  182. $custom->save();
  183. }
  184. }
  185. }
  186. if (!empty($shop)) {
  187. StatVisitClass::addHdCustomVisit($shop->id, $user->id);
  188. }
  189. }
  190. util::success(['info' => $info, 'hd' => $hd, 'custom' => $custom, 'inviteBound' => $inviteBound]);
  191. }
  192. //获取商家的默认门店 ssh 2019.12.6
  193. public function actionDetail()
  194. {
  195. $introUserId = Yii::$app->request->get('introUserId');
  196. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  197. $ad = [];
  198. if (isset($this->shop->img) && !empty($this->shop->img) && $this->shop->img != '[]') {
  199. $arr = json_decode($this->shop->img, true);
  200. if (!empty($arr)) {
  201. foreach ($arr as $img) {
  202. $imgUrl = imgUtil::groupImg($img);
  203. $ad[] = ['adImgUrl' => $imgUrl];
  204. }
  205. }
  206. }
  207. //新人专享礼物
  208. $newUserGift = [];
  209. if (!empty($introUserId)) {
  210. $userInfo = UserService::getUserInfo($this->userId);
  211. $newUserGift = InviteService::hasNewGift($userInfo);
  212. }
  213. util::success(['ad' => $ad, 'shop' => $shop, 'newUserGift' => $newUserGift]);
  214. }
  215. }