Commit ede15da2 by 杨树贤

添加公告接口

parent db636d68
...@@ -12,7 +12,7 @@ class CaseController extends Controller ...@@ -12,7 +12,7 @@ class CaseController extends Controller
public function index(Request $request, CaseService $service) public function index(Request $request, CaseService $service)
{ {
$page = $request->get('page'); $page = $request->get('page');
$pageSize = $request->get('pageSize'); $pageSize = $request->get('page_size');
$list = $service->getCaseList($page, $pageSize); $list = $service->getCaseList($page, $pageSize);
return $this->Export(0, 'ok', ['data' => $list]); return $this->Export(0, 'ok', ['data' => $list]);
......
<?php
namespace App\Http\Controllers;
use App\Model\ArticleModel;
use App\Services\NoticeService;
use Illuminate\Http\Request;
//faq
class NoticeController extends Controller
{
public function index(Request $request, NoticeService $service)
{
$page = $request->get('page');
$pageSize = $request->get('page_size');
$list = $service->getNoticeList($page,$pageSize);
return $this->Export(0, 'ok', ['data' => $list]);
}
public function show(Request $request,NoticeService $service)
{
$faq = $service->getNotice($request->get('id'));
return $faq;
}
}
\ No newline at end of file
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace App\Model; namespace App\Model;
use App\Services\NoticeService;
use http\Env\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
class ArticleModel extends BaseModel class ArticleModel extends BaseModel
...@@ -109,4 +111,29 @@ class ArticleModel extends BaseModel ...@@ -109,4 +111,29 @@ class ArticleModel extends BaseModel
return $data; return $data;
} }
//获取公告列表
public function getNoticeList($page, $pageSize)
{
$noticeTypeId = config('config.notice_type_id');
$data = $this->select(['art_id', 'type_id', 'title'])
->with([
'type',
])->where('top_type_id', $noticeTypeId)
->orderBy('art_id', 'desc')
->page($page, $pageSize)
->get();
return $data;
}
//获取公告信息
public function getNotice($id)
{
$data = $this->select(['art_id', 'type_id', 'title'])
->with(['article_addon'])->where('art_id', $id)
->first();
return $data;
}
} }
\ No newline at end of file
<?php
namespace App\Services;
use App\Model\ArctypeModel;
use App\Model\ArticleModel;
class NoticeService extends BaseService
{
public function getNoticeList($page,$pageSize)
{
$model = new ArticleModel();
//获取所有faq相关的文章,50应该差不多了
$list = $model->getNoticeList($page,$pageSize);
$list = $this->transform($list);
return $list;
}
private function transform($data)
{
foreach ($data as $key => &$item) {
$item['type_name'] = array_get($item['type'], 'type_name');
unset($item['type']);
}
unset($item);
return $data;
}
public function getNotice($id)
{
$model = new ArticleModel();
$faq = $model->getNotice($id);
$faq = $this->transformNotice($faq);
return $faq;
}
private function transformNotice($data)
{
$data['body'] = array_get($data['article_addon'], 'body');
unset($data['article_addon']);
return $data;
}
}
\ No newline at end of file
...@@ -14,4 +14,5 @@ return [ ...@@ -14,4 +14,5 @@ return [
4 => '处理失败' 4 => '处理失败'
], ],
'faq_type_id' => 10, 'faq_type_id' => 10,
'notice_type_id' => 10,
]; ];
\ No newline at end of file
...@@ -23,6 +23,8 @@ $router->group(['middleware' => []], function () use ($router) { ...@@ -23,6 +23,8 @@ $router->group(['middleware' => []], function () use ($router) {
$router->addRoute(['GET', 'POST'], '/case/info', 'CaseController@show'); $router->addRoute(['GET', 'POST'], '/case/info', 'CaseController@show');
$router->addRoute(['GET', 'POST'], '/faq/list', 'FaqController@index'); $router->addRoute(['GET', 'POST'], '/faq/list', 'FaqController@index');
$router->addRoute(['GET', 'POST'], '/faq/info', 'FaqController@show'); $router->addRoute(['GET', 'POST'], '/faq/info', 'FaqController@show');
$router->addRoute(['GET', 'POST'], '/notice/list', 'NoticeController@index');
$router->addRoute(['GET', 'POST'], '/notice/info', 'NoticeController@show');
}); });
$router->group(['middleware' => ['web', 'login']], function () use ($router) { $router->group(['middleware' => ['web', 'login']], function () use ($router) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment