BaseController.php 2.3 KB

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