Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
php_frq_api
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
b1a4cf1d
authored
Jun 04, 2021
by
连敬荣
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
代码重构
parent
0616d4f2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
16 deletions
app/Http/Controllers/SearchController.php
app/Http/routes/api.php
app/Model/LieBrandModel.php
app/Model/LieBrandModell.php
app/Http/Controllers/SearchController.php
View file @
b1a4cf1d
...
...
@@ -3,6 +3,7 @@
namespace
App\Http\Controllers
;
use
App\Model\LieBrandModel
;
use
Illuminate\Http\Request
;
class
SearchController
extends
Controller
...
...
@@ -11,14 +12,14 @@ class SearchController extends Controller
//新增询价,sku查询接口
public
function
getSkuList
(
Request
$request
)
{
$
k
=
$request
->
input
(
'k'
);
$
sku
=
$request
->
input
(
'k'
);
$types
=
$request
->
input
(
'types'
);
$url
=
Config
(
'website.search_url'
)
.
"/search/spu/think?spu_name="
.
$
k
;
$url
=
Config
(
'website.search_url'
)
.
"/search/spu/think?spu_name="
.
$
sku
;
$res
=
post_curl
(
$url
,
[]);
$resArr
=
\GuzzleHttp\json_decode
(
$res
,
true
);
$temp
=
[];
if
(
count
(
$resArr
[
"data"
])
==
0
&&
$types
==
1
)
{
#返回没查到的数据
array_push
(
$temp
,
[
"value"
=>
""
,
"name"
=>
$
k
]);
array_push
(
$temp
,
[
"value"
=>
""
,
"name"
=>
$
sku
]);
}
else
{
foreach
(
$resArr
[
"data"
]
as
$k
=>
$v
)
{
array_push
(
$temp
,
[
"value"
=>
json_encode
(
$v
),
"name"
=>
$v
[
"spu_name"
]
.
" 品牌:"
.
$v
[
"brand_name"
]]);
...
...
@@ -29,10 +30,11 @@ class SearchController extends Controller
}
//新增询价,品牌查询接口
public
function
Api
BrandList
(
Request
$request
)
public
function
get
BrandList
(
Request
$request
)
{
$k
=
$request
->
input
(
'k'
);
$types
=
$request
->
input
(
'types'
);
$types
=
@
$request
->
input
(
'types'
)
?@
$request
->
input
(
'types'
)
:
1
;
$lieBrandModel
=
new
LieBrandModel
();
$lieBrandModel
->
getBrandList
(
$k
,
$types
);
}
}
\ No newline at end of file
app/Http/routes/api.php
View file @
b1a4cf1d
...
...
@@ -2,3 +2,4 @@
Route
::
Get
(
'/ApiSkuList'
,
'SearchController@getSkuList'
);
//新增询价查询sku接口;
Route
::
Get
(
'/ApiBrandList'
,
'SearchController@getBrandList'
);
//
新增询价查询品牌接口
;
\ No newline at end of file
app/Model/LieBrandModel.php
0 → 100644
View file @
b1a4cf1d
<?php
namespace
App\Model
;
use
Illuminate\Database\Eloquent\Model
;
class
LieBrandModel
extends
Model
{
protected
$connection
=
'spu'
;
protected
$table
=
'brand'
;
protected
$primaryKey
=
'brand_id'
;
public
function
getBrandList
(
$k
,
$types
=
1
){
if
(
$types
==
1
)
{
#模糊搜索
$brandInfoList
=
$this
->
select
(
'brand_name'
,
'brand_id'
)
->
where
(
'brand_name'
,
'like'
,
'%'
.
$k
.
'%'
)
->
get
()
->
toArray
();
$brandInfo
=
[];
foreach
(
$brandInfoList
as
$k
=>
$v
){
array_push
(
$brandInfo
,[
"value"
=>
$v
[
"brand_id"
],
"name"
=>
$v
[
"brand_name"
]]);
}
if
(
count
(
$brandInfo
)
==
0
){
$brandInfo
=
[[
"value"
=>
"0"
,
"name"
=>
$k
]];
}
echo
json_encode
(
$brandInfo
,
JSON_UNESCAPED_UNICODE
)
;
exit
();
}
if
(
$types
==
2
)
{
#模糊搜索
$brandInfo
=
$this
->
select
(
"select brand_id as value,brand_name as name from lie_brand where brand_name like '%"
.
$k
.
"%' limit 10"
);
echo
json_encode
(
$brandInfo
,
JSON_UNESCAPED_UNICODE
)
;
exit
();
}
if
(
$types
==
3
){
#精确搜索
$brandInfo
=
$this
->
select
(
"select brand_id as brand_id,brand_name as name from lie_brand where brand_name = '"
.
$k
.
"' limit 1"
);
if
(
!
$brandInfo
){
return
false
;
}
else
{
return
$brandInfo
[
0
][
"brand_id"
];
}
}
}
}
app/Model/LieBrandModell.php
deleted
100644 → 0
View file @
0616d4f2
<?php
namespace
App\Model
;
use
Illuminate\Database\Eloquent\Model
;
class
LieBrandModell
extends
Model
{
//
}
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