BaseController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. $header = httpUtil::getHeader();
  44. $lookShopId = $header['shop-id'] ?? 0;
  45. if (!empty($lookShopId)) {
  46. //商城和下单页
  47. if (in_array($action->id, $this->guestAccess) == false) {
  48. util::fail('您没有权限访问哦~');
  49. }
  50. $shop = ShopClass::getById($lookShopId);
  51. if (empty($shop)) {
  52. util::fail('没有找到店铺');
  53. }
  54. $this->lookShopId = $lookShopId;
  55. $sjId = $shop['merchantId'] ?? 0;
  56. $sj = MerchantService::getMerchantById($sjId);
  57. $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  58. $this->sj = $sj;
  59. $this->sjExtend = $sjExtend;
  60. } else {
  61. //后台
  62. $currentShopId = $admin['currentShopId'] ?? 0;
  63. if(empty($currentShopId)){
  64. if( in_array($action->id, $this->guestAccess) == false){
  65. util::fail('您没有权限访问哦!');
  66. }
  67. }else{
  68. $this->shopId = $currentShopId;
  69. $shop = ShopClass::getShopInfo($currentShopId);
  70. $this->shop = $shop;
  71. if (empty($shop)) {
  72. util::fail('没有找到您管理的门店');
  73. }
  74. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0]);
  75. if (empty($shopAdmin)) {
  76. util::fail('没有找到员工信息');
  77. }
  78. $this->shopAdmin = $shopAdmin;
  79. $this->shopAdminId = $shopAdmin['id'] ?? 0;
  80. $sjId = $shop['merchantId'];
  81. $this->sjId = $sjId;
  82. $sj = MerchantService::getMerchantById($sjId);
  83. $this->sj = $sj;
  84. $sjExtend = MerchantExtendService::getByMerchantId($sjId);
  85. $this->sjExtend = $sjExtend;
  86. }
  87. }
  88. return parent::beforeAction($action);
  89. }
  90. }