BaseController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace mall\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use bizHd\custom\classes\CustomClass;
  5. use bizMall\merchant\services\MerchantExtendService;
  6. use bizMall\merchant\services\MerchantService;
  7. use bizMall\user\services\UserService;
  8. use common\components\httpUtil;
  9. use common\components\jwt;
  10. use common\components\util;
  11. use Yii;
  12. class BaseController extends PublicController
  13. {
  14. public $validate = true;
  15. public $guestAccess = [];
  16. public $userId = 0, $user, $shopId, $shop;
  17. public $sjId, $sj, $sjExtend, $customId = 0, $custom = [];
  18. public $isWx;
  19. public function beforeAction($action)
  20. {
  21. //定义平台类型 1花店 2供货商 3商城
  22. Yii::$app->params['ptStyle'] = 3;
  23. $userId = jwt::getLoginId();
  24. if (empty($userId)) {
  25. util::fail('您还没有登陆');
  26. }
  27. $this->userId = $userId;
  28. $userInfo = UserService::getUserInfo($userId);
  29. $this->user = $userInfo;
  30. $this->isWx = util::isWx();
  31. $header = httpUtil::getHeader();
  32. $shopId = isset($header['account']) ? $header['account'] : 0;
  33. $this->shopId = $shopId;
  34. if (!empty($shopId)) {
  35. $shop = ShopClass::getById($shopId);
  36. if (empty($shop)) {
  37. util::fail('没有找到门店');
  38. }
  39. $sjId = $shop['merchantId'] ?? 0;
  40. if (empty($sjId)) {
  41. util::fail('没有找到商家哦');
  42. }
  43. $sj = MerchantService::getMerchantById($sjId);
  44. if (empty($sj)) {
  45. util::fail('没有找到商家信息');
  46. }
  47. $this->sjId = $sjId;
  48. $this->sj = $sj;
  49. $this->shop = $shop;
  50. $this->sjExtend = MerchantExtendService::getByMerchantId($sjId);
  51. $custom = CustomClass::replaceCustom($sjId, $userInfo, $shopId);
  52. if (!empty($custom)) {
  53. $this->custom = $custom;
  54. $customId = $custom['id'] ?? 0;
  55. $this->customId = $customId;
  56. } else {
  57. if (in_array($action->id, $this->guestAccess) == false) {
  58. util::fail('没有找到客户信息哦');
  59. }
  60. }
  61. }
  62. return parent::beforeAction($action);
  63. }
  64. }