BaseController.php 2.8 KB

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