BaseController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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)) {
  34. util::notLogin();
  35. }
  36. $admin = AdminClass::getById($adminId, true);
  37. if (empty($admin)) {
  38. util::notLogin();
  39. }
  40. $adminId = $admin->id;
  41. $this->admin = $admin;
  42. $this->adminId = $adminId;
  43. // 只能供应商访问
  44. if ($admin->style != ClassesAdminClass::STYLE_HD) {
  45. util::fail('您没有权限访问哦!');
  46. }
  47. //后台
  48. $currentShopId = $admin->currentShopId ?? 0;
  49. if (empty($currentShopId)) {
  50. if (in_array($action->id, $this->guestAccess) == false) {
  51. util::fail('您不是员工没有权限访问');
  52. }
  53. } else {
  54. $this->shopId = $currentShopId;
  55. $shop = ShopService::getById($currentShopId, true);
  56. $this->shop = $shop;
  57. if (empty($shop)) {
  58. util::fail('没有找到店铺');
  59. }
  60. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
  61. if (empty($shopAdmin)) {
  62. util::logout('没有找到员工信息');
  63. }
  64. if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) {
  65. util::fail('您还不是员工哦');
  66. }
  67. if (isset($shopAdmin->status) && $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. }