NoticeController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Actions\Notice\NoticeSend;
  4. use App\Models\Notice;
  5. use App\Models\User;
  6. use App\Services\JPushService;
  7. use Dcat\Admin\Form;
  8. use Dcat\Admin\Grid;
  9. use Dcat\Admin\Show;
  10. use Dcat\Admin\Http\Controllers\AdminController;
  11. use Faker\Factory;
  12. class NoticeController extends AdminController
  13. {
  14. /**
  15. * Make a grid builder.
  16. *
  17. * @return Grid
  18. */
  19. protected function grid()
  20. {
  21. $grid = new Grid(new Notice());
  22. $grid->model()->orderBy('id','desc');
  23. $grid->column('id')->sortable();
  24. $grid->column('title');
  25. $grid->column('content')->limit(60);
  26. $grid->column('users')->using(['全部用户','男性用户','女性用户'])->label(['success','primary','warning']);
  27. $grid->column('created_at');
  28. //$grid->column('updated_at')->sortable();
  29. $grid->filter(function (Grid\Filter $filter) {
  30. $filter->equal('id');
  31. });
  32. //操作管理
  33. // $grid->actions(function (Grid\Displayers\Actions $actions) {
  34. // $actions->append(new NoticeSend(User::class));
  35. // });
  36. return $grid;
  37. }
  38. /**
  39. * Make a show builder.
  40. *
  41. * @param mixed $id
  42. *
  43. * @return Show
  44. */
  45. protected function detail($id)
  46. {
  47. return Show::make($id, new Notice(), function (Show $show) {
  48. $show->field('id');
  49. $show->field('title');
  50. $show->field('content')->unescape();
  51. $show->field('users')->using(['全部用户','男性用户','女性用户']);
  52. $show->field('created_at');
  53. $show->field('updated_at');
  54. });
  55. }
  56. /**
  57. * Make a form builder.
  58. *
  59. * @return Form
  60. */
  61. protected function form()
  62. {
  63. return Form::make(new Notice(), function (Form $form) {
  64. $form->display('id');
  65. $form->text('title');
  66. $form->editor('content');
  67. $form->radio('users')->options([0=>'全部用户',1=>'男性用户',2=>"女性用户"])->default(0);
  68. $form->display('created_at');
  69. $form->display('updated_at');
  70. $form->saved(function (){
  71. //推送消息
  72. JPushService::pushNotify([
  73. //标题
  74. 'title' => '测试',
  75. //内容
  76. 'content' => '测试',
  77. //设备标识,跟设备相关
  78. 'reg_id' => 'xxxxxxxxxxx',
  79. //扩展字段
  80. 'extras' => [
  81. 'key' => 'value',
  82. ],
  83. //推送类型
  84. 'type' => JPushService::PUSH_TYPE_ALL,
  85. ]);
  86. });
  87. });
  88. }
  89. }