| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 | 
							- <?php
 
- namespace app\admin\controller;
 
- use think\exception\ValidateException;
 
- use app\model\LiveAnchor;
 
- class LiveanchorController extends Base
 
- {
 
- 	function index()
 
- 	{
 
- 		$weid = weid();
 
- 		$keyword = input('post.keyword', '', 'serach_in');
 
- 		$query = LiveAnchor::where(['weid' => $weid]);
 
- 		if (!empty($keyword)) {
 
- 			$query->where('name', 'like', '%' . $keyword . '%');
 
- 		}
 
- 		$res = $query->order('sort asc,id asc')
 
- 			->paginate(getpage())
 
- 			->toArray();
 
- 		$data['data'] = $res;
 
- 		return $this->json($data);
 
- 	}
 
- 	function listUpdate()
 
- 	{
 
- 		$data = only('id,status,sort');
 
- 		if (!$data['id']) throw new ValidateException('参数错误');
 
- 		LiveAnchor::update($data);
 
- 		return $this->json(['msg' => '操作成功']);
 
- 	}
 
- 	public function update()
 
- 	{
 
- 		$id = $this->request->post('id');
 
- 		$data = input('post.');
 
- 		unset($data['create_time']);
 
- 		if (empty($id)) {
 
- 			$data['weid'] = weid();
 
- 			try {
 
- 				$res = LiveAnchor::create($data);
 
- 				if ($res->id && empty($data['sort'])) {
 
- 					LiveAnchor::update(['sort' => $res->id, 'id' => $res->id]);
 
- 				}
 
- 			} catch (\Exception $e) {
 
- 				throw new ValidateException($e->getMessage());
 
- 			}
 
- 			return $this->json(['msg' => '添加成功', 'data' => $res->id]);
 
- 		} else {
 
- 			try {
 
- 				LiveAnchor::update($data);
 
- 			} catch (\Exception $e) {
 
- 				throw new ValidateException($e->getMessage());
 
- 			}
 
- 			return $this->json(['msg' => '修改成功']);
 
- 		}
 
- 	}
 
- 	function getInfo()
 
- 	{
 
- 		$id =  $this->request->post('id', '', 'serach_in');
 
- 		if (!$id) throw new ValidateException('参数错误');
 
- 		$data = LiveAnchor::field('*')->find($id)->toArray();
 
- 		return $this->json(['data' => $data]);
 
- 	}
 
- 	function delete()
 
- 	{
 
- 		return $this->del(new LiveAnchor());
 
- 	}
 
- }
 
 
  |