| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- /**
- * 商城端花店(xhHd)业务:列表组装与首页展示模式。
- * app-mall HdController 调用;home-mode 给 mallApp 首页决定展示会员服务页还是花店列表。
- */
- namespace bizMall\hd\classes;
- use bizHd\shop\classes\ShopClass;
- use common\components\imgUtil;
- use bizMall\base\classes\BaseClass;
- use Yii;
- class HdClass extends BaseClass
- {
- public static $baseFile = '\bizMall\hd\models\Hd';
- /**
- * 首页展示模式:1 会员服务说明,0 花店列表。
- * 读 .env 的 MALL_HOME_MODE;改回 0 即恢复列表,不必重发前端。
- * 白名单 MALL_HOME_MODE_ALLOW_USER_IDS 内的用户仍看花店列表,方便自测。
- *
- * @param int $userId 当前登录用户,0 表示未登录
- * @return int 1 会员服务页,0 花店列表或白名单
- */
- public static function getHomeMode($userId = 0)
- {
- $flag = getenv('MALL_HOME_MODE');
- $on = $flag === false ? 0 : intval($flag);
- if ($on != 1) {
- return 0;
- }
- if ($userId > 0) {
- $allowStr = getenv('MALL_HOME_MODE_ALLOW_USER_IDS') ?: '';
- $allowIds = !empty($allowStr) ? explode(',', $allowStr) : [];
- if (in_array($userId, $allowIds)) {
- return 0;
- }
- }
- return 1;
- }
- public static function getHdList($where)
- {
- $data = self::getList('*', $where, 'inTurn DESC,addTime ASC');
- $data['list'] = self::groupBaseInfo($data['list']);
- return $data;
- }
- public static function groupBaseInfo($list)
- {
- if (empty($list)) {
- return $list;
- }
- $ids = array_column($list, 'shopId');
- $shopList = ShopClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,shopName,rechargeWeal,open,openStartTime,openEndTime', 'id');
- foreach ($list as $key => $val) {
- $shortAvatar = $val['avatar'] ?? '';
- $smallAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
- $list[$key]['shortAvatar'] = $shortAvatar;
- $list[$key]['smallAvatar'] = $smallAvatar;
- $shopId = $val['shopId'];
- $currentShop = $shopList[$shopId] ?? [];
- if (empty($currentShop)) {
- // 店铺不存在
- Yii::warning('shopList中店铺不存在--', ['shopId' => $shopId]);
- continue;
- }
- //是否设置了充值福利 ssh 2025031
- $rechargeWeal = $currentShop['rechargeWeal'] ?? 0;
- $list[$key]['rechargeWeal'] = $rechargeWeal;
- //是否营业状态
- $openShop = ShopClass::getOpenShop($currentShop);
- $list[$key]['openShop'] = $openShop;
- }
- return $list;
- }
- }
|