BaseController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 $guestAccessAction = [];
  27. //shish 2020.3.8
  28. public function beforeAction($action)
  29. {
  30. //定义平台类型 1花店 2供货商
  31. Yii::$app->params['ptStyle'] = 1;
  32. //token验证
  33. $adminId = jwt::getLoginId();
  34. if (empty($adminId)) {
  35. util::notLogin();
  36. }
  37. $sjId = 0;
  38. $sj = [];
  39. $sjExtend = [];
  40. $currentShopId = 0;
  41. $admin = AdminClass::getAdminById($adminId, true);
  42. if (empty($admin)) {
  43. util::notLogin();
  44. }
  45. $adminId = $admin['id'];
  46. $this->admin = $admin;
  47. $this->adminId = $adminId;
  48. $header = httpUtil::getHeader();
  49. $lookShopId = $header['shop-id'] ?? 0;
  50. if (!empty($lookShopId)) {
  51. //商城
  52. if (in_array($action->id, $this->guestAccessAction) == false) {
  53. util::fail('您没有权限访问哦');
  54. }
  55. $shop = ShopClass::getById($lookShopId);
  56. if (empty($shop)) {
  57. util::fail('没有找到店铺');
  58. }
  59. $sjId = $shop['merchantId'] ?? 0;
  60. //新增并获取客户信息
  61. $custom = CustomClass::replaceCustom($sjId, $admin);
  62. dd($custom);
  63. $customId = $custom['id'] ?? 0;
  64. if (empty($customId)) {
  65. util::fail('没有找到客户信息');
  66. }
  67. $this->custom = $custom;
  68. $this->customId = $customId;
  69. $this->sjId = $sjId;
  70. $sj = MerchantService::getMerchantById($sjId);
  71. $this->sj = $sj;
  72. $this->sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  73. } else {
  74. //后台
  75. $currentShopId = $admin['currentShopId'] ?? 0;
  76. if (empty($currentShopId) && in_array($action->id, $this->guestAccessAction) == false) {
  77. util::fail('您没有权限访问哦~');
  78. }
  79. $this->shopId = $currentShopId;
  80. $shop = ShopService::getById($currentShopId);
  81. $this->shop = $shop;
  82. if (empty($shop)) {
  83. util::fail('没有找到店铺');
  84. }
  85. $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0]);
  86. if (empty($shopAdmin)) {
  87. util::fail('没有找到员工信息');
  88. }
  89. $this->shopAdmin = $shopAdmin;
  90. $this->shopAdminId = $shopAdmin['id'] ?? 0;
  91. $sjId = $shop['merchantId'];
  92. $this->sjId = $sjId;
  93. $sj = MerchantService::getMerchantById($sjId);
  94. $this->sj = $sj;
  95. $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
  96. $this->sjExtend = $sjExtend;
  97. }
  98. return parent::beforeAction($action);
  99. }
  100. }