BaseController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopAdminClass;
  4. use biz\shop\classes\ShopClass;
  5. use biz\shop\classes\ShopExtClass;
  6. use biz\sj\classes\SjClass;
  7. use biz\sj\services\MerchantExtendService;
  8. use bizGhs\admin\services\AdminService;
  9. use bizGhs\shop\classes\MainClass;
  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, $account;
  17. public $sjId = 0, $sj = [], $sjExtend = [];
  18. public $shop, $shopExt = [], $shopId = 0;
  19. public $mainId = 0, $main = [];
  20. public $shopAdminId = 0, $shopAdmin;
  21. public $appId;
  22. //不需要登陆的方法名
  23. public $guestAccess = [];
  24. //ssh 2020.3.8
  25. public function beforeAction($action)
  26. {
  27. //定义平台类型 1花店 2供货商
  28. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  29. // 客户端协议版本:2=旧版「待结+余额」双字段;3=仅净余额 balance(见 AccountMoneyClass)
  30. $headers = Yii::$app->getRequest()->getHeaders();
  31. Yii::$app->params['clientAppVersion'] = (int)$headers->get('appVersion', 2);
  32. // $headers = Yii::$app->getRequest()->getHeaders();
  33. // $requestVersion = $headers->get('appVersion');
  34. // $currentVersion = dict::getDict('appVersion');
  35. // if ($requestVersion < $currentVersion) {
  36. // if (in_array($action->id, $this->guestAccess) == false) {
  37. // //util::fail('请先升级系统');
  38. // }
  39. // }
  40. //token验证
  41. $adminId = jwt::getLoginId();
  42. //将石少华的号模拟成别人的号进行测试,有多处需要同步修改,关键词 simulate_other ssh 20250717
  43. $simulateKey = 'simulate_admin_id';
  44. $simulateId = Yii::$app->redis->executeCommand('GET', [$simulateKey]);
  45. if (!empty($simulateId) && $simulateId > 0) {
  46. if (getenv('YII_ENV') == 'production') {
  47. if ($adminId == 4) {
  48. $adminId = $simulateId;
  49. }
  50. } else {
  51. if ($adminId == 919) {
  52. $adminId = $simulateId;
  53. }
  54. }
  55. }
  56. if (empty($adminId) && in_array($action->id, $this->guestAccess) == false) {
  57. util::notLogin();
  58. }
  59. $this->adminId = $adminId;
  60. $admin = AdminService::getById($adminId, true);
  61. if (empty($admin) && in_array($action->id, $this->guestAccess) == false) {
  62. util::logout('帐号无效');
  63. }
  64. $this->admin = $admin;
  65. //后台
  66. $currentShopId = $admin->currentGhsShopId ?? 0;
  67. if (empty($currentShopId)) {
  68. if (in_array($action->id, $this->guestAccess) == false) {
  69. util::fail('请注册登录');
  70. }
  71. } else {
  72. $this->shopId = $currentShopId;
  73. $shop = ShopClass::getById($currentShopId, true);
  74. if (empty($shop)) {
  75. util::fail('没有找到您的门店');
  76. }
  77. $this->shop = $shop;
  78. $mainId = $shop->mainId ?? 0;
  79. $this->mainId = $mainId;
  80. $main = MainClass::getById($mainId, true);
  81. if (empty($main)) {
  82. util::fail('没有main信息17,shopId:' . $this->shopId);
  83. }
  84. $this->main = $main;
  85. $shopExt = ShopExtClass::getByCondition(['shopId' => $currentShopId], true);
  86. if (empty($shopExt)) {
  87. util::fail('门店信息有问题,请联系管理员');
  88. }
  89. $this->shopExt = $shopExt;
  90. $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true);
  91. if (empty($shopAdmin)) {
  92. util::logout('没有找到员工');
  93. }
  94. // if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) { //第95行查询时已限定 'delStatus' => 0, $shopAdmin->delStatus == 1 永远不会成立
  95. // util::fail('您不是本店员工哦');
  96. // }
  97. if (isset($shopAdmin->status) && $shopAdmin->status == 0) {
  98. util::fail('您已被平台禁止登录');
  99. }
  100. $this->shopAdmin = $shopAdmin;
  101. $this->shopAdminId = $shopAdmin->id ?? 0;
  102. $sjId = $shop->sjId;
  103. $this->sjId = $sjId;
  104. $sj = SjClass::getById($sjId, true);
  105. $this->sj = $sj;
  106. $sjExtend = MerchantExtendService::getBySjId($sjId, true);
  107. $this->sjExtend = $sjExtend;
  108. }
  109. return parent::beforeAction($action);
  110. }
  111. }