BaseController.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. //兼容早期代码,勿删,扫码付款页也用到
  46. $shopId = Yii::$app->request->post('account', 0);
  47. }
  48. if (!empty($shopId)) {
  49. $this->shopId = $shopId;
  50. $shop = ShopClass::getById($shopId, true);
  51. if (!empty($shop)) {
  52. $this->shop = $shop;
  53. $mainId = $shop->mainId ?? 0;
  54. $main = MainClass::getById($mainId, true);
  55. $this->main = $main;
  56. $this->mainId = $mainId;
  57. $hdId = Yii::$app->request->get('hdId', 0);
  58. if (empty($hdId)) {
  59. //兼容早期代码,勿删,扫码付款页也用到,只写POST方式
  60. $hdId = Yii::$app->request->post('hdId', 0);
  61. }
  62. if (!empty($hdId)) {
  63. $hd = HdClass::getById($hdId, true);
  64. if (!empty($hd)) {
  65. if (!empty($this->userId) && $hd->userId == $this->userId && $shopId == $hd->shopId) {
  66. $this->hd = $hd;
  67. $this->hdId = $hdId;
  68. $customId = $hd->customId ?? 0;
  69. $custom = CustomClass::getById($customId, true);
  70. $this->custom = $custom;
  71. $this->customId = $customId;
  72. }
  73. }
  74. }
  75. }
  76. }
  77. return parent::beforeAction($action);
  78. }
  79. }