EpisodesBatchUploadController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Admin\Controllers\Episode;
  3. use App\Admin\Actions\Grid\BatchEditEpisode;
  4. use App\Models\Episode;
  5. use App\Models\EpisodesList;
  6. use Dcat\Admin\Form;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Layout\Content;
  9. use Dcat\Admin\Show;
  10. use Dcat\Admin\Http\Controllers\AdminController;
  11. class EpisodesBatchUploadController extends AdminController
  12. {
  13. private $id = null;
  14. public function index(Content $content, $id = 0)
  15. {
  16. $this->id = $id;
  17. $episode = Episode::find($id);
  18. $form = $this->form();
  19. return $content
  20. ->title($episode->name)
  21. ->breadcrumb(
  22. ['text' => $episode->name],
  23. ['text' => '剧集上传'],
  24. )
  25. ->body($form)
  26. ->description('剧集上传');
  27. }
  28. public function store($id = 0)
  29. {
  30. $req = request()->post();
  31. $form = new Form();
  32. $response = $form->response();
  33. if(isset($req['lists']) && empty($req['lists'])) {
  34. return $response->error('请上传剧集');
  35. }else if(!isset($req['lists'])){
  36. return $this->form()->store();
  37. }
  38. $lists = explode(',',$req['lists']);
  39. $sort = EpisodesList::where('episodes_id',$id)->max('sort');
  40. foreach ($lists as $list)
  41. {
  42. $episode = new EpisodesList();
  43. $episode->episodes_id = $id;
  44. $episode->sort = ++$sort;
  45. $episode->url = $list;
  46. $episode->save();
  47. }
  48. return $response->success(__('admin.save_succeeded'))
  49. ->redirect(admin_url("/episodes/{$id}/lists"));
  50. }
  51. public function form()
  52. {
  53. $id = $this->id;
  54. return new Form(new EpisodesList(), function (Form $form) use ($id) {
  55. $form->action(admin_url("/episodes/batch/{$id}/upload"));
  56. $form->tools(
  57. function (Form\Tools $tools) {
  58. $tools->disableList();
  59. }
  60. );
  61. $form->disableHeader();
  62. $form->disableCreatingCheck();
  63. $form->disableEditingCheck();
  64. $form->disableViewCheck();
  65. $form->multipleFile('lists', '剧集')
  66. ->chunkSize(1024)
  67. ->maxSize(1024 * 1024)
  68. ->saveFullUrl()
  69. ->uniqueName()
  70. ->autoUpload()
  71. ->autoSave(false)
  72. ->removable(false)
  73. ->required();
  74. $form->saved(function (Form $form) use ($id) {
  75. return $form
  76. ->response()
  77. ->success(trans('admin.update_succeeded'))
  78. ->redirect(admin_url("/episodes/{$id}/lists"));
  79. });
  80. });
  81. }
  82. }