UserAuthController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace api\controllers;
  3. use Yii;
  4. use yii\data\ActiveDataProvider;
  5. use yii\web\NotFoundHttpException;
  6. use common\enums\StatusEnum;
  7. /**
  8. * 个人信息访问基类
  9. *
  10. * 注意:适用于个人中心
  11. *
  12. * Class UserAuthController
  13. * @package api\controllers
  14. * @property yii\db\ActiveRecord|yii\base\Model $modelClass
  15. * @author jianyan74 <751393839@qq.com>
  16. */
  17. class UserAuthController extends OnAuthController
  18. {
  19. /**
  20. * 首页
  21. *
  22. * @return ActiveDataProvider
  23. */
  24. public function actionIndex()
  25. {
  26. return new ActiveDataProvider([
  27. 'query' => $this->modelClass::find()
  28. ->where(['status' => StatusEnum::ENABLED, 'member_id' => Yii::$app->user->identity->member_id])
  29. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  30. ->orderBy('id desc')
  31. ->asArray(),
  32. 'pagination' => [
  33. 'pageSize' => $this->pageSize,
  34. 'validatePage' => false,// 超出分页不返回data
  35. ],
  36. ]);
  37. }
  38. /**
  39. * @param $id
  40. * @return \yii\db\ActiveRecord
  41. * @throws NotFoundHttpException
  42. */
  43. protected function findModel($id)
  44. {
  45. /* @var $model \yii\db\ActiveRecord */
  46. if (empty($id) || !($model = $this->modelClass::find()->where([
  47. 'id' => $id,
  48. 'status' => StatusEnum::ENABLED,
  49. 'member_id' => Yii::$app->user->identity->member_id,
  50. ])->andFilterWhere(['merchant_id' => $this->getMerchantId()])->one())) {
  51. throw new NotFoundHttpException('请求的数据不存在或您的权限不足.');
  52. }
  53. return $model;
  54. }
  55. }
粤ICP备19079148号