BaseController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\merchant\services\MerchantExtendService;
  7. use bizMall\merchant\services\MerchantService;
  8. use bizMall\shop\classes\MainClass;
  9. use bizMall\user\classes\UserClass;
  10. use bizMall\user\services\UserService;
  11. use common\components\dict;
  12. use common\components\httpUtil;
  13. use common\components\jwt;
  14. use common\components\util;
  15. use function GuzzleHttp\Promise\iter_for;
  16. use Yii;
  17. class BaseController extends PublicController
  18. {
  19. public $validate = true;
  20. public $guestAccess = [];
  21. public $userId = 0, $user, $shopId, $shop;
  22. public $sjId, $sj, $sjExtend, $customId = 0, $custom = [], $mainId = 0, $main = [];
  23. public $isWx;
  24. public function beforeAction($action)
  25. {
  26. //定义平台类型 1花店 2供应商 3商城
  27. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'mall');
  28. $shopId = Yii::$app->request->get('account', 0);
  29. $this->shopId = $shopId;
  30. if (!empty($shopId)) {
  31. $shop = ShopClass::getById($shopId, true);
  32. if (!empty($shop)) {
  33. $mainId = $shop->mainId ?? 0;
  34. $main = MainClass::getById($mainId, true);
  35. $this->main = $main;
  36. $this->mainId = $mainId;
  37. $this->shop = $shop;
  38. $sjId = $shop->sjId ?? 0;
  39. $this->sjId = $sjId;
  40. $sj = SjClass::getById($this->sjId, true);
  41. if (empty($sj)) {
  42. util::fail('没有找到商家信息');
  43. }
  44. $this->sj = $sj;
  45. }
  46. }
  47. if (httpUtil::isMiniProgram()) {
  48. $userId = jwt::getLoginId();
  49. if (empty($userId)) {
  50. util::notLogin('您还没有登陆');
  51. }
  52. $this->userId = $userId;
  53. $user = UserClass::getById($userId, true);
  54. if (empty($user)) {
  55. util::fail('没有找到客户信息');
  56. }
  57. $this->user = $user;
  58. $this->isWx = util::isWx();
  59. if (!empty($shop)) {
  60. $this->sjExtend = MerchantExtendService::getBySjId($this->sjId);
  61. $userInfo = isset($user->attributes) ? $user->attributes : [];
  62. $custom = CustomClass::replaceCustom($this->sjId, $userInfo, $shopId);
  63. if (!empty($custom)) {
  64. $this->custom = $custom;
  65. $customId = $custom['id'] ?? 0;
  66. $this->customId = $customId;
  67. } else {
  68. if (in_array($action->id, $this->guestAccess) == false) {
  69. util::fail('没有找到客户信息哦');
  70. }
  71. }
  72. }
  73. } else {
  74. //非登陆情况的请求,支付宝扫码付款需要用到
  75. }
  76. return parent::beforeAction($action);
  77. }
  78. }