NotifyAnnounceController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace addons\TinyShop\merchant\modules\common\controllers;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. use common\traits\MerchantCurd;
  6. use common\models\base\SearchModel;
  7. use addons\TinyShop\common\models\common\NotifyAnnounce;
  8. use addons\TinyShop\backend\controllers\BaseController;
  9. /**
  10. * 公告
  11. *
  12. * Class NotifyAnnounceController
  13. * @package addons\TinyShop\merchant\modules\common\controllers
  14. * @author jianyan74 <751393839@qq.com>
  15. */
  16. class NotifyAnnounceController extends BaseController
  17. {
  18. use MerchantCurd;
  19. /**
  20. * @var NotifyAnnounce
  21. */
  22. public $modelClass = NotifyAnnounce::class;
  23. /**
  24. * @return string
  25. * @throws \yii\web\NotFoundHttpException
  26. */
  27. public function actionIndex()
  28. {
  29. $searchModel = new SearchModel([
  30. 'model' => $this->modelClass,
  31. 'scenario' => 'default',
  32. 'partialMatchAttributes' => ['title'], // 模糊查询
  33. 'defaultOrder' => [
  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. /**
  49. * 编辑/创建
  50. *
  51. * @return mixed
  52. */
  53. public function actionEdit()
  54. {
  55. $id = Yii::$app->request->get('id', null);
  56. $model = $this->findModel($id);
  57. $model->member_id = Yii::$app->user->id;
  58. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  59. return $this->redirect(['index']);
  60. }
  61. return $this->render($this->action->id, [
  62. 'model' => $model,
  63. ]);
  64. }
  65. }
粤ICP备19079148号