LevelController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace addons\TinyShop\api\modules\v1\controllers\member;
  3. use Yii;
  4. use yii\data\ActiveDataProvider;
  5. use api\controllers\OnAuthController;
  6. use common\enums\StatusEnum;
  7. use common\models\member\Level;
  8. use common\enums\MemberLevelUpgradeTypeEnum;
  9. /**
  10. * Class LevelController
  11. * @package addons\TinyShop\api\modules\v1\controllers\member
  12. * @author jianyan74 <751393839@qq.com>
  13. */
  14. class LevelController extends OnAuthController
  15. {
  16. /**
  17. * @var Level
  18. */
  19. public $modelClass = Level::class;
  20. /**
  21. * @return ActiveDataProvider
  22. */
  23. public function actionIndex()
  24. {
  25. $data = new ActiveDataProvider([
  26. 'query' => $this->modelClass::find()
  27. ->where(['status' => StatusEnum::ENABLED])
  28. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  29. ->orderBy('level asc')
  30. ->asArray(),
  31. 'pagination' => [
  32. 'pageSize' => $this->pageSize,
  33. 'validatePage' => false,// 超出分页不返回data
  34. ],
  35. ]);
  36. $memberLevelUpgradeType = Yii::$app->debris->backendConfig('member_level_upgrade_type');
  37. $models = $data->getModels();
  38. foreach ($models as &$model) {
  39. $model['remark'] = [];
  40. switch ($memberLevelUpgradeType) {
  41. case MemberLevelUpgradeTypeEnum::CONSUMPTION_INTEGRAL :
  42. $model['remark'] = '累计积分满 ' . $model['integral'] . ' 积分';
  43. break;
  44. case MemberLevelUpgradeTypeEnum::CONSUMPTION_MONEY :
  45. $model['remark'] = '消费金额满 ' . $model['money'] . ' 元';
  46. break;
  47. case MemberLevelUpgradeTypeEnum::CONSUMPTION_GROWTH :
  48. $model['remark'] = '消费成长值满 ' . $model['money'];
  49. break;
  50. }
  51. }
  52. $data->setModels($models);
  53. return $data;
  54. }
  55. /**
  56. * 权限验证
  57. *
  58. * @param string $action 当前的方法
  59. * @param null $model 当前的模型类
  60. * @param array $params $_GET变量
  61. * @throws \yii\web\BadRequestHttpException
  62. */
  63. public function checkAccess($action, $model = null, $params = [])
  64. {
  65. // 方法名称
  66. if (in_array($action, ['delete', 'update', 'create'])) {
  67. throw new \yii\web\BadRequestHttpException('权限不足');
  68. }
  69. }
  70. }
粤ICP备19079148号