ShopController.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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' => 501,
  28. 'name' => '楼兰花艺',
  29. 'address' => '厦门市集美区凤林前山路147号',
  30. 'businessHours' => '09:00-22:00',
  31. 'cover' => 'shop/wsf_ll.png',
  32. ],
  33. [
  34. 'shopId' => 1,
  35. 'name' => '国兰花尚',
  36. 'address' => '厦门市思明区后埭溪路128号',
  37. 'businessHours' => '09:00-22:00',
  38. 'cover' => 'hhb/images/guest/shop2.jpg',
  39. ],
  40. [
  41. 'shopId' => 17117,
  42. 'name' => '淘花里鲜花',
  43. 'address' => '广东省中山市歧关西路20号',
  44. 'businessHours' => '09:00-22:00',
  45. 'cover' => 'hhb/images/guest/shop3.jpg',
  46. ],
  47. [
  48. 'shopId' => 77702,
  49. 'name' => '天天鲜花',
  50. 'address' => '厦门市思明区双涵路97号',
  51. 'businessHours' => '09:00-22:00',
  52. 'cover' => 'hhb/images/guest/shop1.jpg',
  53. ],
  54. [
  55. 'shopId' => 2,
  56. 'name' => '龙岩花掌柜',
  57. 'address' => '龙岩市交易城C区',
  58. 'businessHours' => '09:00-22:00',
  59. 'cover' => 'hhb/images/guest/shop2.jpg',
  60. ]
  61. ]
  62. : [
  63. [
  64. 'shopId' => 36523,
  65. 'name' => '好运鲜花批发',
  66. 'address' => '厦门市集美区凤林前山路147号',
  67. 'businessHours' => '09:00-22:00',
  68. 'cover' => 'hhb/images/guest/shop1.jpg',
  69. ],
  70. [
  71. 'shopId' => 37064,
  72. 'name' => '楼兰鲜花',
  73. 'address' => '福州市仓山区浦上大道339-30号',
  74. 'businessHours' => '09:00-22:00',
  75. 'cover' => 'hhb/images/guest/shop2.jpg',
  76. ],
  77. [
  78. 'shopId' => 36548,
  79. 'name' => '花夕花艺',
  80. 'address' => '漳州市龙海区鸿江路15号',
  81. 'businessHours' => '09:00-22:00',
  82. 'cover' => 'hhb/images/guest/shop3.jpg',
  83. ]
  84. ];
  85. $list = [];
  86. foreach ($rows as $row) {
  87. $shopId = (int)($row['shopId'] ?? 0);
  88. $list[] = [
  89. 'shopId' => $shopId,
  90. 'account' => $shopId,
  91. 'id' => $shopId,
  92. 'name' => (string)($row['name'] ?? ''),
  93. 'address' => (string)($row['address'] ?? ''),
  94. 'businessHours' => (string)($row['businessHours'] ?? ''),
  95. 'cover' => imgUtil::groupImg($row['cover'] ?? ''),
  96. 'avatar' => imgUtil::groupImg($row['cover'] ?? ''),
  97. ];
  98. }
  99. util::success([
  100. 'banner' => imgUtil::groupImg('hhb/images/guest/banner.jpg'),
  101. 'list' => $list,
  102. ]);
  103. }
  104. /**
  105. * 未登录首页按花店名称搜索(xhShop.ptStyle=1 零售花店)
  106. * 仅匹配 shopName / merchantName,不按城市搜
  107. */
  108. public function actionSearch()
  109. {
  110. $keyword = trim((string)Yii::$app->request->get('keyword', ''));
  111. if ($keyword === '') {
  112. util::success(['list' => []]);
  113. }
  114. // 限制长度,避免超长 like 拖垮查询
  115. if (mb_strlen($keyword) > 30) {
  116. $keyword = mb_substr($keyword, 0, 30);
  117. }
  118. $ptStyle = (int)dict::getDict('ptStyle', 'hd'); // 1=零售花店
  119. $rows = \biz\shop\models\Shop::find()
  120. ->select(['id', 'shopName', 'merchantName', 'city', 'address', 'floor', 'avatar', 'openStartTime', 'openEndTime', 'open'])
  121. ->where(['ptStyle' => $ptStyle])
  122. ->andWhere([
  123. 'or',
  124. ['like', 'shopName', $keyword],
  125. ['like', 'merchantName', $keyword],
  126. ])
  127. ->orderBy(['id' => SORT_DESC])
  128. ->limit(30)
  129. ->asArray()
  130. ->all();
  131. $list = [];
  132. foreach ($rows as $row) {
  133. $shopName = trim((string)($row['shopName'] ?? ''));
  134. $merchantName = trim((string)($row['merchantName'] ?? ''));
  135. // 展示名:首店只显示商家名,否则「商家名 店名」
  136. $name = ($shopName === '' || $shopName === '首店')
  137. ? ($merchantName !== '' ? $merchantName : $shopName)
  138. : ($merchantName !== '' ? ($merchantName . ' ' . $shopName) : $shopName);
  139. $avatarShort = $row['avatar'] ?? '';
  140. $start = trim((string)($row['openStartTime'] ?? ''));
  141. $end = trim((string)($row['openEndTime'] ?? ''));
  142. $hours = '';
  143. if ($start !== '' && $end !== '') {
  144. $hours = $start . '-' . $end;
  145. }
  146. $list[] = [
  147. 'id' => (int)$row['id'],
  148. 'account' => (int)$row['id'],
  149. 'name' => $name,
  150. 'address' => trim(($row['city'] ?? '') . ($row['address'] ?? '') . ($row['floor'] ?? '')),
  151. 'avatar' => empty($avatarShort)
  152. ? ''
  153. : imgUtil::groupImg($avatarShort) . '?x-oss-process=image/resize,m_fill,h_200,w_200',
  154. 'businessHours' => $hours,
  155. 'open' => isset($row['open']) ? (int)$row['open'] : 1,
  156. ];
  157. }
  158. util::success(['list' => $list]);
  159. }
  160. //门店详情 ssh 20230210
  161. public function actionInfo()
  162. {
  163. $get = Yii::$app->request->get();
  164. $hdId = $get['hdId'] ?? 0;
  165. $shop = $this->shop;
  166. $info = !empty($shop) ? $shop->attributes : [];
  167. if (isset($info['superWx'])) {
  168. $superWx = $info['superWx'];
  169. $info['superWx'] = imgUtil::groupImg($superWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  170. } else {
  171. $info['superWx'] = '';
  172. }
  173. $shortAvatar = $info['avatar'] ?? '';
  174. $avatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_300,w_300";
  175. $info['avatar'] = $avatar;
  176. $info['shortAvatar'] = $shortAvatar;
  177. // 合并 xhShopExt 客服电话/微信二维码,供商城客服页展示与拨号
  178. $ext = !empty($shop) ? ShopExtClass::getByCondition(['shopId' => $shop->id], true) : null;
  179. $shortServiceWx = !empty($ext) ? ($ext->serviceWx ?? '') : '';
  180. $info['serviceMobile'] = !empty($ext) ? ($ext->serviceMobile ?? '') : '';
  181. $info['shortServiceWx'] = $shortServiceWx;
  182. $info['serviceWx'] = empty($shortServiceWx)
  183. ? ''
  184. : imgUtil::groupImg($shortServiceWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  185. $user = $this->user;
  186. $hd = [];
  187. $custom = [];
  188. $inviteBound = 0;
  189. if (!empty($user)) {
  190. if (empty($hdId)) {
  191. $inviterCustomId = isset($get['inviterCustomId']) ? (int)$get['inviterCustomId'] : 0;
  192. $respond = CustomClass::buildRelation($shop, $user, $inviterCustomId);
  193. $hd = $respond['hd'];
  194. $custom = $respond['custom'];
  195. $inviteBound = !empty($respond['inviteBound']) ? (int)$respond['inviteBound'] : 0;
  196. } else {
  197. $hd = HdClass::getById($hdId, true);
  198. if (!empty($hd)) {
  199. $customId = $hd->customId;
  200. $custom = CustomClass::getById($customId, true);
  201. if (!empty($custom)) {
  202. $custom->visitTime = date("Y-m-d H:i:s");
  203. $custom->save();
  204. }
  205. }
  206. }
  207. if (!empty($shop)) {
  208. StatVisitClass::addHdCustomVisit($shop->id, $user->id);
  209. }
  210. }
  211. util::success(['info' => $info, 'hd' => $hd, 'custom' => $custom, 'inviteBound' => $inviteBound]);
  212. }
  213. //获取商家的默认门店 ssh 2019.12.6
  214. public function actionDetail()
  215. {
  216. $introUserId = Yii::$app->request->get('introUserId');
  217. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  218. $ad = [];
  219. if (isset($this->shop->img) && !empty($this->shop->img) && $this->shop->img != '[]') {
  220. $arr = json_decode($this->shop->img, true);
  221. if (!empty($arr)) {
  222. foreach ($arr as $img) {
  223. $imgUrl = imgUtil::groupImg($img);
  224. $ad[] = ['adImgUrl' => $imgUrl];
  225. }
  226. }
  227. }
  228. //新人专享礼物
  229. $newUserGift = [];
  230. if (!empty($introUserId)) {
  231. $userInfo = UserService::getUserInfo($this->userId);
  232. $newUserGift = InviteService::hasNewGift($userInfo);
  233. }
  234. util::success(['ad' => $ad, 'shop' => $shop, 'newUserGift' => $newUserGift]);
  235. }
  236. }