root_id], ['employee_id', '>', 0]])->group('employee_id')->column('employee_id'); $where = [ ['del', '=', 0], ['root_id', '=', $this->root_id] ]; // 运营人员列表 $employee = Lecturer::where($where)->column('id,name'); View::assign('employee', $employee); return View::fetch(); } $param = Request::only(['page', 'limit', 'keyword', 'date', 'employee_id']); $where = [ ['del', '=', 0], ['root_id', '=', $this->root_id] ]; if (!empty($param['date'])) { $dates = explode(' - ', $param['date']); $where[] = ['start_date', '>=', strtotime($dates[0])]; $where[] = ['start_date', '<=', strtotime($dates[1])]; } if (!empty($param['keyword'])) { $where[] = ['name', 'like', '%' . $param['keyword'] . '%']; } if (!empty($param['employee_id'])) { $where[] = ['lecturer_id', '=', $param['employee_id']]; } $list = Broadcast::with(['lecturer'=>function($query){ $query->bind(['lecturer_name'=>'name']); }])->where($where)->page($param['page'], $param['limit'])->field('*')->order('addtime desc')->select()->toArray(); $aids = []; foreach ($list as &$val) { $val['start_date'] = str_replace('-','/',$val['start_date']); $val['end_date'] = str_replace('-','/',$val['end_date']); $val['time'] = $val['start_date'].'-'.$val['end_date']; $val['type'] = $val['broadcast_type']==1 ? '威哥直播' : '直播'; $val['broadcast_platform'] = $val['broadcast_platform']==1 ? '其他平台' : 'boos直播'; } $count = Broadcast::where($where)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } /** * 添加视图 */ public function add() { //讲师列表 $employee = Lecturer::where([['del','=',0],['root_id','=',0]])->column('name,id'); View::assign('employee', $employee); return View::fetch(); } /** * 删除直播 */ public function del() { $id = input('id',0); Broadcast::where([['id','=',$id],['root_id','=',0]])->update(['del'=>1]); return json(['code' => 0, 'msg' => '删除成功']); } /** * 添加直播 */ public function addActivity() { $data = Request::only(['name','lecturer_id','start_date','broadcast_type','broadcast_platform','broadcast_url','broadcast_cover']); $date = explode(' - ',$data['start_date']); $data['start_date'] = strtotime($date[0]); $data['end_date'] = strtotime($date[1]); $data['root_id'] = $this->root_id; $data['addtime'] = time(); if ($data['start_date'] > $data['end_date']) return json(['code' => 1, 'msg' => '开始日期需在结束日期之前']); Broadcast::insert($data); return json(['code' => 0, 'msg' => '添加成功']); } /** * 修改视图 */ public function edit($id) { $where = [ ['root_id','=',0], ['id','=',$id] ]; $data = Broadcast::where($where)->findOrEmpty(); View::assign('data', $data); //讲师列表 $employee = Lecturer::where([['del','=',0],['root_id','=',0]])->column('name,id'); View::assign('employee', $employee); return View::fetch(); } /** * 编辑直播 */ public function editActivity() { $data = Request::only(['name','lecturer_id','start_date','broadcast_type','broadcast_platform','broadcast_url','broadcast_cover']); $id = input('id',0); $info = Broadcast::where([['root_id','=',0],['id','=',$id]])->findOrEmpty(); $date = explode(' - ',$data['start_date']); $data['start_date'] = strtotime($date[0]); $data['end_date'] = strtotime($date[1]); foreach ($data as $key => $value) { $info->$key = $value; } $info->save(); return json(['code' => 0, 'msg' => '添加成功']); } /** * 直播回访 */ public function playback() { $id = input('id',0); $data = Broadcast::where([['root_id','=',0],['id','=',$id]])->field('id,playback_cover,playback_url')->findOrEmpty(); View::assign('data', $data); return View::fetch(); } /** * 直播回访 */ public function savePlayback() { $data = Request::only(['playback_cover'=>'','playback_url'=>'']); $id = input('id',0); $info = Broadcast::where([['root_id','=',0],['id','=',$id]])->field('id,playback_cover,playback_url')->findOrEmpty(); foreach ($data as $key => $value) { $info->$key = $value; } $info->save(); return json(['code' => 0, 'msg' => '保存成功','data'=>'保存成功']); } }