GoodsController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 search()
  29. {
  30. return $this->ok([
  31. "total" => 1,
  32. "page_total" => 1,
  33. "list" => [
  34. [
  35. "id" => 1,
  36. "name" => "商品名称",
  37. "thumb" => Image::imageUrl(),
  38. ],
  39. ],
  40. "category" => [
  41. [
  42. "id" => 1,
  43. "thumb" => Image::imageUrl(),
  44. "name" => "分类名称",
  45. ],
  46. ],
  47. ]);
  48. }
  49. public function fav()
  50. {
  51. $params = $this->valid([
  52. "id" => "required",
  53. ]);
  54. return $this->ok([
  55. "was_created" => app(FavService::class)->fav(Auth::id(), $params)->wasRecentlyCreated,
  56. ]);
  57. }
  58. public function ask()
  59. {
  60. $params = $this->valid([
  61. "id" => "required",
  62. "sku_id" => "required",
  63. "sku_custom" => "",
  64. ]);
  65. $params['source'] = Order::SOURCE_GOODS;
  66. return $this->ok(app(OrderService::class)->askOne(Auth::user(), $params));
  67. }
  68. public function cart()
  69. {
  70. $params = $this->valid([
  71. "id" => "required",
  72. "sku_id" => "required",
  73. "sku_custom" => "array",
  74. ]);
  75. $cart = app(CartService::class)->add(Auth::user(), $params);
  76. return $this->ok([
  77. "id" => $cart->id,
  78. ]);
  79. }
  80. }