HelperController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace addons\TinyShop\api\modules\v1\controllers\common;
  3. use Yii;
  4. use api\controllers\OnAuthController;
  5. use common\helpers\ArrayHelper;
  6. use addons\TinyShop\common\models\common\Helper;
  7. /**
  8. * Class HelperController
  9. * @package addons\TinyShop\api\modules\v1\controllers\common
  10. * @author jianyan74 <751393839@qq.com>
  11. */
  12. class HelperController extends OnAuthController
  13. {
  14. /**
  15. * @var Helper
  16. */
  17. public $modelClass = Helper::class;
  18. /**
  19. * 不用进行登录验证的方法
  20. * 例如: ['index', 'update', 'create', 'view', 'delete']
  21. * 默认全部需要验证
  22. *
  23. * @var array
  24. */
  25. protected $authOptional = ['index', 'view'];
  26. /**
  27. * @return array|\yii\data\ActiveDataProvider
  28. */
  29. public function actionIndex()
  30. {
  31. $data = Yii::$app->tinyShopService->helper->findAll();
  32. return ArrayHelper::itemsMerge($data, 0, 'id', 'pid', 'child');
  33. }
  34. /**
  35. * 权限验证
  36. *
  37. * @param string $action 当前的方法
  38. * @param null $model 当前的模型类
  39. * @param array $params $_GET变量
  40. * @throws \yii\web\BadRequestHttpException
  41. */
  42. public function checkAccess($action, $model = null, $params = [])
  43. {
  44. // 方法名称
  45. if (in_array($action, ['delete', 'create', 'update'])) {
  46. throw new \yii\web\BadRequestHttpException('权限不足');
  47. }
  48. }
  49. }
粤ICP备19079148号