BannerController.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Modules\Admin\Controllers\Admin;
  3. use App\Base\BaseController;
  4. use App\Models\Setting;
  5. use App\Modules\Admin\Services\SettingService;
  6. use Illuminate\Support\Arr;
  7. class BannerController extends BaseController
  8. {
  9. /** @var SettingService $service */
  10. protected $service;
  11. public function __construct(SettingService $authService)
  12. {
  13. $this->service = $authService;
  14. }
  15. public function paginate()
  16. {
  17. $data = $this->valid([
  18. "name" => "",
  19. "status" => "",
  20. "page_size" => "",
  21. ]);
  22. return $this->ok($this->service->bannerPaginate($data));
  23. }
  24. public function store()
  25. {
  26. $params = $this->valid([
  27. "id" => "",
  28. "name" => "required",
  29. "imageUrl" => "required|url",
  30. "sort" => "required|int",
  31. "interval" => "",
  32. ]);
  33. return $this->ok($this->service->store($params));
  34. }
  35. public function del()
  36. {
  37. $id = request()->input("id", 0);
  38. Setting::whereType(Setting::TYPE_BANNER)->where("id", $id)->delete();
  39. return $this->ok(true);
  40. }
  41. public function changeStatus()
  42. {
  43. $id = request()->input("id", 0);
  44. $m = Setting::whereType(Setting::TYPE_BANNER)->where("id", $id)->firstOrFail();
  45. $value = $m->value ?? [];
  46. $isUse = 1;
  47. if (Arr::get($value, "is_use")) {
  48. $isUse = 0;
  49. }
  50. $value['is_use'] = $isUse;
  51. $m->value = $value;
  52. $m->save();
  53. return $this->ok(true);
  54. }
  55. }