BaseController.php 3.2 KB

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