BaseController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace mall\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\classes\SjClass;
  5. use bizHd\custom\classes\CustomClass;
  6. use bizMall\hd\classes\HdClass;
  7. use bizMall\merchant\services\MerchantExtendService;
  8. use bizMall\merchant\services\MerchantService;
  9. use bizMall\shop\classes\MainClass;
  10. use bizMall\user\classes\UserClass;
  11. use bizMall\user\services\UserService;
  12. use common\components\dict;
  13. use common\components\httpUtil;
  14. use common\components\jwt;
  15. use common\components\util;
  16. use function GuzzleHttp\Promise\iter_for;
  17. use Yii;
  18. class BaseController extends PublicController
  19. {
  20. public $validate = true;
  21. public $guestAccess = [];
  22. public $userId = 0, $user, $shopId, $shop;
  23. public $sjId, $sj, $sjExtend, $customId = 0, $custom, $hd, $hdId, $mainId = 0, $main;
  24. public $isWx;
  25. public function beforeAction($action)
  26. {
  27. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'mall');
  28. $this->isWx = util::isWx();
  29. $userId = jwt::getLoginId();
  30. if (empty($userId)) {
  31. if (!in_array($action->id, $this->guestAccess)) {
  32. util::fail('请先登录哈');
  33. }
  34. }
  35. $this->userId = $userId;
  36. $user = UserClass::getById($userId, true);
  37. if (empty($user)) {
  38. if (!in_array($action->id, $this->guestAccess)) {
  39. util::fail('请先登录呢');
  40. }
  41. }
  42. $this->user = $user;
  43. $shopId = Yii::$app->request->get('account', 0);
  44. if (!empty($shopId)) {
  45. $this->shopId = $shopId;
  46. $shop = ShopClass::getById($shopId, true);
  47. if (!empty($shop)) {
  48. $this->shop = $shop;
  49. $mainId = $shop->mainId ?? 0;
  50. $main = MainClass::getById($mainId, true);
  51. $this->main = $main;
  52. $this->mainId = $mainId;
  53. $hdId = Yii::$app->request->get('hdId', 0);
  54. if (empty($hdId)) {
  55. //兼容早期代码没有写规范问题
  56. $hdId = Yii::$app->request->post('hdId', 0);
  57. }
  58. if (!empty($hdId)) {
  59. $hd = HdClass::getById($hdId, true);
  60. if (!empty($hd)) {
  61. if (!empty($this->userId) && $hd->userId == $this->userId && $shopId == $hd->shopId) {
  62. $this->hd = $hd;
  63. $this->hdId = $hdId;
  64. $customId = $hd->customId ?? 0;
  65. $custom = CustomClass::getById($customId, true);
  66. $this->custom = $custom;
  67. $this->customId = $customId;
  68. }
  69. }
  70. }
  71. }
  72. }
  73. return parent::beforeAction($action);
  74. }
  75. }