GoodsController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\FavService;
  6. use App\Modules\Mini\Services\GoodsService;
  7. use App\Modules\Mini\Services\OrderService;
  8. use Faker\Provider\Image;
  9. use Illuminate\Support\Facades\Auth;
  10. class GoodsController extends BaseController
  11. {
  12. protected GoodsService $service;
  13. /**
  14. * @param GoodsService $service
  15. */
  16. public function __construct(GoodsService $service)
  17. {
  18. $this->service = $service;
  19. }
  20. public function goods()
  21. {
  22. $params = $this->valid([
  23. "id" => "required",
  24. ]);
  25. return $this->ok($this->service->info($params));
  26. }
  27. public function search()
  28. {
  29. return $this->ok([
  30. "total" => 1,
  31. "page_total" => 1,
  32. "list" => [
  33. [
  34. "id" => 1,
  35. "name" => "商品名称",
  36. "thumb" => Image::imageUrl(),
  37. ],
  38. ],
  39. "category" => [
  40. [
  41. "id" => 1,
  42. "thumb" => Image::imageUrl(),
  43. "name" => "分类名称",
  44. ],
  45. ],
  46. ]);
  47. }
  48. public function fav()
  49. {
  50. $params = $this->valid([
  51. "id" => "required",
  52. ]);
  53. return $this->ok([
  54. "was_created" => app(FavService::class)->fav(Auth::id(), $params)->wasRecentlyCreated,
  55. ]);
  56. }
  57. public function ask()
  58. {
  59. $params = $this->valid([
  60. "id" => "required",
  61. "sku_id" => "required",
  62. "sku_custom" => "",
  63. ]);
  64. $params['source'] = Order::SOURCE_GOODS;
  65. return $this->ok(app(OrderService::class)->askOne(Auth::user(), $params));
  66. }
  67. }