海南旅游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.3 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. use Illuminate\Support\Facades\Storage;
  8. /**
  9. * 频道列表
  10. * Class Channel
  11. * @package App\Http\Controllers\Api
  12. */
  13. class ChannelController extends Controller
  14. {
  15. // 所有频道列表
  16. public function index()
  17. {
  18. $list = Channel::query()
  19. ->where('agent_id', $this->agent_id)
  20. ->orderBy('sort')
  21. ->orderBy('id')
  22. ->get(['id', 'pid', 'name', 'icon']);
  23. $prefix = Storage::disk('public')->url('');
  24. foreach ($list as $k => &$v) {
  25. $v->icon = $prefix . $v->icon;
  26. }
  27. return $this->success($list);
  28. }
  29. // 我的频道
  30. public function my()
  31. {
  32. $channel_ids = UserChannel::where('user_id', $this->user_id)->value('channels');
  33. $list = Channel::whereIn('id', $channel_ids)->get(['id', 'pid', 'name', 'icon']);
  34. return $this->success($list);
  35. }
  36. //根据频道ID获取产品
  37. public function product()
  38. {
  39. $channel_id = (int)request()->input('channel_id');
  40. $list = AgentProduct::list($this->agent_id)
  41. ->whereRaw("FIND_IN_SET($channel_id, `channel_id`)")
  42. ->orderBy('id', 'DESC')
  43. ->simplePaginate();
  44. return $this->success($list);
  45. }
  46. }