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