HdClass.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * 商城端花店(xhHd)业务:列表组装与首页展示模式。
  4. * app-mall HdController 调用;home-mode 给 mallApp 首页决定展示会员服务页还是花店列表。
  5. */
  6. namespace bizMall\hd\classes;
  7. use bizHd\shop\classes\ShopClass;
  8. use common\components\imgUtil;
  9. use bizMall\base\classes\BaseClass;
  10. use Yii;
  11. class HdClass extends BaseClass
  12. {
  13. public static $baseFile = '\bizMall\hd\models\Hd';
  14. /**
  15. * 首页展示模式:1 会员服务说明,0 花店列表。
  16. * 读 .env 的 MALL_HOME_MODE;改回 0 即恢复列表,不必重发前端。
  17. * 白名单 MALL_HOME_MODE_ALLOW_USER_IDS 内的用户仍看花店列表,方便自测。
  18. *
  19. * @param int $userId 当前登录用户,0 表示未登录
  20. * @return int 1 会员服务页,0 花店列表或白名单
  21. */
  22. public static function getHomeMode($userId = 0)
  23. {
  24. $flag = getenv('MALL_HOME_MODE');
  25. $on = $flag === false ? 0 : intval($flag);
  26. if ($on != 1) {
  27. return 0;
  28. }
  29. if ($userId > 0) {
  30. $allowStr = getenv('MALL_HOME_MODE_ALLOW_USER_IDS') ?: '';
  31. $allowIds = !empty($allowStr) ? explode(',', $allowStr) : [];
  32. if (in_array($userId, $allowIds)) {
  33. return 0;
  34. }
  35. }
  36. return 1;
  37. }
  38. public static function getHdList($where)
  39. {
  40. $data = self::getList('*', $where, 'inTurn DESC,addTime ASC');
  41. $data['list'] = self::groupBaseInfo($data['list']);
  42. return $data;
  43. }
  44. public static function groupBaseInfo($list)
  45. {
  46. if (empty($list)) {
  47. return $list;
  48. }
  49. $ids = array_column($list, 'shopId');
  50. $shopList = ShopClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,shopName,rechargeWeal,open,openStartTime,openEndTime', 'id');
  51. foreach ($list as $key => $val) {
  52. $shortAvatar = $val['avatar'] ?? '';
  53. $smallAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  54. $list[$key]['shortAvatar'] = $shortAvatar;
  55. $list[$key]['smallAvatar'] = $smallAvatar;
  56. $shopId = $val['shopId'];
  57. $currentShop = $shopList[$shopId] ?? [];
  58. if (empty($currentShop)) {
  59. // 店铺不存在
  60. Yii::warning('shopList中店铺不存在--', ['shopId' => $shopId]);
  61. continue;
  62. }
  63. //是否设置了充值福利 ssh 2025031
  64. $rechargeWeal = $currentShop['rechargeWeal'] ?? 0;
  65. $list[$key]['rechargeWeal'] = $rechargeWeal;
  66. //是否营业状态
  67. $openShop = ShopClass::getOpenShop($currentShop);
  68. $list[$key]['openShop'] = $openShop;
  69. }
  70. return $list;
  71. }
  72. }