BaseController.php 2.6 KB

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