WxPostsCommentManualController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Admin\Controllers\Posts;
  3. use App\Admin\Repositories\Posts\WxPostsCommentManual;
  4. use App\Wen\Utils\Settings;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. use Illuminate\Support\Carbon;
  10. use Illuminate\Support\Facades\Cache;
  11. class WxPostsCommentManualController extends AdminController
  12. {
  13. /**
  14. * Make a grid builder.
  15. *
  16. * @return Grid
  17. */
  18. protected function grid()
  19. {
  20. return Grid::make(new WxPostsCommentManual(), function (Grid $grid) {
  21. $grid->column('id')->sortable();
  22. $grid->column('owers', '头像')->display(function ($v) {
  23. if($this->ower['user_avatar'] ?? '') {
  24. return '<img src="' . ($this->ower['user_avatar'] ?? Settings::get('img_default', 'https://img.mini.minisns.cn/icons/dafault.png')) . '" style="border-radius:50px;width:30px;" />';
  25. }
  26. return '';
  27. })->width('50px');
  28. $grid->column('ower')->display(function ($v) {
  29. if($v && $v['user_name']){
  30. return '<a target="_blank" href="'.admin_url('/users?id='.$v['id']).'">'.$v['user_name'].'</a>' ?? '用户已删除';
  31. }
  32. return '';
  33. })->width('100px');
  34. $grid->column('posts_id')->display(function ($v){
  35. if($v){
  36. return '<a href="'.admin_url('posts/index').'" target="_blank">笔记'.$v.'</a>';
  37. }
  38. return '';
  39. });
  40. $grid->column('content');
  41. $grid->column('img');
  42. $grid->column('expect_time');
  43. $grid->column('publish_time');
  44. $grid->column('status')->using([0=>'待发布', 1=>'已发布'])->label([0=>'gray', 1=>'primary']);
  45. $grid->filter(function (Grid\Filter $filter) {
  46. $filter->equal('id');
  47. });
  48. });
  49. }
  50. /**
  51. * Make a show builder.
  52. *
  53. * @param mixed $id
  54. *
  55. * @return Show
  56. */
  57. protected function detail($id)
  58. {
  59. return Show::make($id, new WxPostsCommentManual(), function (Show $show) {
  60. $show->field('id');
  61. $show->field('posts_id');
  62. $show->field('expect_user');
  63. $show->field('content');
  64. $show->field('img');
  65. $show->field('expect_time');
  66. $show->field('publish_time');
  67. $show->field('status');
  68. });
  69. }
  70. /**
  71. * Make a form builder.
  72. *
  73. * @return Form
  74. */
  75. protected function form()
  76. {
  77. return Form::make(new WxPostsCommentManual(), function (Form $form) {
  78. $form->display('id');
  79. $form->text('posts_id')->default(Cache::get('posts_comment_manual_last_post_id', ''))->required();
  80. $form->select('expect_user', '用户')->options(function ($id) {
  81. if($id){
  82. $user = \App\Models\User\WxUser::find($id);
  83. if ($user) {
  84. return [$user->id => $user->user_name];
  85. }
  86. }
  87. })->ajax('select/users');
  88. $form->textarea('content')->required();
  89. $form->image('img')->url('files/uploads')->autoUpload();
  90. $expect_time = \App\Models\Posts\WxPostsCommentManual::where('status', 0)->max('expect_time');
  91. if(_empty_($expect_time)){
  92. $expect_time = current_time();
  93. }else{
  94. $expect_time = Carbon::parse($expect_time);
  95. $now = Carbon::now();
  96. // 比较时间
  97. if ($expect_time->lessThan($now)) {
  98. $expect_time = $now;
  99. }else{
  100. $expect_time = Carbon::parse($expect_time)->addMinutes(mini_rand(1, 20));
  101. }
  102. }
  103. $form->datetime('expect_time')->default($expect_time)->required();
  104. // $form->text('publish_time');
  105. // $form->text('status');
  106. });
  107. }
  108. }