| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?php
- namespace mall\controllers;
- use biz\shop\classes\ShopExtClass;
- use bizHd\stat\classes\StatVisitClass;
- use bizHd\custom\classes\CustomClass;
- use bizHd\custom\classes\HdClass;
- use bizMall\invite\services\InviteService;
- use bizMall\user\services\UserService;
- use common\components\dict;
- use common\components\imgUtil;
- use Yii;
- use common\components\util;
- class ShopController extends BaseController
- {
- public $guestAccess = ['info', 'search', 'recommend'];
- /**
- * 未登录首页「推荐花店」:内容后端写死,按 YII_ENV 区分测试/正式
- * 返回 shopId、名称、地址、营业时间、封面完整 URL;进店用 account=shopId
- */
- public function actionRecommend()
- {
- $isProd = getenv('YII_ENV') === 'production';
- // 测试 / 正式各写死 3 家;shopId 请换成真实 xhShop.id(ptStyle=1)
- $rows = $isProd
- ? [
- [
- 'shopId' => 4458,
- 'name' => '花语鲜花店',
- 'address' => '北京市朝阳区望京街道广顺北大街33号',
- 'businessHours' => '09:00-22:00',
- 'cover' => 'hhb/images/guest/shop1.jpg',
- ],
- [
- 'shopId' => 4458,
- 'name' => '初见花艺',
- 'address' => '北京市朝阳区望京SOHO塔1-B座底商',
- 'businessHours' => '09:00-22:00',
- 'cover' => 'hhb/images/guest/shop2.jpg',
- ],
- [
- 'shopId' => 4458,
- 'name' => '拾光花坊',
- 'address' => '北京市朝阳区利泽西街6号院底商',
- 'businessHours' => '09:00-22:00',
- 'cover' => 'hhb/images/guest/shop3.jpg',
- ],
- ]
- : [
- [
- 'shopId' => 36524,
- 'name' => '花语鲜花店',
- 'address' => '北京市朝阳区望京街道广顺北大街33号',
- 'businessHours' => '09:00-22:00',
- 'cover' => 'hhb/images/guest/shop1.jpg',
- ],
- [
- 'shopId' => 36524,
- 'name' => '初见花艺',
- 'address' => '北京市朝阳区望京SOHO塔1-B座底商',
- 'businessHours' => '09:00-22:00',
- 'cover' => 'hhb/images/guest/shop2.jpg',
- ],
- [
- 'shopId' => 36524,
- 'name' => '拾光花坊',
- 'address' => '北京市朝阳区利泽西街6号院底商',
- 'businessHours' => '09:00-22:00',
- 'cover' => 'hhb/images/guest/shop3.jpg',
- ],
- ];
- $list = [];
- foreach ($rows as $row) {
- $shopId = (int)($row['shopId'] ?? 0);
- $list[] = [
- 'shopId' => $shopId,
- 'account' => $shopId,
- 'id' => $shopId,
- 'name' => (string)($row['name'] ?? ''),
- 'address' => (string)($row['address'] ?? ''),
- 'businessHours' => (string)($row['businessHours'] ?? ''),
- 'cover' => imgUtil::groupImg($row['cover'] ?? ''),
- 'avatar' => imgUtil::groupImg($row['cover'] ?? ''),
- ];
- }
- util::success([
- 'banner' => imgUtil::groupImg('hhb/images/guest/banner.jpg'),
- 'list' => $list,
- ]);
- }
- /**
- * 未登录首页按花店名称搜索(xhShop.ptStyle=1 零售花店)
- * 仅匹配 shopName / merchantName,不按城市搜
- */
- public function actionSearch()
- {
- $keyword = trim((string)Yii::$app->request->get('keyword', ''));
- if ($keyword === '') {
- util::success(['list' => []]);
- }
- // 限制长度,避免超长 like 拖垮查询
- if (mb_strlen($keyword) > 30) {
- $keyword = mb_substr($keyword, 0, 30);
- }
- $ptStyle = (int)dict::getDict('ptStyle', 'hd'); // 1=零售花店
- $rows = \biz\shop\models\Shop::find()
- ->select(['id', 'shopName', 'merchantName', 'city', 'address', 'floor', 'avatar', 'openStartTime', 'openEndTime', 'open'])
- ->where(['ptStyle' => $ptStyle])
- ->andWhere([
- 'or',
- ['like', 'shopName', $keyword],
- ['like', 'merchantName', $keyword],
- ])
- ->orderBy(['id' => SORT_DESC])
- ->limit(30)
- ->asArray()
- ->all();
- $list = [];
- foreach ($rows as $row) {
- $shopName = trim((string)($row['shopName'] ?? ''));
- $merchantName = trim((string)($row['merchantName'] ?? ''));
- // 展示名:首店只显示商家名,否则「商家名 店名」
- $name = ($shopName === '' || $shopName === '首店')
- ? ($merchantName !== '' ? $merchantName : $shopName)
- : ($merchantName !== '' ? ($merchantName . ' ' . $shopName) : $shopName);
- $avatarShort = $row['avatar'] ?? '';
- $start = trim((string)($row['openStartTime'] ?? ''));
- $end = trim((string)($row['openEndTime'] ?? ''));
- $hours = '';
- if ($start !== '' && $end !== '') {
- $hours = $start . '-' . $end;
- }
- $list[] = [
- 'id' => (int)$row['id'],
- 'account' => (int)$row['id'],
- 'name' => $name,
- 'address' => trim(($row['city'] ?? '') . ($row['address'] ?? '') . ($row['floor'] ?? '')),
- 'avatar' => empty($avatarShort)
- ? ''
- : imgUtil::groupImg($avatarShort) . '?x-oss-process=image/resize,m_fill,h_200,w_200',
- 'businessHours' => $hours,
- 'open' => isset($row['open']) ? (int)$row['open'] : 1,
- ];
- }
- util::success(['list' => $list]);
- }
- //门店详情 ssh 20230210
- public function actionInfo()
- {
- $get = Yii::$app->request->get();
- $hdId = $get['hdId'] ?? 0;
- $shop = $this->shop;
- $info = !empty($shop) ? $shop->attributes : [];
- if (isset($info['superWx'])) {
- $superWx = $info['superWx'];
- $info['superWx'] = imgUtil::groupImg($superWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- } else {
- $info['superWx'] = '';
- }
- $shortAvatar = $info['avatar'] ?? '';
- $avatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_300,w_300";
- $info['avatar'] = $avatar;
- $info['shortAvatar'] = $shortAvatar;
- // 合并 xhShopExt 客服电话/微信二维码,供商城客服页展示与拨号
- $ext = !empty($shop) ? ShopExtClass::getByCondition(['shopId' => $shop->id], true) : null;
- $shortServiceWx = !empty($ext) ? ($ext->serviceWx ?? '') : '';
- $info['serviceMobile'] = !empty($ext) ? ($ext->serviceMobile ?? '') : '';
- $info['shortServiceWx'] = $shortServiceWx;
- $info['serviceWx'] = empty($shortServiceWx)
- ? ''
- : imgUtil::groupImg($shortServiceWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
- $user = $this->user;
- $hd = [];
- $custom = [];
- $inviteBound = 0;
- if (!empty($user)) {
- if (empty($hdId)) {
- $inviterCustomId = isset($get['inviterCustomId']) ? (int)$get['inviterCustomId'] : 0;
- $respond = CustomClass::buildRelation($shop, $user, $inviterCustomId);
- $hd = $respond['hd'];
- $custom = $respond['custom'];
- $inviteBound = !empty($respond['inviteBound']) ? (int)$respond['inviteBound'] : 0;
- } else {
- $hd = HdClass::getById($hdId, true);
- if (!empty($hd)) {
- $customId = $hd->customId;
- $custom = CustomClass::getById($customId, true);
- if (!empty($custom)) {
- $custom->visitTime = date("Y-m-d H:i:s");
- $custom->save();
- }
- }
- }
- if (!empty($shop)) {
- StatVisitClass::addHdCustomVisit($shop->id, $user->id);
- }
- }
- util::success(['info' => $info, 'hd' => $hd, 'custom' => $custom, 'inviteBound' => $inviteBound]);
- }
- //获取商家的默认门店 ssh 2019.12.6
- public function actionDetail()
- {
- $introUserId = Yii::$app->request->get('introUserId');
- $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
- $ad = [];
- if (isset($this->shop->img) && !empty($this->shop->img) && $this->shop->img != '[]') {
- $arr = json_decode($this->shop->img, true);
- if (!empty($arr)) {
- foreach ($arr as $img) {
- $imgUrl = imgUtil::groupImg($img);
- $ad[] = ['adImgUrl' => $imgUrl];
- }
- }
- }
- //新人专享礼物
- $newUserGift = [];
- if (!empty($introUserId)) {
- $userInfo = UserService::getUserInfo($this->userId);
- $newUserGift = InviteService::hasNewGift($userInfo);
- }
- util::success(['ad' => $ad, 'shop' => $shop, 'newUserGift' => $newUserGift]);
- }
- }
|