BaseController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if (!empty($shop)) {
  32. $this->shop = $shop;
  33. $sjId = $shop->sjId ?? 0;
  34. $this->sjId = $sjId;
  35. $sj = SjClass::getById($this->sjId, true);
  36. if (empty($sj)) {
  37. util::fail('没有找到商家信息');
  38. }
  39. $this->sj = $sj;
  40. }
  41. }
  42. if (httpUtil::isMiniProgram()) {
  43. $userId = jwt::getLoginId();
  44. if (empty($userId)) {
  45. util::fail('您还没有登陆');
  46. }
  47. $this->userId = $userId;
  48. $user = UserClass::getById($userId, true);
  49. if (empty($user)) {
  50. util::fail('没有找到客户信息');
  51. }
  52. $this->user = $user;
  53. $this->isWx = util::isWx();
  54. if (!empty($shop)) {
  55. $this->sjExtend = MerchantExtendService::getBySjId($this->sjId);
  56. $userInfo = isset($user->attributes) ? $user->attributes : [];
  57. $custom = CustomClass::replaceCustom($this->sjId, $userInfo, $shopId);
  58. if (!empty($custom)) {
  59. $this->custom = $custom;
  60. $customId = $custom['id'] ?? 0;
  61. $this->customId = $customId;
  62. } else {
  63. if (in_array($action->id, $this->guestAccess) == false) {
  64. util::fail('没有找到客户信息哦');
  65. }
  66. }
  67. }
  68. } else {
  69. //非登陆情况的请求,支付宝扫码付款需要用到
  70. }
  71. return parent::beforeAction($action);
  72. }
  73. }