Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
LC_api_news
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
db636d68
authored
Nov 27, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加faq接口
parent
d4fe1828
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
91 additions
and
15 deletions
.env
app/Http/Controllers/FaqController.php
app/Model/ArctypeModel.php
app/Model/ArticleModel.php
app/Services/FaqService.php
config/config.php
routes/web.php
.env
View file @
db636d68
...
...
@@ -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
...
...
app/Http/Controllers/FaqController.php
View file @
db636d68
...
...
@@ -3,14 +3,27 @@
namespace
App\Http\Controllers
;
use
App\Model\ArticleModel
;
use
App\Services\FaqService
;
use
Illuminate\Http\Request
;
//
案例
class
Case
Controller
extends
Controller
//
faq
class
Faq
Controller
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
app/Model/ArctypeModel.php
View file @
db636d68
...
...
@@ -13,13 +13,18 @@ class ArctypeModel extends Model
public
function
articles
()
{
return
$this
->
hasMany
(
ArticleModel
::
class
,
't
op_t
ype_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
app/Model/ArticleModel.php
View file @
db636d68
...
...
@@ -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
app/Services/FaqService.php
View file @
db636d68
...
...
@@ -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
config/config.php
View file @
db636d68
...
...
@@ -12,5 +12,6 @@ return [
2
=>
'处理中'
,
3
=>
'处理成功'
,
4
=>
'处理失败'
]
],
'faq_type_id'
=>
10
,
];
\ No newline at end of file
routes/web.php
View file @
db636d68
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment