海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Channel;
  5. use App\Models\Notice;
  6. use App\Models\Product;
  7. use App\Models\Slide;
  8. use App\Models\UserChannel;
  9. /**
  10. * 小程序首页
  11. * Class IndexController
  12. * @package App\Http\Controllers\Api
  13. */
  14. class IndexController extends Controller
  15. {
  16. // 首页数据大杂烩
  17. public function index()
  18. {
  19. # 轮播图
  20. $slide = Slide::where('status', 1)->orderBy('sort')->orderBy('id', 'DESC')->limit(2)->get(['title','url']);
  21. # 公告
  22. $notice = Notice::limit(10)->get(['title', 'updated_at']);
  23. # 我的频道
  24. $channel_ids = UserChannel::where('uid', $this->user_id)->value('channels');
  25. $my_channels = Channel::whereIn('id', $channel_ids)->get(['id', 'pid', 'name', 'icon']);
  26. # 人气爆款
  27. $hots = Product::get(['title', 'price', 'original_price', 'pictures', 'sales']);
  28. # 猜你喜欢
  29. $guess = Product::get(['title', 'price', 'original_price', 'pictures', 'sales']);
  30. return $this->success([
  31. 'slide' => $slide,
  32. 'notice' => $notice,
  33. 'my_channels' => $my_channels,
  34. 'hots' => $hots,
  35. 'guess' => $guess,
  36. ]);
  37. }
  38. }