BaseController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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, $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. $hd = HdClass::getById($hdId, true);
  55. if (!empty($hd)) {
  56. if ($hd->userId != $this->userId) {
  57. util::fail('不是你的花店,无法访问哦');
  58. }
  59. if ($shopId != $hd->shopId) {
  60. util::fail('花店信息有问题哦');
  61. }
  62. $this->hd = $hd;
  63. $customId = $hd->customId ?? 0;
  64. $custom = CustomClass::getById($customId, true);
  65. $this->custom = $custom;
  66. }
  67. }
  68. }
  69. return parent::beforeAction($action);
  70. }
  71. }