BaseController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\admin\classes\AdminClass;
  4. use bizHd\admin\services\ShopAdminService;
  5. use bizHd\custom\classes\CustomClass;
  6. use biz\shop\classes\ShopAdminClass;
  7. use biz\sj\classes\MerchantExtendClass;
  8. use bizHd\merchant\classes\ShopClass;
  9. use bizHd\merchant\services\AdminService;
  10. use biz\sj\services\MerchantExtendService;
  11. use biz\sj\services\MerchantService;
  12. use bizHd\merchant\services\ShopService;
  13. use bizHd\wx\services\WxOpenService;
  14. use common\components\httpUtil;
  15. use common\components\jwt;
  16. use Yii;
  17. use common\components\util;
  18. class BaseController extends PublicController
  19. {
  20. public $admin, $adminId, $adminAvatar, $account, $customId = 0, $custom;
  21. public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $shop = [], $shopAdminId = 0, $shopAdmin = [];
  22. public $appId;
  23. public $isWx = false;
  24. public $isLogin = false;
  25. //游客可以访问的方法
  26. public $guestAccess = [];
  27. //ssh 2020.3.8
  28. public function beforeAction($action)
  29. {
  30. //定义平台类型 1花店 2供货商 3商城
  31. Yii::$app->params['ptStyle'] = 1;
  32. //token验证
  33. $adminId = jwt::getLoginId();
  34. if (empty($adminId)) {
  35. util::notLogin();
  36. }
  37. $admin = AdminClass::getAdminById($adminId, true);
  38. if (empty($admin)) {
  39. util::notLogin();
  40. }
  41. $adminId = $admin['id'];
  42. $this->admin = $admin;
  43. $this->adminId = $adminId;
  44. $header = httpUtil::getHeader();
  45. $lookShopId = $header['shop-id'] ?? 0;
  46. if (!empty($lookShopId)) {
  47. //商城
  48. if (in_array($action->id, $this->guestAccess) == false) {
  49. util::fail('您没有权限访问哦');
  50. }
  51. $shop = ShopClass::getById($lookShopId);
  52. if (empty($shop)) {
  53. util::fail('没有找到店铺');
  54. }
  55. $sjId = $shop['merchantId'] ?? 0;
  56. //新增并获取客户信息
  57. $custom = CustomClass::replaceCustom($sjId, $admin);
  58. $customId = $custom['id'] ?? 0;
  59. if (empty($customId)) {
  60. util::fail('没有找到客户信息');
  61. }
  62. $this->custom = $custom;
  63. $this->customId = $customId;
  64. $this->sjId = $sjId;
  65. $sj = MerchantService::getMerchantById($sjId);
  66. $this->sj = $sj;
  67. $this->sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  68. } else {
  69. //后台
  70. $currentShopId = $admin['currentShopId'] ?? 0;
  71. if (empty($currentShopId)) {
  72. if (in_array($action->id, $this->guestAccess) == false) {
  73. util::fail('您不是员工没有权限访问');
  74. }
  75. } else {
  76. $this->shopId = $currentShopId;
  77. $shop = ShopService::getById($currentShopId);
  78. $this->shop = $shop;
  79. if (empty($shop)) {
  80. util::fail('没有找到店铺');
  81. }
  82. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0]);
  83. if (empty($shopAdmin)) {
  84. util::fail('没有找到员工信息');
  85. }
  86. $this->shopAdmin = $shopAdmin;
  87. $this->shopAdminId = $shopAdmin['id'] ?? 0;
  88. $sjId = $shop['merchantId'];
  89. $this->sjId = $sjId;
  90. $sj = MerchantService::getMerchantById($sjId);
  91. $this->sj = $sj;
  92. $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  93. $this->sjExtend = $sjExtend;
  94. }
  95. }
  96. return parent::beforeAction($action);
  97. }
  98. }