BaseController.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace hd\controllers;
  3. use biz\sj\classes\SjClass;
  4. use bizHd\admin\classes\AdminClass;
  5. use biz\shop\classes\ShopAdminClass;
  6. use biz\sj\classes\MerchantExtendClass;
  7. use bizHd\merchant\services\ShopService;
  8. use common\components\dict;
  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, $mainId = 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'] = dict::getDict('ptStyle', 'hd');
  26. //token验证
  27. $adminId = jwt::getLoginId();
  28. if (getenv('YII_ENV', 'local') != 'production') {
  29. //$adminId = 253;
  30. }
  31. if (empty($adminId) && in_array($action->id, $this->guestAccess) == false) {
  32. util::notLogin();
  33. }
  34. $admin = AdminClass::getById($adminId, true);
  35. if (empty($admin) && in_array($action->id, $this->guestAccess) == false) {
  36. util::notLogin();
  37. }
  38. $adminId = $admin->id ?? 0;
  39. $this->admin = $admin;
  40. $this->adminId = $adminId;
  41. if (in_array($action->id, $this->guestAccess) == false) {
  42. if ($admin->style != AdminClass::STYLE_HD) {
  43. util::fail('您没有权限访问哦');
  44. }
  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. if (empty($shop)) {
  56. util::fail('没有找到店铺');
  57. }
  58. $this->shop = $shop;
  59. $this->mainId = $shop->mainId ?? 0;
  60. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
  61. if (empty($shopAdmin)) {
  62. util::logout('没有找到员工信息');
  63. }
  64. if (isset($shopAdmin->delStatus) == false || $shopAdmin->delStatus == 1) {
  65. util::fail('您还不是员工哦');
  66. }
  67. if (isset($shopAdmin->status) == false || $shopAdmin->status == 0) {
  68. util::fail('您的帐号已被禁用');
  69. }
  70. $this->shopAdmin = $shopAdmin;
  71. $this->shopAdminId = $shopAdmin->id ?? 0;
  72. $sjId = $shop->sjId;
  73. $this->sjId = $sjId;
  74. $sj = SjClass::getById($sjId, true);
  75. $this->sj = $sj;
  76. $sjExtend = MerchantExtendClass::getBySjId($sjId, true);
  77. $this->sjExtend = $sjExtend;
  78. }
  79. return parent::beforeAction($action);
  80. }
  81. }