海南旅游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.

51 lines
1.5 KiB

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