SingleController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace addons\TinyBlog\merchant\controllers;
  3. use Yii;
  4. use common\models\base\SearchModel;
  5. use common\traits\MerchantCurd;
  6. use common\enums\StatusEnum;
  7. use addons\TinyBlog\common\models\Single;
  8. /**
  9. * Class SingleController
  10. * @package addons\TinyBlog\merchant\controllers
  11. * @author jianyan74 <751393839@qq.com>
  12. */
  13. class SingleController extends BaseController
  14. {
  15. use MerchantCurd;
  16. /**
  17. * @var Single
  18. */
  19. public $modelClass = Single::class;
  20. /**
  21. * 首页
  22. *
  23. * @return string
  24. * @throws \yii\web\NotFoundHttpException
  25. */
  26. public function actionIndex()
  27. {
  28. $searchModel = new SearchModel([
  29. 'model' => $this->modelClass,
  30. 'scenario' => 'default',
  31. 'partialMatchAttributes' => ['title'], // 模糊查询
  32. 'defaultOrder' => [
  33. 'sort' => SORT_ASC,
  34. 'id' => SORT_DESC
  35. ],
  36. 'pageSize' => $this->pageSize
  37. ]);
  38. $dataProvider = $searchModel
  39. ->search(Yii::$app->request->queryParams);
  40. $dataProvider->query
  41. ->andWhere(['>=', 'status', StatusEnum::DISABLED])
  42. ->andWhere(['merchant_id' => $this->getMerchantId()]);
  43. return $this->render($this->action->id, [
  44. 'dataProvider' => $dataProvider,
  45. 'searchModel' => $searchModel,
  46. ]);
  47. }
  48. }
粤ICP备19079148号