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

54 lines
1.5 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\AgentProduct;
  7. use App\Models\Slide;
  8. use App\Models\Special;
  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', 'name', 'icon']);
  28. # 专题列表
  29. $special = Special::query()
  30. ->where('agent_id', $this->agent_id)
  31. ->orderBy('sort')
  32. ->orderBy('id')
  33. ->get(['id', 'picture_ad']);
  34. # 人气爆款
  35. $hots = AgentProduct::query()
  36. ->select('id', 'sale', 'product_id', 'price', 'original_price') //必须查询product_id才能with
  37. ->with('product:id,title,pictures') //必须查询ID才能正常查询
  38. ->limit(6)->get();
  39. return $this->success([
  40. 'slide' => $slide,
  41. 'notice' => $notice,
  42. 'my_channels' => $my_channels,
  43. 'special' => $special,
  44. 'hots' => $hots,
  45. ]);
  46. }
  47. }