ShopController.php 9.3 KB

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