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

46 lines
1.1 KiB

  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\AgentProduct;
  5. use App\Models\Channel;
  6. use App\Models\UserChannel;
  7. /**
  8. * 频道列表
  9. * Class Channel
  10. * @package App\Http\Controllers\Api
  11. */
  12. class ChannelController extends Controller
  13. {
  14. // 所有频道列表
  15. public function index()
  16. {
  17. $list = Channel::query()
  18. ->where('agent_id', $this->agent_id)
  19. ->orderBy('sort')
  20. ->orderBy('id')
  21. ->get(['id', 'pid', 'name', 'icon']);
  22. return $this->success($list);
  23. }
  24. // 我的频道
  25. public function my()
  26. {
  27. $channel_ids = UserChannel::where('user_id', $this->user_id)->value('channels');
  28. $list = Channel::whereIn('id', $channel_ids)->get(['id', 'pid', 'name', 'icon']);
  29. return $this->success($list);
  30. }
  31. //根据频道ID获取产品
  32. public function product()
  33. {
  34. $channel_id = (int)request()->input('channel_id');
  35. $list = AgentProduct::list()->where('agent_id', $this->agent_id)
  36. ->whereRaw("FIND_IN_SET($channel_id, `channel_id`)")
  37. ->orderBy('id', 'DESC')
  38. ->simplePaginate();
  39. return $this->success($list);
  40. }
  41. }