| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575 |
- <?php
- namespace App\Web\Controllers;
- use App\Http\Controllers\BaseController;
- use App\Web\Services\BlogService;
- use Illuminate\Http\Request;
- class BlogController extends BaseController
- {
- protected $service = null;
- /**
- * 构造函数
- * BlogController constructor.
- * @param BlogService $service
- */
- public function __construct(BlogService $service)
- {
- $this->service = $service;
- }
- /**
- * 获取文章类型列表
- * */
- public function getBlogTypeList(Request $request)
- {
- $params = $request->only(['page_size', 'page', 'status', 'keyword', 'plate_id']);
- $ret = $this->service->getBlogTypeList($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 文章类型保存
- * */
- public function saveBlogType(Request $request)
- {
- $this->validate($request, [
- 'type_name' => 'required',
- ], [
- 'type_name.required' => '类型名称不能为空',
- ]);
- $params = $request->only(['id', 'type_name', 'status', 'sort', 'seo_data', 'seo_id', 'expand_content', 'plate_id']);
- $ret = $this->service->saveBlogType($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 变更文章类型状态
- * */
- public function changeBlogTypeStatus(Request $request)
- {
- $this->validate($request, [
- 'id' => 'required',
- ], [
- 'id.required' => 'id不能为空',
- ]);
- $params = $request->only(['id', 'status']);
- $ret = $this->service->saveBlogType($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 保存文章类型关系
- * */
- public function typeRelationSave(Request $request)
- {
- $this->validate($request, [
- 'blog_id' => 'required',
- ], [
- 'blog_id.required' => '文章id不能为空',
- ]);
- $params = $request->only(['blog_id', 'type_ids']);
- $ret = $this->service->typeRelationSave($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 根据文章类型 保存文章关系
- * */
- public function addRelationByTypeId(Request $request)
- {
- $this->validate($request, [
- 'blog_ids' => 'required',
- 'type_id' => 'required',
- ], [
- 'blog_ids.required' => '文章id不能为空',
- 'type_id.required' => '文章类型id不能为空',
- ]);
- $typeId = $request->input('type_id', 0);
- $blogIds = $request->input('blog_ids', []);
- $ret = $this->service->addRelationByTypeId($typeId, $blogIds);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 根据类型id及文章id 删除关联关系
- * */
- public function delTypeRelation(Request $request)
- {
- $this->validate($request, [
- 'blog_id' => 'required',
- 'type_id' => 'required',
- ], [
- 'blog_id.required' => '文章id不能为空',
- 'type_id.required' => '类型id不能未空',
- ]);
- $blogId = $request->input('blog_id', '');
- $typeId = $request->input('type_id', '');
- $ret = $this->service->delTypeRelation($typeId, $blogId);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 获取文章标签列表
- * */
- public function getBlogTagList(Request $request)
- {
- $params = $request->only(['page_size', 'page', 'status', 'keyword']);
- $ret = $this->service->getBlogTagList($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 文章标签保存
- * */
- public function saveBlogTag(Request $request)
- {
- $this->validate($request, [
- 'tag_name' => 'required',
- ], [
- 'tag_name.required' => '类型名称不能为空',
- ]);
- $params = $request->only(['id', 'tag_name', 'is_hot', 'status', 'sort', 'seo_id', 'seo_data']);
- $ret = $this->service->saveBlogTag($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 变更文章类型状态
- * */
- public function changeBlogTagStatus(Request $request)
- {
- $this->validate($request, [
- 'id' => 'required',
- ], [
- 'id.required' => 'id不能为空',
- ]);
- $params = $request->only(['id', 'status']);
- $ret = $this->service->saveBlogTag($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 保存文章标签关系
- * */
- public function tagRelationSave(Request $request)
- {
- $this->validate($request, [
- 'blog_id' => 'required',
- ], [
- 'blog_id.required' => '文章id不能为空',
- ]);
- $params = $request->only(['blog_id', 'tag_ids']);
- $ret = $this->service->tagRelationSave($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 根据文章标签 保存文章关系
- * */
- public function addRelationByTagId(Request $request)
- {
- $this->validate($request, [
- 'blog_ids' => 'required',
- 'tag_id' => 'required',
- ], [
- 'blog_ids.required' => '文章id不能为空',
- 'tag_id.required' => '文章标签id不能为空',
- ]);
- $tagId = $request->input('tag_id', 0);
- $blogIds = $request->input('blog_ids', []);
- $ret = $this->service->addRelationByTagId($tagId, $blogIds);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 根据标签id及文章id 删除关联关系
- * */
- public function delTagRelation(Request $request)
- {
- $this->validate($request, [
- 'blog_id' => 'required',
- 'tag_id' => 'required',
- ], [
- 'blog_id.required' => '文章id不能为空',
- 'tag_id.required' => '标签id不能未空',
- ]);
- $blogId = $request->input('blog_id', '');
- $tagId = $request->input('tag_id', '');
- $ret = $this->service->delTagRelation($tagId, $blogId);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 获取文章板块列表
- * */
- public function getBlogPlateList(Request $request)
- {
- $params = $request->only(['page_size', 'page', 'status', 'keyword']);
- $ret = $this->service->getBlogPlateList($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 文章板块保存
- * */
- public function saveBlogPlate(Request $request)
- {
- $this->validate($request, [
- 'plate_name' => 'required',
- ], [
- 'plate_name.required' => '类型名称不能为空',
- ]);
- $params = $request->only(['id', 'plate_name', 'status', 'sort', 'seo_id', 'seo_data']);
- $ret = $this->service->saveBlogPlate($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 变更文章板块状态
- * */
- public function changeBlogPlateStatus(Request $request)
- {
- $this->validate($request, [
- 'id' => 'required',
- ], [
- 'id.required' => 'id不能为空',
- ]);
- $params = $request->only(['id', 'status']);
- $ret = $this->service->saveBlogPlate($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 获取文章列表
- * */
- public function getBlogList(Request $request)
- {
- $params = $request->only(['page_size', 'page', 'status', 'keyword', 'plate_id', 'sort', 'is_admin']);
- $ret = $this->service->getBlogList($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 获取文章详情
- * */
- public function getBlogInfo(Request $request)
- {
- $this->validate($request, [
- 'id' => 'required',
- ], [
- 'id.required' => '文章id不能为空',
- ]);
- $id = $request->input('id', 0);
- $ret = $this->service->getBlogInfo(['id' => $id]);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 获取文章分类未关联的文章
- * */
- public function getUnrelatedBlogByTypeIds(Request $request)
- {
- $this->validate($request, [
- 'type_id' => 'required',
- ], [
- 'type_id.required' => 'id不能为空',
- ]);
- $params = $request->only(['page_size', 'page', 'status', 'keyword', 'type_id']);
- $ret = $this->service->getUnrelatedBlogByTypeIds($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 获取文章标签未关联的文章
- * */
- public function getUnrelatedBlogByTagIds(Request $request)
- {
- $this->validate($request, [
- 'tag_id' => 'required',
- ], [
- 'tag_id.required' => 'id不能为空',
- ]);
- $params = $request->only(['page_size', 'page', 'status', 'keyword', 'tag_id']);
- $ret = $this->service->getUnrelatedBlogByTagIds($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 根据类型id 获取文章列表
- * */
- public function getBlogListByType(Request $request)
- {
- $params = $request->only(['page_size', 'page', 'status', 'keyword', 'type_id']);
- $ret = $this->service->getBlogByTypeIds($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 根据标签id 获取文章列表
- * */
- public function getBlogListByTag(Request $request)
- {
- $params = $request->only(['page_size', 'page', 'status', 'keyword', 'tag_id']);
- $ret = $this->service->getBlogByTagIds($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 变更文章板块状态
- * */
- public function changeBlogStatus(Request $request)
- {
- $this->validate($request, [
- 'id' => 'required',
- ], [
- 'id.required' => 'id不能为空',
- ]);
- $params = $request->only(['id', 'status']);
- $ret = $this->service->saveBlog($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 保存文章数据
- * */
- public function saveBlog(Request $request)
- {
- $this->validate($request, [
- 'plate_id' => 'required',
- 'title' => 'required',
- 'content' => 'required|string',
- 'type_ids' => 'array',
- 'tag_ids' => 'array',
- ]);
- $params = $request->only(['id', 'plate_id', 'pub_date', 'title', 'author', 'content', 'outline_bar', 'description',
- 'image_url', 'image_alt', 'main_image', 'main_image_alt', 'virtual_view',
- 'download_url', 'seo_id', 'sort', 'seo_data', 'status', 'tag_ids', 'type_ids', 'is_top', 'expand_content']);
- $ret = $this->service->saveBlog($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 文章推荐设置
- * */
- public function recommendSet(Request $request)
- {
- $this->validate($request, [
- 'id' => 'required',
- ]);
- $params = $request->only(['id', 'is_recommend']);
- $ret = $this->service->recommendSet($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 更新文章的浏览量
- * */
- public function upBlogPv(Request $request)
- {
- $this->validate($request, [
- 'id' => 'required',
- ], [
- 'id.required' => 'id不能为空',
- ]);
- $blogId = $request->input('id', 0);
- $incValue = $request->input('inc_val', 1);
- $ret = $this->service->upBlogPv($blogId, $incValue);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 文章预览
- * */
- public function previewBlog(Request $request)
- {
- $this->validate($request, [
- 'id' => 'required',
- ], [
- 'id.required' => 'id不能为空',
- ]);
- $blogId = $request->input('id', 0);
- $ret = $this->service->getBlogRenderData(['id' => $blogId]);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 根据类型id获取文章
- * */
- public function getPublishBlogListByTypeId(Request $request)
- {
- $params = $request->only(['page_size', 'page', 'type_id', 'plate_id']);
- $ret = $this->service->getPublishBlogListByTypeId($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 根据标签id获取文章
- * */
- public function getPublishBlogListByTagId(Request $request)
- {
- $params = $request->only(['page_size', 'page', 'tag_id', 'plate_id']);
- $ret = $this->service->getPublishBlogListByTagId($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 搜索获取已发布的文章
- * */
- public function getSearchBlogList(Request $request)
- {
- $params = $request->only(['page_size', 'keyword']);
- $ret = $this->service->getPublishBlogList($params);
- return $this->jsonResponse(
- 'ok',
- $ret
- );
- }
- /**
- * 新闻排序上下移
- * @url /api/blog/change-sort
- */
- public function changeBlogSort(Request $request)
- {
- $this->validate($request, [
- 'id' => 'required',
- 'sort' => 'required',
- ]);
- $ret = $this->service->changeBlogSort($request->input('id'), $request->input('sort'));
- return $this->jsonResponse('ok', $ret);
- }
- // 批量修改分类
- public function typePluralEdit(Request $request)
- {
- $this->validate($request, [
- 'ids' => 'required',
- ]);
- $ret = $this->service->typePluralEdit($request->all());
- return $this->jsonResponse('ok', $ret);
- }
- // 批量修改标签
- public function tagPluralEdit(Request $request)
- {
- $this->validate($request, [
- 'ids' => 'required',
- ]);
- $ret = $this->service->tagPluralEdit($request->all());
- return $this->jsonResponse('ok', $ret);
- }
- // 批量删除
- public function batchDeleteNews(Request $request)
- {
- $this->validate($request, [
- 'ids' => 'required',
- ]);
- $ret = $this->service->batchDelete($request->all(), 2);
- return $this->jsonResponse('ok', $ret);
- }
- // 批量修改状态
- public function batchStatusNews(Request $request)
- {
- $this->validate($request, [
- 'ids' => 'required',
- ]);
- $ret = $this->service->batchStatus($request->all());
- return $this->jsonResponse('ok', $ret);
- }
- }
|