MerchantBehaviors.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers\cloud\behaviors;
  8. use app\models\StoreCloud;
  9. use Yii;
  10. use yii\base\ActionFilter;
  11. use yii\helpers\Json;
  12. use yii\web\Response;
  13. class MerchantBehaviors extends ActionFilter
  14. {
  15. // 接口白名单
  16. public static $allow_list = [
  17. ];
  18. public function beforeAction($action)
  19. {
  20. $params_r = $_REQUEST['r'];
  21. if (in_array($params_r, self::$allow_list)) {
  22. return true;
  23. }
  24. // 判断当前商城是否创建云仓数据
  25. $store_id = get_store_id();
  26. $storeCloud = StoreCloud::find()->where(['store_id' => $store_id,'is_delete'=>0])->one();
  27. if (!$storeCloud) {
  28. \Yii::$app->response->format = Response::FORMAT_JSON;
  29. Yii::$app->response->data = [
  30. 'code' => 1,
  31. 'msg' => '未创建云仓商户,请联系管理员添加'
  32. ];
  33. return false;
  34. }
  35. // 重置token
  36. $token = get_merchant_token();
  37. if (!$token) {
  38. \Yii::$app->response->format = Response::FORMAT_JSON;
  39. Yii::$app->response->data = [
  40. 'code' => 1,
  41. 'msg' => '账户异常,请联系管理员处理'
  42. ];
  43. return false;
  44. }
  45. return parent::beforeAction($action);
  46. }
  47. }