Просмотр исходного кода

零售端-未登录用户接口数据

ouyang 12 часов назад
Родитель
Сommit
db2889fb77
2 измененных файлов с 238 добавлено и 1 удалено
  1. 138 1
      app-mall/controllers/ShopController.php
  2. 100 0
      common/components/dict.php

+ 138 - 1
app-mall/controllers/ShopController.php

@@ -8,6 +8,7 @@ use bizHd\custom\classes\CustomClass;
 use bizHd\custom\classes\HdClass;
 use bizHd\custom\classes\HdClass;
 use bizMall\invite\services\InviteService;
 use bizMall\invite\services\InviteService;
 use bizMall\user\services\UserService;
 use bizMall\user\services\UserService;
+use common\components\dict;
 use common\components\imgUtil;
 use common\components\imgUtil;
 use Yii;
 use Yii;
 use common\components\util;
 use common\components\util;
@@ -15,7 +16,143 @@ use common\components\util;
 class ShopController extends BaseController
 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
     //门店详情 ssh 20230210
     public function actionInfo()
     public function actionInfo()

+ 100 - 0
common/components/dict.php

@@ -97,6 +97,106 @@ class dict
                 'changeRate' => 0.00
                 'changeRate' => 0.00
             ],
             ],
         ],
         ],
+        // 花店配送方式默认配置(xhPsMethod):与 ghs shMethod 独立,新店注册/首次拉配置时写入
+        // 默认仅启用跑腿(用自定义计费)+自取;送货/物流/快递禁用
+        'psMethod' => [
+            0 => [
+                'name' => '送货',
+                'originName' => '送货',
+                'calcType' => 0,
+                'status' => 0,
+                'sort' => 3,
+                'minAmount' => 0.00,
+                'minNum' => 0,
+                'unMeet' => 0,
+                'unMeetFee' => 0.00,
+                'unMeetLockType' => 0,
+                'unMeetLockSeconds' => 1800,
+                'startKm' => 0.00,
+                'startPrice' => 0.00,
+                'perKmPrice' => 0.00,
+                'changeRate' => 0.00,
+                'hsFreeKm' => 0.00,
+                'hsPerKmPrice' => 0.00,
+            ],
+            1 => [
+                'name' => '自取',
+                'originName' => '自取',
+                'calcType' => 0,
+                'status' => 1,
+                'sort' => 2,
+                'minAmount' => 0.00,
+                'minNum' => 0,
+                'unMeet' => 0,
+                'unMeetFee' => 0.00,
+                'unMeetLockType' => 0,
+                'unMeetLockSeconds' => 1800,
+                'startKm' => 0.00,
+                'startPrice' => 0.00,
+                'perKmPrice' => 0.00,
+                'changeRate' => 0.00,
+                'hsFreeKm' => 0.00,
+                'hsPerKmPrice' => 0.00,
+            ],
+            2 => [
+                'name' => '跑腿',
+                'originName' => '跑腿',
+                // 新店默认用自定义计费,避免未绑定跑腿商户无法下单
+                'calcType' => 1,
+                'status' => 1,
+                'sort' => 1,
+                'minAmount' => 0.00,
+                'minNum' => 0,
+                'unMeet' => 0,
+                'unMeetFee' => 0.00,
+                'unMeetLockType' => 0,
+                'unMeetLockSeconds' => 1800,
+                'startKm' => 5.00,
+                'startPrice' => 15.00,
+                'perKmPrice' => 3.00,
+                'changeRate' => 0.00,
+                'hsFreeKm' => 0.00,
+                'hsPerKmPrice' => 0.00,
+            ],
+            3 => [
+                'name' => '物流',
+                'originName' => '物流',
+                'calcType' => 0,
+                'status' => 0,
+                'sort' => 5,
+                'minAmount' => 0.00,
+                'minNum' => 0,
+                'unMeet' => 0,
+                'unMeetFee' => 0.00,
+                'unMeetLockType' => 0,
+                'unMeetLockSeconds' => 1800,
+                'startKm' => 0.00,
+                'startPrice' => 0.00,
+                'perKmPrice' => 0.00,
+                'changeRate' => 0.00,
+                'hsFreeKm' => 0.00,
+                'hsPerKmPrice' => 0.00,
+            ],
+            4 => [
+                'name' => '快递',
+                'originName' => '快递',
+                'calcType' => 0,
+                'status' => 0,
+                'sort' => 4,
+                'minAmount' => 0.00,
+                'minNum' => 0,
+                'unMeet' => 0,
+                'unMeetFee' => 0.00,
+                'unMeetLockType' => 0,
+                'unMeetLockSeconds' => 1800,
+                'startKm' => 0.00,
+                'startPrice' => 0.00,
+                'perKmPrice' => 0.00,
+                'changeRate' => 0.00,
+                'hsFreeKm' => 0.00,
+                'hsPerKmPrice' => 0.00,
+            ],
+        ],
         //APP通知打开关闭状态 1打开 0关闭
         //APP通知打开关闭状态 1打开 0关闭
         'appNotice' => 1,
         'appNotice' => 1,
         //微信通知打开关闭状态 1打开 0关闭
         //微信通知打开关闭状态 1打开 0关闭