素材中心代码
This commit is contained in:
@@ -612,4 +612,145 @@ class YunzeradminController extends Base
|
||||
}
|
||||
return json(['code' => 1, 'msg' => '请求方法无效']);
|
||||
}
|
||||
|
||||
//素材中心
|
||||
public function materialcenter()
|
||||
{
|
||||
return View::fetch();
|
||||
}
|
||||
// 内容推送列表
|
||||
public function materialcenterlist()
|
||||
{
|
||||
if (Request::isGet()) {
|
||||
$page = intval(input('post.page', 1));
|
||||
$limit = intval(input('post.limit', 10));
|
||||
|
||||
$query = ContentPush::where('delete_time', null)
|
||||
->field('id, title, type, status, sort, create_time, update_time');
|
||||
|
||||
// 获取总记录数
|
||||
$count = $query->count();
|
||||
|
||||
// 获取分页数据
|
||||
$lists = $query->order(['sort DESC', 'id DESC'])
|
||||
->page($page, $limit)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 处理数据
|
||||
foreach ($lists as &$item) {
|
||||
$item['create_time'] = is_numeric($item['create_time']) ? date('Y-m-d H:i:s', $item['create_time']) : $item['create_time'];
|
||||
$item['update_time'] = is_numeric($item['update_time']) ? date('Y-m-d H:i:s', $item['update_time']) : $item['update_time'];
|
||||
}
|
||||
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '',
|
||||
'count' => $count,
|
||||
'data' => $lists
|
||||
]);
|
||||
}
|
||||
return json(['code' => 1, 'msg' => '请求方法无效']);
|
||||
}
|
||||
// 添加内容推送
|
||||
public function materialcenteradd()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$data = [
|
||||
'title' => input('post.title'),
|
||||
'content' => input('post.content'),
|
||||
'image' => input('post.image'),
|
||||
'url' => input('post.url'),
|
||||
'type' => input('post.type', 1),
|
||||
'status' => input('post.status', 1),
|
||||
'sort' => input('post.sort', 0),
|
||||
'create_time' => time()
|
||||
];
|
||||
|
||||
$res = ContentPush::insert($data);
|
||||
if (!$res) {
|
||||
Log::record('添加内容推送', 0, '添加内容推送失败', '内容推送管理');
|
||||
return json(['code' => 1, 'msg' => '添加内容推送失败']);
|
||||
}
|
||||
Log::record('添加内容推送', 1, '', '内容推送管理');
|
||||
return json(['code' => 0, 'msg' => '添加成功']);
|
||||
}
|
||||
return json(['code' => 1, 'msg' => '请求方法无效']);
|
||||
}
|
||||
|
||||
// 编辑内容推送
|
||||
public function materialcenteredit()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$id = input('post.id');
|
||||
if (empty($id)) {
|
||||
Log::record('编辑内容推送', 0, 'ID不能为空', '内容推送管理');
|
||||
return json(['code' => 1, 'msg' => 'ID不能为空']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'title' => input('post.title'),
|
||||
'content' => input('post.content'),
|
||||
'image' => input('post.image'),
|
||||
'url' => input('post.url'),
|
||||
'type' => input('post.type', 1),
|
||||
'status' => input('post.status', 1),
|
||||
'sort' => input('post.sort', 0),
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
$res = ContentPush::where('id', $id)->update($data);
|
||||
if ($res === false) {
|
||||
Log::record('编辑内容推送', 0, '更新内容推送失败', '内容推送管理');
|
||||
return json(['code' => 1, 'msg' => '更新内容推送失败']);
|
||||
}
|
||||
Log::record('编辑内容推送', 1, '', '内容推送管理');
|
||||
return json(['code' => 0, 'msg' => '更新成功']);
|
||||
}
|
||||
return json(['code' => 1, 'msg' => '请求方法无效']);
|
||||
}
|
||||
|
||||
// 删除内容推送
|
||||
public function materialcenterdel()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$id = input('post.id');
|
||||
if (empty($id)) {
|
||||
Log::record('删除内容推送', 0, 'ID不能为空', '内容推送管理');
|
||||
return json(['code' => 1, 'msg' => 'ID不能为空']);
|
||||
}
|
||||
|
||||
$res = ContentPush::where('id', $id)->update(['delete_time' => time()]);
|
||||
if (!$res) {
|
||||
Log::record('删除内容推送', 0, '删除内容推送失败', '内容推送管理');
|
||||
return json(['code' => 1, 'msg' => '删除内容推送失败']);
|
||||
}
|
||||
Log::record('删除内容推送', 1, '', '内容推送管理');
|
||||
return json(['code' => 0, 'msg' => '删除成功']);
|
||||
}
|
||||
return json(['code' => 1, 'msg' => '请求方法无效']);
|
||||
}
|
||||
|
||||
// 修改内容推送状态
|
||||
public function materialcenterstatus()
|
||||
{
|
||||
if (Request::isPost()) {
|
||||
$id = input('post.id');
|
||||
$status = input('post.status');
|
||||
|
||||
if (empty($id)) {
|
||||
Log::record('修改内容推送状态', 0, 'ID不能为空', '内容推送管理');
|
||||
return json(['code' => 1, 'msg' => 'ID不能为空']);
|
||||
}
|
||||
|
||||
$res = ContentPush::where('id', $id)->update(['status' => $status]);
|
||||
if ($res === false) {
|
||||
Log::record('修改内容推送状态', 0, '更新状态失败', '内容推送管理');
|
||||
return json(['code' => 1, 'msg' => '更新状态失败']);
|
||||
}
|
||||
Log::record('修改内容推送状态', 1, '', '内容推送管理');
|
||||
return json(['code' => 0, 'msg' => '更新成功']);
|
||||
}
|
||||
return json(['code' => 1, 'msg' => '请求方法无效']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user