|
|
@@ -8,6 +8,7 @@ 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;
|
|
|
@@ -15,7 +16,143 @@ use common\components\util;
|
|
|
class ShopController extends BaseController
|
|
|
{
|
|
|
|
|
|
- public $guestAccess = ['info'];
|
|
|
+ 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()
|