BaseController.php 2.6 KB

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