GoodsController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Modules\Mini\Controllers;
  3. use App\Base\BaseController;
  4. use App\Models\Order\Order;
  5. use App\Modules\Mini\Services\CartService;
  6. use App\Modules\Mini\Services\FavService;
  7. use App\Modules\Mini\Services\GoodsService;
  8. use App\Modules\Mini\Services\OrderService;
  9. use Faker\Provider\Image;
  10. use Illuminate\Support\Facades\Auth;
  11. class GoodsController extends BaseController
  12. {
  13. protected GoodsService $service;
  14. /**
  15. * @param GoodsService $service
  16. */
  17. public function __construct(GoodsService $service)
  18. {
  19. $this->service = $service;
  20. }
  21. public function goods()
  22. {
  23. $params = $this->valid([
  24. "id" => "required",
  25. ]);
  26. return $this->ok($this->service->info($params));
  27. }
  28. public function fav()
  29. {
  30. $params = $this->valid([
  31. "id" => "required",
  32. ]);
  33. return $this->ok([
  34. "was_created" => app(FavService::class)->fav(Auth::id(), $params)->wasRecentlyCreated,
  35. ]);
  36. }
  37. public function ask()
  38. {
  39. $params = $this->valid([
  40. "id" => "required",
  41. "custom" => "",
  42. "count" => "",
  43. ]);
  44. $params['source'] = Order::SOURCE_GOODS;
  45. return $this->ok(app(OrderService::class)->askOne(Auth::user(), $params));
  46. }
  47. public function cart()
  48. {
  49. $params = $this->valid([
  50. "id" => "required",
  51. 'count' => "required",
  52. "custom" => "",
  53. ]);
  54. $cart = app(CartService::class)->add(Auth::user(), $params);
  55. return $this->ok([
  56. "id" => $cart->id,
  57. ]);
  58. }
  59. }