BaseController.php 2.8 KB

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