BaseController.php 2.9 KB

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