Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
goods
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
goods
Commits
b3d6c4da
Commit
b3d6c4da
authored
Jun 16, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:调整返回数据结构
parent
84928268
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
133 additions
and
5 deletions
+133
-5
Goods.php
application/modules/Goods/controllers/Goods.php
+10
-5
ElasticGoodService.php
application/services/goods/ElasticGoodService.php
+123
-0
No files found.
application/modules/Goods/controllers/Goods.php
View file @
b3d6c4da
...
...
@@ -9,6 +9,7 @@ use \Validate\GoodsAddValidate;
use
\Validate\GoodsEditValidate
;
use
\Validate\GoodsInfoOpValidate
;
use
\Validate\GoodsInfoFeValidate
;
use
\App\Services\goods\ElasticGoodService
;
class
GoodsController
extends
Base
...
...
@@ -19,7 +20,7 @@ class GoodsController extends Base
public
function
get_goods_category_listAction
()
{
$categoryList
=
CategoryService
::
getCategoryList
();
$this
->
success
([
"
data
"
=>
$categoryList
]);
$this
->
success
([
"
result
"
=>
$categoryList
]);
}
/**
...
...
@@ -55,7 +56,7 @@ class GoodsController extends Base
$params
=
$this
->
params
;
$data
=
GoodsService
::
getGoodsSpuInfo
(
$params
);
$this
->
success
([
"
data
"
=>
$data
]);
$this
->
success
([
"
result
"
=>
$data
]);
}
/**
...
...
@@ -67,7 +68,7 @@ class GoodsController extends Base
$params
=
$this
->
params
;
$data
=
GoodsService
::
getGoodsSkuInfo
(
$params
);
$this
->
success
([
"
data
"
=>
$data
]);
$this
->
success
([
"
result
"
=>
$data
]);
}
/**
...
...
@@ -105,7 +106,7 @@ class GoodsController extends Base
$params
=
$this
->
params
;
$res
=
GoodsService
::
checkGoodsName
(
$params
[
"name"
],
$params
[
"life_account_id"
]);
$this
->
success
([
"
data
"
=>
$res
]);
$this
->
success
([
"
result
"
=>
$res
]);
}
/**
...
...
@@ -116,7 +117,7 @@ class GoodsController extends Base
$params
=
$this
->
params
;
$data
=
GoodsService
::
getOpGoodsSpuList
(
$params
);
$this
->
success
([
"
data
"
=>
$data
]);
$this
->
success
([
"
result
"
=>
$data
]);
}
/**
...
...
@@ -129,9 +130,13 @@ class GoodsController extends Base
/**
* c端 es:商品列表 (sku list)
* @throws Exception
*/
public
function
goods_list_cAction
()
{
$params
=
$this
->
params
;
$data
=
ElasticGoodService
::
searchDoc
(
$params
);
$this
->
success
([
"result"
=>
$data
]);
}
}
\ No newline at end of file
application/services/goods/ElasticService.php
→
application/services/goods/Elastic
Good
Service.php
View file @
b3d6c4da
...
...
@@ -4,8 +4,9 @@ namespace App\Services\goods;
use
Api\PhpUtils\Elastic\ElasticUtil
;
class
ElasticService
class
Elastic
Good
Service
{
const
INDEX
=
"bp_goods"
;
public
static
function
createIndex
(
$index
)
{
$elasticClient
=
ElasticUtil
::
getInstance
();
...
...
@@ -27,28 +28,26 @@ class ElasticService
/**
* 写入 es 一条数据
* @param $index
* @param $data
* @param $id
* @return array|callable
*/
public
static
function
indexDoc
(
$i
ndex
,
$i
d
,
$data
)
public
static
function
indexDoc
(
$id
,
$data
)
{
$elasticClient
=
ElasticUtil
::
getInstance
();
return
$elasticClient
->
indexDoc
(
$index
,
$data
,
$id
);
return
$elasticClient
->
indexDoc
(
self
::
INDEX
,
$data
,
$id
);
}
/**
* 修改 es 一条数据
* @param $index
* @param $id
* @param $data
* @return array|callable
*/
public
static
function
updateDoc
(
$i
ndex
,
$i
d
,
$data
)
public
static
function
updateDoc
(
$id
,
$data
)
{
$elasticClient
=
ElasticUtil
::
getInstance
();
return
$elasticClient
->
updateDoc
(
$index
,
$id
,
$data
);
return
$elasticClient
->
updateDoc
(
self
::
INDEX
,
$id
,
$data
);
}
public
static
function
bulk
(
$index
)
...
...
@@ -67,25 +66,58 @@ class ElasticService
var_export
(
$res
);
}
public
static
function
searchDoc
(
$index
,
$searchContent
,
$sortType
,
$from
=
0
,
$size
=
10
)
/**
* @param array $params
* @return array|object
*/
public
static
function
searchDoc
(
$params
=
[])
{
if
(
!
empty
(
$params
[
"search_content"
]))
{
}
$sortType
=
0
;
if
(
!
empty
(
$params
[
"sort_type"
]))
{
$sortType
=
$params
[
"sort_type"
];
}
$from
=
empty
(
$params
[
"from"
])
?
0
:
(
int
)
$params
[
"from"
];
$size
=
empty
(
$params
[
"size"
])
?
10
:
(
int
)
$params
[
"size"
];
$sortList
=
[
[
"price_sort"
=>
"asc"
,
"total_amount_sold"
=>
"desc"
],
//todo 距离排序
[
"total_amount_sold"
=>
"desc"
],
[
"price_sort"
=>
"asc"
],
];
$data
=
[
"size"
=>
$size
,
"from"
=>
$from
,
"query"
=>
[
"match"
=>
[
"test_field"
=>
"中国"
]
],
"sort"
=>
[
"match"
=>
[
"test_field"
=>
"中国"
]
],
"from"
=>
$from
,
"size"
=>
$size
,
// "query" => [
// "bool" => [],
// ],
"sort"
=>
$sortList
[
$sortType
],
];
$elasticClient
=
ElasticUtil
::
getInstance
();
$res
=
$elasticClient
->
searchDoc
(
$index
,
$data
);
var_export
(
$res
);
$res
=
$elasticClient
->
searchDoc
(
self
::
INDEX
,
$data
);
$result
=
[];
if
(
!
empty
(
$res
[
"hits"
][
"total"
][
"value"
]))
{
$result
[
"count"
]
=
$res
[
"hits"
][
"total"
][
"value"
];
foreach
(
$res
[
"hits"
][
"hits"
]
as
$key
=>
$source
)
{
$result
[
"data"
][
$key
][
"id"
]
=
empty
(
$source
[
"_source"
][
"id"
])
?
$source
[
"_source"
][
"doc"
][
"id"
]
:
$source
[
"_source"
][
"id"
];
$result
[
"data"
][
$key
][
"goods_pic"
]
=
empty
(
$source
[
"_source"
][
"goods_pic"
])
?
$source
[
"_source"
][
"doc"
][
"goods_pic"
]
:
$source
[
"_source"
][
"goods_pic"
];
$result
[
"data"
][
$key
][
"name"
]
=
empty
(
$source
[
"_source"
][
"name"
])
?
$source
[
"_source"
][
"doc"
][
"name"
]
:
$source
[
"_source"
][
"name"
];
$result
[
"data"
][
$key
][
"inventory_rest"
]
=
empty
(
$source
[
"_source"
][
"inventory_rest"
])
?
$source
[
"_source"
][
"doc"
][
"inventory_rest"
]
:
$source
[
"_source"
][
"inventory_rest"
];
$result
[
"data"
][
$key
][
"total_amount_sold"
]
=
empty
(
$source
[
"_source"
][
"total_amount_sold"
])
?
$source
[
"_source"
][
"doc"
][
"total_amount_sold"
]
:
$source
[
"_source"
][
"total_amount_sold"
];
$result
[
"data"
][
$key
][
"original_price"
]
=
empty
(
$source
[
"_source"
][
"original_price"
])
?
$source
[
"_source"
][
"doc"
][
"original_price"
]
:
$source
[
"_source"
][
"original_price"
];
$result
[
"data"
][
$key
][
"price"
]
=
empty
(
$source
[
"_source"
][
"price"
])
?
$source
[
"_source"
][
"doc"
][
"price"
]
:
$source
[
"_source"
][
"price"
];
$result
[
"data"
][
$key
][
"status"
]
=
empty
(
$source
[
"_source"
][
"status"
])
?
$source
[
"_source"
][
"doc"
][
"status"
]
:
$source
[
"_source"
][
"status"
];
$result
[
"data"
][
$key
][
"online_status"
]
=
empty
(
$source
[
"_source"
][
"online_status"
])
?
$source
[
"_source"
][
"doc"
][
"online_status"
]
:
$source
[
"_source"
][
"online_status"
];
}
}
//为避免空数据时候返回给前端错误结构
return
$result
?
$result
:
(
object
)
$result
;
}
}
\ No newline at end of file
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