BatchEditEpisodeListForm.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Admin\Actions\Form;
  3. use App\Models\EpisodesList;
  4. use Dcat\Admin\Contracts\LazyRenderable;
  5. use Dcat\Admin\Traits\LazyWidget;
  6. use Dcat\Admin\Widgets\Form;
  7. class BatchEditEpisodeListForm extends Form implements LazyRenderable
  8. {
  9. use LazyWidget;
  10. public function handle(array $input)
  11. {
  12. // 选择的行
  13. $ids = explode(',', $input['id'] ?? null);
  14. if (empty($ids)) {
  15. return $this->response()->error('参数错误');
  16. }
  17. $isFree = $input['is_free'] ?? null;
  18. $salePrice = $input['sale_price'] ?? 0;
  19. $originPrice = $input['origin_price'] ?? 0;
  20. foreach ($ids as $id) {
  21. EpisodesList::where('id', $id)->update([
  22. 'is_free' => $isFree,
  23. 'sale_price' => $salePrice,
  24. 'origin_price' => $originPrice,
  25. ]);
  26. }
  27. return $this->response()->success('修改成功')->refresh();
  28. }
  29. public function form()
  30. {
  31. $this->radio('is_free')
  32. ->options(config('global.episode_free'))
  33. ->when(0, function (Form $form) {
  34. $form->number('origin_price')->min(1);
  35. $form->number('sale_price')->min(1);
  36. })->default(1);
  37. $this->hidden('id')->attribute('id', 'batch-id');
  38. }
  39. public function default()
  40. {
  41. }
  42. }