BaseController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\admin\classes\AdminClass;
  4. use biz\shop\classes\ShopAdminClass;
  5. use biz\sj\classes\MerchantExtendClass;
  6. use biz\sj\services\MerchantService;
  7. use bizHd\merchant\services\ShopService;
  8. use common\components\jwt;
  9. use Yii;
  10. use common\components\util;
  11. class BaseController extends PublicController
  12. {
  13. public $admin, $adminId, $adminAvatar, $account, $customId = 0, $custom;
  14. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $shop = [], $shopAdminId = 0, $shopAdmin = [];
  15. public $appId;
  16. public $isWx = false;
  17. public $isLogin = false;
  18. //游客可以访问的方法
  19. public $guestAccess = [];
  20. //ssh 2020.3.8
  21. public function beforeAction($action)
  22. {
  23. //定义平台类型 1花店 2供货商 3商城
  24. Yii::$app->params['ptStyle'] = 1;
  25. //token验证
  26. $adminId = jwt::getLoginId();
  27. if (empty($adminId)) {
  28. util::notLogin();
  29. }
  30. $admin = AdminClass::getAdminById($adminId, true);
  31. if (empty($admin)) {
  32. util::notLogin();
  33. }
  34. $adminId = $admin['id'];
  35. $this->admin = $admin;
  36. $this->adminId = $adminId;
  37. //后台
  38. $currentShopId = $admin['currentShopId'] ?? 0;
  39. if (empty($currentShopId)) {
  40. if (in_array($action->id, $this->guestAccess) == false) {
  41. util::fail('您不是员工没有权限访问');
  42. }
  43. } else {
  44. $this->shopId = $currentShopId;
  45. $shop = ShopService::getById($currentShopId);
  46. $this->shop = $shop;
  47. if (empty($shop)) {
  48. util::fail('没有找到店铺');
  49. }
  50. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId]);
  51. if (empty($shopAdmin)) {
  52. util::logout('没有找到员工信息');
  53. }
  54. if (isset($shopAdmin['delStatus']) && $shopAdmin['delStatus'] == 1) {
  55. util::fail('您还不是员工哦');
  56. }
  57. if (isset($shopAdmin['status']) && $shopAdmin['status'] == 0) {
  58. util::fail('您的帐号已被禁用');
  59. }
  60. $this->shopAdmin = $shopAdmin;
  61. $this->shopAdminId = $shopAdmin['id'] ?? 0;
  62. $sjId = $shop['merchantId'];
  63. $this->sjId = $sjId;
  64. $sj = MerchantService::getMerchantById($sjId);
  65. $this->sj = $sj;
  66. $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  67. $this->sjExtend = $sjExtend;
  68. }
  69. return parent::beforeAction($action);
  70. }
  71. }