BaseController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace shop\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\admin\services\ShopAdminService;
  5. use biz\custom\classes\CustomClass;
  6. use biz\merchant\classes\MerchantExtendClass;
  7. use biz\merchant\classes\ShopClass;
  8. use biz\merchant\services\AdminService;
  9. use biz\merchant\services\MerchantExtendService;
  10. use biz\merchant\services\MerchantService;
  11. use biz\merchant\services\ShopService;
  12. use biz\wx\services\WxOpenService;
  13. use common\components\httpUtil;
  14. use common\components\jwt;
  15. use Yii;
  16. use common\components\util;
  17. class BaseController extends PublicController
  18. {
  19. public $admin, $adminId, $adminAvatar, $account, $customId = 0, $custom;
  20. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0;
  21. public $appId;
  22. public $isWx = false;
  23. public $isLogin = false;
  24. //游客可以访问的方法
  25. public $guestAccessAction = [];
  26. //shish 2020.3.8
  27. public function beforeAction($action)
  28. {
  29. //token验证
  30. //$adminId = jwt::getLoginId();
  31. $adminId = 18569;
  32. if (empty($adminId)) {
  33. util::notLogin();
  34. }
  35. $admin = AdminClass::getAdminById($adminId, true);
  36. if (empty($admin)) {
  37. util::notLogin();
  38. }
  39. $adminId = $admin['id'];
  40. $this->admin = $admin;
  41. $this->adminId = $adminId;
  42. $header = httpUtil::getHeader();
  43. $shopId = $header['shop-id'] ?? 0;
  44. if (!empty($shopId)) {
  45. $shop = ShopClass::getById($shopId);
  46. if (empty($shop)) {
  47. util::fail('没有找到店铺');
  48. }
  49. $sjId = $shop['merchantId'] ?? 0;
  50. $custom = CustomClass::getCustom(['sjId' => $sjId, 'adminId' => $adminId]);
  51. $customId = $custom['id'] ?? 0;
  52. if (empty($customId)) {
  53. util::fail('没有找到客户信息');
  54. }
  55. $this->custom = $custom;
  56. $this->customId = $customId;
  57. $this->sjId = $sjId;
  58. $sj = MerchantService::getMerchantById($sjId);
  59. $this->sj = $sj;
  60. $this->sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  61. if (in_array($action->id, $this->guestAccessAction) == false) {
  62. util::fail('此商家的页面,您没有权限访问');
  63. }
  64. } else {
  65. $currentShopId = $admin['currentShopId'] ?? 0;
  66. if (!empty($currentShopId)) {
  67. $shop = ShopService::getById($currentShopId);
  68. $sjId = $shop['merchantId'];
  69. $sj = MerchantService::getMerchantById($sjId);
  70. $this->sj = $sj;
  71. $this->shopId = $currentShopId;
  72. $this->sjId = $sjId;
  73. $this->sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  74. } else {
  75. if (in_array($action->id, $this->guestAccessAction) == false) {
  76. util::fail('此管理后台页面,您没有权限访问');
  77. }
  78. }
  79. }
  80. return parent::beforeAction($action);
  81. }
  82. }