BaseController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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, $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;
  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. $this->shop = $shop;
  58. if (empty($shop)) {
  59. util::fail('没有找到店铺');
  60. }
  61. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
  62. if (empty($shopAdmin)) {
  63. util::logout('没有找到员工信息');
  64. }
  65. if (isset($shopAdmin->delStatus) == false || $shopAdmin->delStatus == 1) {
  66. util::fail('您还不是员工哦');
  67. }
  68. if (isset($shopAdmin->status) == false || $shopAdmin->status == 0) {
  69. util::fail('您的帐号已被禁用');
  70. }
  71. $this->shopAdmin = $shopAdmin;
  72. $this->shopAdminId = $shopAdmin->id ?? 0;
  73. $sjId = $shop->sjId;
  74. $this->sjId = $sjId;
  75. $sj = SjClass::getById($sjId, true);
  76. $this->sj = $sj;
  77. $sjExtend = MerchantExtendClass::getBySjId($sjId, true);
  78. $this->sjExtend = $sjExtend;
  79. }
  80. return parent::beforeAction($action);
  81. }
  82. }