ShopController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace mall\controllers;
  3. use biz\shop\classes\ShopExtClass;
  4. use bizHd\stat\classes\StatVisitClass;
  5. use bizHd\custom\classes\CustomClass;
  6. use bizHd\custom\classes\HdClass;
  7. use bizMall\invite\services\InviteService;
  8. use bizMall\user\services\UserService;
  9. use common\components\imgUtil;
  10. use Yii;
  11. use common\components\util;
  12. class ShopController extends BaseController
  13. {
  14. public $guestAccess = ['info'];
  15. //门店详情 ssh 20230210
  16. public function actionInfo()
  17. {
  18. $get = Yii::$app->request->get();
  19. $hdId = $get['hdId'] ?? 0;
  20. $shop = $this->shop;
  21. $info = !empty($shop) ? $shop->attributes : [];
  22. if (isset($info['superWx'])) {
  23. $superWx = $info['superWx'];
  24. $info['superWx'] = imgUtil::groupImg($superWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  25. } else {
  26. $info['superWx'] = '';
  27. }
  28. $shortAvatar = $info['avatar'] ?? '';
  29. $avatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_300,w_300";
  30. $info['avatar'] = $avatar;
  31. $info['shortAvatar'] = $shortAvatar;
  32. // 合并 xhShopExt 客服电话/微信二维码,供商城客服页展示与拨号
  33. $ext = !empty($shop) ? ShopExtClass::getByCondition(['shopId' => $shop->id], true) : null;
  34. $shortServiceWx = !empty($ext) ? ($ext->serviceWx ?? '') : '';
  35. $info['serviceMobile'] = !empty($ext) ? ($ext->serviceMobile ?? '') : '';
  36. $info['shortServiceWx'] = $shortServiceWx;
  37. $info['serviceWx'] = empty($shortServiceWx)
  38. ? ''
  39. : imgUtil::groupImg($shortServiceWx) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  40. $user = $this->user;
  41. $hd = [];
  42. $custom = [];
  43. $inviteBound = 0;
  44. if (!empty($user)) {
  45. if (empty($hdId)) {
  46. $inviterCustomId = isset($get['inviterCustomId']) ? (int)$get['inviterCustomId'] : 0;
  47. $respond = CustomClass::buildRelation($shop, $user, $inviterCustomId);
  48. $hd = $respond['hd'];
  49. $custom = $respond['custom'];
  50. $inviteBound = !empty($respond['inviteBound']) ? (int)$respond['inviteBound'] : 0;
  51. } else {
  52. $hd = HdClass::getById($hdId, true);
  53. if (!empty($hd)) {
  54. $customId = $hd->customId;
  55. $custom = CustomClass::getById($customId, true);
  56. if (!empty($custom)) {
  57. $custom->visitTime = date("Y-m-d H:i:s");
  58. $custom->save();
  59. }
  60. }
  61. }
  62. if (!empty($shop)) {
  63. StatVisitClass::addHdCustomVisit($shop->id, $user->id);
  64. }
  65. }
  66. util::success(['info' => $info, 'hd' => $hd, 'custom' => $custom, 'inviteBound' => $inviteBound]);
  67. }
  68. //获取商家的默认门店 ssh 2019.12.6
  69. public function actionDetail()
  70. {
  71. $introUserId = Yii::$app->request->get('introUserId');
  72. $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
  73. $ad = [];
  74. if (isset($this->shop->img) && !empty($this->shop->img) && $this->shop->img != '[]') {
  75. $arr = json_decode($this->shop->img, true);
  76. if (!empty($arr)) {
  77. foreach ($arr as $img) {
  78. $imgUrl = imgUtil::groupImg($img);
  79. $ad[] = ['adImgUrl' => $imgUrl];
  80. }
  81. }
  82. }
  83. //新人专享礼物
  84. $newUserGift = [];
  85. if (!empty($introUserId)) {
  86. $userInfo = UserService::getUserInfo($this->userId);
  87. $newUserGift = InviteService::hasNewGift($userInfo);
  88. }
  89. util::success(['ad' => $ad, 'shop' => $shop, 'newUserGift' => $newUserGift]);
  90. }
  91. }