BaseController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace mall\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\classes\SjClass;
  5. use bizHd\custom\classes\CustomClass;
  6. use bizMall\merchant\services\MerchantExtendService;
  7. use bizMall\merchant\services\MerchantService;
  8. use bizMall\user\classes\UserClass;
  9. use bizMall\user\services\UserService;
  10. use common\components\dict;
  11. use common\components\httpUtil;
  12. use common\components\jwt;
  13. use common\components\util;
  14. use function GuzzleHttp\Promise\iter_for;
  15. use Yii;
  16. class BaseController extends PublicController
  17. {
  18. public $validate = true;
  19. public $guestAccess = [];
  20. public $userId = 0, $user, $shopId, $shop;
  21. public $sjId, $sj, $sjExtend, $customId = 0, $custom = [];
  22. public $isWx;
  23. public function beforeAction($action)
  24. {
  25. //定义平台类型 1花店 2供货商 3商城
  26. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'mall');
  27. $shopId = Yii::$app->request->get('account', 0);
  28. $this->shopId = $shopId;
  29. if (!empty($shopId)) {
  30. $shop = ShopClass::getById($shopId, true);
  31. $this->shop = $shop;
  32. }
  33. if (httpUtil::isMiniProgram()) {
  34. $userId = jwt::getLoginId();
  35. if (empty($userId)) {
  36. util::fail('您还没有登陆');
  37. }
  38. $this->userId = $userId;
  39. $user = UserClass::getById($userId, true);
  40. if (empty($user)) {
  41. util::fail('没有找到客户信息');
  42. }
  43. $this->user = $user;
  44. $this->isWx = util::isWx();
  45. if (!empty($shop)) {
  46. $sjId = $shop->sjId ?? 0;
  47. if (empty($sjId)) {
  48. util::fail('没有找到商家哦');
  49. }
  50. $sj = SjClass::getById($sjId, true);
  51. if (empty($sj)) {
  52. util::fail('没有找到商家信息');
  53. }
  54. $this->sjId = $sjId;
  55. $this->sj = $sj;
  56. $this->sjExtend = MerchantExtendService::getBySjId($sjId);
  57. $userInfo = isset($user->attributes) ? $user->attributes : [];
  58. $custom = CustomClass::replaceCustom($sjId, $userInfo, $shopId);
  59. if (!empty($custom)) {
  60. $this->custom = $custom;
  61. $customId = $custom['id'] ?? 0;
  62. $this->customId = $customId;
  63. } else {
  64. if (in_array($action->id, $this->guestAccess) == false) {
  65. util::fail('没有找到客户信息哦');
  66. }
  67. }
  68. }
  69. } else {
  70. //非登陆情况的请求,支付宝扫码付款需要用到
  71. }
  72. return parent::beforeAction($action);
  73. }
  74. }