NotifyController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace common\widgets\notify;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. use common\models\base\SearchModel;
  6. use common\models\common\NotifyMember;
  7. use common\helpers\ResultHelper;
  8. use backend\controllers\BaseController;
  9. /**
  10. * Class NotifyController
  11. * @package common\widgets\notify
  12. * @author jianyan74 <751393839@qq.com>
  13. */
  14. class NotifyController extends BaseController
  15. {
  16. protected $view = '@common/widgets/notify/views/';
  17. /**
  18. * 提醒
  19. *
  20. * @return string
  21. * @throws \yii\web\NotFoundHttpException
  22. */
  23. public function actionRemind()
  24. {
  25. $type = Yii::$app->request->get('type');
  26. $searchModel = new SearchModel([
  27. 'model' => NotifyMember::class,
  28. 'scenario' => 'default',
  29. 'partialMatchAttributes' => [], // 模糊查询
  30. 'defaultOrder' => [
  31. 'id' => SORT_DESC
  32. ],
  33. 'pageSize' => $this->pageSize
  34. ]);
  35. $dataProvider = $searchModel
  36. ->search(Yii::$app->request->queryParams);
  37. $dataProvider->query
  38. ->with(['notify'])
  39. ->andWhere(['>=', 'status', StatusEnum::DISABLED])
  40. ->andWhere(['merchant_id' => Yii::$app->user->identity->merchant_id])
  41. ->andFilterWhere(['type' => $type]);
  42. return $this->render($this->view . $this->action->id, [
  43. 'dataProvider' => $dataProvider,
  44. 'searchModel' => $searchModel,
  45. 'type' => $type,
  46. ]);
  47. }
  48. /**
  49. * 公告详情
  50. *
  51. * @param $id
  52. * @return mixed|string
  53. */
  54. public function actionAnnounceView($id)
  55. {
  56. if (empty($id) || empty(($model = NotifyMember::find()->where([
  57. 'id' => $id,
  58. 'status' => StatusEnum::ENABLED
  59. ])->with(['notify'])->one()))) {
  60. return $this->message('找不到该公告', $this->redirect(['index']), 'error');
  61. }
  62. // 设置公告为已读
  63. Yii::$app->services->notifyMember->readByNotifyId(Yii::$app->user->id, Yii::$app->user->identity->merchant_id, [$model->notify_id]);
  64. return $this->render($this->view . $this->action->id, [
  65. 'model' => Yii::$app->services->notifyAnnounce->findById($model->notify->target_id),
  66. ]);
  67. }
  68. /**
  69. * @return mixed
  70. */
  71. public function actionRead()
  72. {
  73. $ids = Yii::$app->request->post('ids');
  74. if (empty($ids)) {
  75. return ResultHelper::json(422, '请至少选中一项');
  76. }
  77. Yii::$app->services->notifyMember->readById(Yii::$app->user->id, Yii::$app->user->identity->merchant_id, $ids);
  78. return ResultHelper::json(200, 'ok');
  79. }
  80. /**
  81. * @return mixed
  82. */
  83. public function actionDeleteAll()
  84. {
  85. $ids = Yii::$app->request->post('ids');
  86. if (empty($ids)) {
  87. return ResultHelper::json(422, '请至少选中一项');
  88. }
  89. Yii::$app->services->notifyMember->deleteById(Yii::$app->user->identity->merchant_id, $ids);
  90. return ResultHelper::json(200, 'ok');
  91. }
  92. /**
  93. * @return mixed
  94. */
  95. public function actionReadAll()
  96. {
  97. Yii::$app->services->notifyMember->readAll(Yii::$app->user->id, Yii::$app->user->identity->merchant_id);
  98. return $this->message('全部设为已读成功', $this->redirect(['remind']));
  99. }
  100. }
粤ICP备19079148号