Commit db636d68 by 杨树贤

添加faq接口

parent d4fe1828
......@@ -7,6 +7,14 @@ SYSTEM_CODE=09
SYSTEM_NAME=媒体系统Api
ELK_NAME=lc_news_api
DB_CONNECTION=mysql
DB_HOST=192.168.2.239
DB_PORT=3306
DB_DATABASE=lc_news
DB_USERNAME=root
DB_PASSWORD=root
DB_PREFIX=lc_
BaseUrl=http://lc_server_news.cc
REDIS_HOST=192.168.1.235
......
......@@ -3,14 +3,27 @@
namespace App\Http\Controllers;
use App\Model\ArticleModel;
use App\Services\FaqService;
use Illuminate\Http\Request;
//案例
class CaseController extends Controller
//faq
class FaqController extends Controller
{
public function index(Request $request)
public function index(Request $request, FaqService $service)
{
//因为是获取案例,所以要制定一个ID类型
$caseArticleArctypeId = 10;
$list = $service->getFaqList();
return $this->Export(0, 'ok', ['data' => $list]);
}
public function show(Request $request,FaqService $service)
{
$faq = $service->getFaq($request->get('id'));
return $faq;
}
}
\ No newline at end of file
......@@ -13,13 +13,18 @@ class ArctypeModel extends Model
public function articles()
{
return $this->hasMany(ArticleModel::class, 'top_type_id', 'type_id');
return $this->hasMany(ArticleModel::class, 'type_id', 'type_id');
}
public function getFaqList()
{
$faqTypeId = config('config.faq_type_id');
return $this->select(['type_id', 'type_name', 'sort', 'description'])
->where('parent_id', $faqTypeId)->with([
'articles' => function ($query) {
$query->select(['type_id', 'art_id', 'title']);
},
])->get();
}
}
\ No newline at end of file
......@@ -99,4 +99,14 @@ class ArticleModel extends BaseModel
return $data;
}
//获取Faq
public function getFaq($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
......@@ -4,15 +4,48 @@
namespace App\Services;
class CodeService
use App\Model\ArctypeModel;
use App\Model\ArticleModel;
class FaqService extends BaseService
{
//回复报价需要添加流水
public function addCode($map = [])
public function getFaqList()
{
$model = new ArctypeModel();
//获取所有faq相关的文章,50应该差不多了
$list = $model->getFaqList();
$list = $this->transform($list);
return $list;
}
private function transform($data)
{
foreach ($data as $key => &$item) {
foreach ($item['articles'] as $k => $v) {
$v['url'] = url() . '/faq/info?id=' . $v['art_id'];
}
}
unset($item);
return $data;
}
public function getFaq($id)
{
$model = new ArticleModel();
$faq = $model->getFaq($id);
$faq = $this->transformFaq($faq);
return $faq;
}
private function transformFaq($data)
{
$url = config('website.BaseUrl') . '/codes/add';
$result = reportCurl($url, $map, true);
$result = json_decode($result, true);
$data['body'] = array_get($data['article_addon'], 'body');
unset($data['article_addon']);
return $result;
return $data;
}
}
\ No newline at end of file
......@@ -12,5 +12,6 @@ return [
2 => '处理中',
3 => '处理成功',
4 => '处理失败'
]
],
'faq_type_id' => 10,
];
\ No newline at end of file
......@@ -22,6 +22,7 @@ $router->group(['middleware' => []], function () use ($router) {
$router->addRoute(['GET', 'POST'], '/case/list', 'CaseController@index');
$router->addRoute(['GET', 'POST'], '/case/info', 'CaseController@show');
$router->addRoute(['GET', 'POST'], '/faq/list', 'FaqController@index');
$router->addRoute(['GET', 'POST'], '/faq/info', 'FaqController@show');
});
$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