CartController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Modules\Mini\Controllers;
  3. use App\Base\BaseController;
  4. use App\Models\Cart;
  5. use App\Modules\Mini\Services\CartService;
  6. use Faker\Provider\Image;
  7. use Illuminate\Support\Facades\Auth;
  8. class CartController extends BaseController
  9. {
  10. protected CartService $service;
  11. /**
  12. * @param CartService $service
  13. */
  14. public function __construct(CartService $service)
  15. {
  16. $this->service = $service;
  17. }
  18. public function index()
  19. {
  20. $params = $this->valid([
  21. "page_size" => "int",
  22. ]);
  23. return $this->ok($this->service->paginate(Auth::user(), $params));
  24. }
  25. public function del()
  26. {
  27. $params = $this->valid([
  28. "ids" => "required|array",
  29. ]);
  30. $row = Cart::whereIn("id", $params['ids'])->where("user_id", Auth::id())->delete();
  31. return $this->ok([
  32. "row" => $row,
  33. ]);
  34. }
  35. public function ask()
  36. {
  37. $params = $this->valid([
  38. "ids" => "required|array",
  39. ]);
  40. return $this->ok($this->service->ask(Auth::user(), $params));
  41. }
  42. public function store()
  43. {
  44. $params = $this->valid([
  45. "id" => "required",
  46. "count" => "required",
  47. ]);
  48. $cart = app(CartService::class)->update(Auth::user(), $params);
  49. return $this->ok([
  50. "id" => $cart->id,
  51. ]);
  52. }
  53. }