海南旅游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.6 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\AgentProduct;
  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(10)->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 = AgentProduct::select(['title', 'price', 'original_price', 'pictures'])->get();
  32. $hots = AgentProduct::query()
  33. ->select('id', 'sale', 'product_id', 'price', 'original_price') //必须查询product_id才能with
  34. ->with(['product' => fn ($query) => $query->select('id', 'title', 'pictures')]) //必须查询ID才能正常查询
  35. ->limit(6)->get();
  36. return $this->success([
  37. 'slide' => $slide,
  38. 'notice' => $notice,
  39. 'my_channels' => $my_channels,
  40. 'home_ad1' => $home_ad1,
  41. 'hots' => $hots,
  42. ]);
  43. }
  44. }