BaseController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopAdminClass;
  4. use biz\shop\classes\ShopClass;
  5. use biz\sj\classes\MerchantExtendClass;
  6. use biz\sj\services\MerchantExtendService;
  7. use biz\sj\services\MerchantService;
  8. use bizGhs\merchant\services\ShopService;
  9. use bizHd\wx\services\WxOpenService;
  10. use bizGhs\admin\services\AdminService;
  11. use bizGhs\shop\services\ShopAdminService;
  12. use common\components\httpUtil;
  13. use common\components\jwt;
  14. use common\components\noticeUtil;
  15. use common\components\stringUtil;
  16. use Yii;
  17. use common\components\util;
  18. class BaseController extends PublicController
  19. {
  20. public $admin, $adminId, $adminAvatar, $account;
  21. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shop = [], $shopId = 0, $lookShopId = 0, $shopAdminId = 0, $shopAdmin = [];
  22. public $appId;
  23. public $isWx = false;
  24. public $isLogin = false;
  25. public $guestAccess = [];//不需要登陆的方法名
  26. //ssh 2020.3.8
  27. public function beforeAction($action)
  28. {
  29. //定义平台类型 1花店 2供货商
  30. Yii::$app->params['ptStyle'] = 2;
  31. //token验证
  32. $adminId = jwt::getLoginId();
  33. //$adminId = 18;
  34. if (empty($adminId)) {
  35. util::notLogin();
  36. }
  37. $this->adminId = $adminId;
  38. $admin = AdminService::getById($adminId);
  39. if (empty($admin)) {
  40. util::fail('帐号无效');
  41. }
  42. $this->admin = $admin;
  43. //后台
  44. $currentShopId = $admin['currentShopId'] ?? 0;
  45. if (empty($currentShopId)) {
  46. if (in_array($action->id, $this->guestAccess) == false) {
  47. util::fail('您没有权限访问哦!');
  48. }
  49. } else {
  50. $this->shopId = $currentShopId;
  51. $shop = ShopClass::getShopInfo($currentShopId);
  52. $this->shop = $shop;
  53. if (empty($shop)) {
  54. util::fail('没有找到您管理的门店');
  55. }
  56. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0]);
  57. if (empty($shopAdmin)) {
  58. util::fail('没有找到员工信息');
  59. }
  60. $this->shopAdmin = $shopAdmin;
  61. $this->shopAdminId = $shopAdmin['id'] ?? 0;
  62. $sjId = $shop['merchantId'];
  63. $this->sjId = $sjId;
  64. $sj = MerchantService::getMerchantById($sjId);
  65. $this->sj = $sj;
  66. $sjExtend = MerchantExtendService::getByMerchantId($sjId);
  67. $this->sjExtend = $sjExtend;
  68. }
  69. return parent::beforeAction($action);
  70. }
  71. }