NotifyAnnounceController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace backend\modules\common\controllers;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. use common\traits\MerchantCurd;
  6. use common\models\base\SearchModel;
  7. use common\models\common\NotifyAnnounce;
  8. use backend\controllers\BaseController;
  9. /**
  10. * Class BaseNotifyAnnounceController
  11. * @package backend\modules\base\controllers
  12. * @author jianyan74 <751393839@qq.com>
  13. */
  14. class NotifyAnnounceController extends BaseController
  15. {
  16. use MerchantCurd;
  17. /**
  18. * @var NotifyAnnounce
  19. */
  20. public $modelClass = NotifyAnnounce::class;
  21. /**
  22. * @return string
  23. * @throws \yii\web\NotFoundHttpException
  24. */
  25. public function actionIndex()
  26. {
  27. $searchModel = new SearchModel([
  28. 'model' => $this->modelClass,
  29. 'scenario' => 'default',
  30. 'partialMatchAttributes' => ['title'], // 模糊查询
  31. 'defaultOrder' => [
  32. 'id' => SORT_DESC,
  33. ],
  34. 'pageSize' => $this->pageSize,
  35. ]);
  36. $dataProvider = $searchModel
  37. ->search(Yii::$app->request->queryParams);
  38. $dataProvider->query
  39. ->andWhere(['>=', 'status', StatusEnum::DISABLED])
  40. ->andWhere(['merchant_id' => $this->getMerchantId()]);
  41. return $this->render($this->action->id, [
  42. 'dataProvider' => $dataProvider,
  43. 'searchModel' => $searchModel,
  44. ]);
  45. }
  46. /**
  47. * 编辑/创建
  48. *
  49. * @return mixed
  50. */
  51. public function actionEdit()
  52. {
  53. $id = Yii::$app->request->get('id', null);
  54. $model = $this->findModel($id);
  55. $model->member_id = Yii::$app->user->id;
  56. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  57. return $this->redirect(['index']);
  58. }
  59. return $this->render($this->action->id, [
  60. 'model' => $model,
  61. ]);
  62. }
  63. }
粤ICP备19079148号