Live.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace addons\shopro\controller;
  3. use addons\shopro\library\Wechat;
  4. use addons\shopro\exception\Exception;
  5. use think\Cache;
  6. class Live extends Base
  7. {
  8. protected $noNeedLogin = ['*'];
  9. protected $noNeedRight = ['*'];
  10. public function index()
  11. {
  12. $params = $this->request->get();
  13. $type = $params['type'] ?? 'all';
  14. $ids = array_filter(isset($params['ids']) ? explode(',', $params['ids']) : []);
  15. if (!in_array($type, ['all', 'notice', 'living', 'lived'])) {
  16. $this->error('参数错误');
  17. }
  18. // 同步直播
  19. \addons\shopro\model\Live::autoSyncLive();
  20. if ($type != 'all') {
  21. $lives = \addons\shopro\model\Live::{$type}()
  22. ->with('goods')
  23. ->order('id', 'desc')
  24. ->paginate(10);
  25. } else {
  26. $lives = \addons\shopro\model\Live::order('live_status', 'asc')
  27. ->with('goods')
  28. ->order('id', 'desc');
  29. if (isset($params['ids'])) {
  30. // 首页根据 id 获取
  31. $lives = $lives->where('id', 'in', $ids)->select();
  32. } else {
  33. // 直播列表
  34. $lives = $lives->paginate(10);
  35. }
  36. }
  37. $this->success('获取成功', $lives);
  38. }
  39. }