GoodsController.php 1.6 KB

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