p2 project
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.

176 lines
6.9 KiB

5 months ago
<?php
namespace app\admin\service;
4 months ago
use app\model\BlockedWordModel;
5 months ago
use app\model\VideoOnDemandModel;
class VideoService extends AdminBaseService
{
// 获取点播列表
public function videoOnDemandList($param)
{
try {
if (empty($param['page']) || !is_numeric($param['page'])) {
4 months ago
return $this->toData('400', '参错错误');
5 months ago
}
if (empty($param['limit']) || !is_numeric($param['limit'])) {
4 months ago
return $this->toData('400', '参错错误');
5 months ago
}
$where = [];
if (isset($param['title'])) {
$where['title'] = $param['title'];
}
$list = VideoOnDemandModel::where($where)->order('id', 'desc')->paginate([
'list_rows' => $param['limit'],
'page' => $param['page'],
]);
return $this->toData('0', 'SUCCESS', [
'list' => $list->items(), // 当前页的数据
'page' => $list->currentPage(), // 当前页码
'total' => $list->total(), // 总记录数
'last_page' => $list->lastPage(), // 最后一页页码
]);
} catch (\Exception $exception) {
4 months ago
return $this->toData('500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
5 months ago
}
}
// 添加点播信息
public function addVideoOnDemand($param)
{
try {
if (empty($param['title']) || empty($param['cover_id']) || empty($param['video_id']) || empty($param['cover_url']) || empty($param['video_url'] || empty($param['state'])) ) {
4 months ago
return $this->toData('400', '参错错误');
5 months ago
}
$insert = VideoOnDemandModel::create([
'title' => $param['title'],
'desc' => $param['desc'] ?? "",
'cover_id' => $param['cover_id'],
'video_id' => $param['video_id'],
'cover_url' => $param['cover_url'],
'video_url' => $param['video_url'],
'sort' => $param['sort'] ?? 0,
'state' => $param['state'],
]);
return $this->toData('0', 'SUCCESS', ['insert_id' => $insert->id]);
} catch (\Exception $exception) {
4 months ago
return $this->toData('500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
5 months ago
}
}
// 编辑点播信息
public function editVideoOnDemand($param)
{
try {
if (empty($param['id'])) {
4 months ago
return $this->toData('400', 'Missing param id');
5 months ago
}
if (empty($param['title']) || empty($param['cover_id']) || empty($param['video_id']) || empty($param['cover_url']) || empty($param['video_url'] || empty($param['state'])) ) {
4 months ago
return $this->toData('400', '参错错误');
5 months ago
}
$ckInfo = VideoOnDemandModel::where('id', $param['id'])->find();
if (empty($ckInfo)) {
4 months ago
return $this->toData('500', '编辑的数据不存在');
5 months ago
}
$ckInfo->title = $param['title'];
$ckInfo->desc = $param['desc'];
$ckInfo->cover_id = $param['cover_id'];
$ckInfo->video_id = $param['video_id'];
$ckInfo->cover_url = $param['cover_url'];
$ckInfo->video_url = $param['video_url'];
$ckInfo->sort = $param['sort'];
$ckInfo->state = $param['state'];
$ckInfo->save();
4 months ago
return $this->toData('0', 'success');
5 months ago
} catch (\Exception $exception) {
4 months ago
return $this->toData('500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
5 months ago
}
}
4 months ago
// 屏蔽词列表
public function blockedWordList($param)
{
try {
if (empty($param['page']) || !is_numeric($param['page'])) {
return $this->toData('400', '参错错误');
}
if (empty($param['limit']) || !is_numeric($param['limit'])) {
return $this->toData('400', '参错错误');
}
$list = BlockedWordModel::order('id', 'desc')->paginate([
'list_rows' => $param['limit'],
'page' => $param['page'],
]);
return $this->toData('0', 'SUCCESS', [
'list' => $list->items(), // 当前页的数据
'page' => $list->currentPage(), // 当前页码
'total' => $list->total(), // 总记录数
'last_page' => $list->lastPage(), // 最后一页页码
]);
} catch (\Exception $exception) {
return $this->toData('500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
// 新增屏蔽词
public function blockedWordAdd($param)
{
try {
if (empty($param['word'])) {
return $this->toData('400', '参错错误');
}
$blockedWord = BlockedWordModel::where(['word'=>$param['word']])->find();
if (!empty($blockedWord)) {
return $this->toData('400', '已存在相同屏蔽词');
}
$insert = BlockedWordModel::create([
'word' => $param['word'],
]);
if (!$insert) {
return $this->toData('500', '添加失败');
}
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
// 编辑屏蔽词
public function blockedWordEdit($param)
{
try {
if (empty($param['id']) || empty($param['word'])) {
return $this->toData('400', '参错错误');
}
$blockedWord = BlockedWordModel::where(['id'=>$param['id']])->find();
if (empty($blockedWord)) {
return $this->toData('400', '数据不存在');
}
$blockedWord->word = $param['word'];
$blockedWord->save();
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
// 删除屏蔽词
public function blockedWordDelete($param)
{
try {
if (empty($param['id'])) {
return $this->toData('400', '参错错误');
}
$blockedWord = BlockedWordModel::where(['id'=>$param['id']])->find();
if (empty($blockedWord)) {
return $this->toData('400', '数据不存在');
}
$blockedWord->state = 0;
$blockedWord->save();
return $this->toData('0', 'SUCCESS');
} catch (\Exception $exception) {
return $this->toData('500', 'The system is busy.', [$exception->getMessage(), $exception->getTrace()]);
}
}
5 months ago
}