ShopController.php 9.6 KB

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