Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sun
Project
Project
Details
Activity
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
钟尚武
sun
Commits
10dbb7bc
Commit
10dbb7bc
authored
Jul 04, 2019
by
haowang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add product api
parent
1ead0077
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
337 additions
and
0 deletions
+337
-0
brand.py
api/brand.py
+110
-0
category.py
api/category.py
+20
-0
classify.py
api/classify.py
+21
-0
product.py
api/product.py
+172
-0
urls.py
api/urls.py
+14
-0
No files found.
api/brand.py
0 → 100644
View file @
10dbb7bc
import
json
from
utils.base
import
APIView
,
get_offset_count
from
utils.logger
import
error_logger
class
BrandListView
(
APIView
):
def
get
(
self
,
request
):
offset
,
count
=
get_offset_count
(
request
)
cn_name
=
request
.
GET
.
get
(
'cn_name'
,
None
)
id_
=
request
.
GET
.
get
(
'id'
,
None
)
has_area
=
request
.
GET
.
get
(
'has_area'
,
None
)
is_online
=
request
.
GET
.
get
(
'is_online'
,
None
)
has_icon
=
request
.
GET
.
get
(
'has_icon'
,
None
)
classify_id
=
request
.
GET
.
get
(
'classify_id'
,
None
)
data
=
self
.
rpc
[
'neptune/commodity/brand/list'
](
offset
=
offset
,
count
=
count
,
cn_name
=
cn_name
,
id_
=
id_
,
has_area
=
has_area
,
is_online
=
is_online
,
has_icon
=
has_icon
,
classify_id
=
classify_id
)
.
unwrap
()
brand_ids
=
[
obj
.
get
(
'id'
)
for
obj
in
data
]
product_count
=
self
.
rpc
[
'neptune/commodity/brand/product_count'
](
ids
=
brand_ids
)
.
unwrap
()
category_ids
=
self
.
rpc
[
'neptune/commodity/brand/brands_category_ids'
](
ids
=
brand_ids
)
.
unwrap
()
category_infos
=
self
.
rpc
[
'neptune/commodity/category/infos'
](
ids
=
category_ids
)
.
unwrap
()
category_dict
=
{
str
(
obj
.
get
(
'id'
)):
obj
for
obj
in
category_infos
}
if
category_infos
else
{}
for
obj
in
data
:
brand_id
=
obj
.
get
(
'id'
)
obj
[
'product_num'
]
=
product_count
.
get
(
str
(
brand_id
))
or
0
obj
[
'category_names'
]
=
[
category_dict
.
get
(
str
(
id_
))
.
get
(
'cn_name'
)
for
id_
in
category_ids
.
get
(
str
(
brand_id
))]
if
category_dict
.
get
(
str
(
id_
))
else
[]
obj
.
pop
(
'platform'
)
total
=
self
.
rpc
[
'neptune/commodity/brand/count'
](
cn_name
=
cn_name
,
id_
=
id_
,
has_area
=
has_area
,
is_online
=
is_online
,
has_icon
=
has_icon
,
classify_id
=
classify_id
)
.
unwrap
()
result
=
{
'data'
:
data
,
'total'
:
total
,
}
return
result
class
BrandInfoView
(
APIView
):
def
get
(
self
,
request
):
id_
=
request
.
GET
.
get
(
'id'
)
data
=
self
.
rpc
[
'neptune/commodity/brand/info'
](
id_
=
id_
)
.
unwrap
()
return
data
class
BrandCreateView
(
APIView
):
def
post
(
self
,
request
):
cn_name
=
request
.
POST
.
get
(
'cn_name'
)
icon
=
request
.
POST
.
get
(
'icon'
,
''
)
en_name
=
request
.
POST
.
get
(
'en_name'
,
None
)
alias
=
request
.
POST
.
get
(
'alias'
,
None
)
area
=
request
.
POST
.
get
(
'area'
,
None
)
classify_id
=
request
.
POST
.
get
(
'classify_id'
,
None
)
category_ids
=
json
.
loads
(
request
.
POST
.
get
(
'category_ids'
,
'[]'
))
description
=
request
.
POST
.
get
(
'description'
,
None
)
is_online
=
request
.
POST
.
get
(
'is_online'
,
False
)
if
not
cn_name
or
not
classify_id
:
return
r'缺少参数'
data
=
self
.
rpc
[
'neptune/commodity/brand/create'
](
cn_name
=
cn_name
,
icon
=
icon
,
en_name
=
en_name
,
alias
=
alias
,
area
=
area
,
classify_id
=
classify_id
,
description
=
description
,
is_online
=
is_online
)
.
unwrap
()
brand_id
=
data
.
get
(
'id'
)
self
.
rpc
[
'neptune/commodity/brand/batch_add_categorys'
](
id_
=
brand_id
,
category_ids
=
category_ids
)
.
unwrap
()
return
data
class
BrandUpdateView
(
APIView
):
def
post
(
self
,
request
):
id_
=
request
.
POST
.
get
(
'id'
,
None
)
cn_name
=
request
.
POST
.
get
(
'cn_name'
,
None
)
en_name
=
request
.
POST
.
get
(
'en_name'
,
None
)
alias
=
request
.
POST
.
get
(
'alias'
,
None
)
area
=
request
.
POST
.
get
(
'area'
,
None
)
icon
=
request
.
POST
.
get
(
'icon'
,
None
)
description
=
request
.
POST
.
get
(
'description'
,
None
)
is_online
=
request
.
POST
.
get
(
'is_online'
,
None
)
classify_id
=
request
.
POST
.
get
(
'classify_id'
,
None
)
category_ids
=
json
.
loads
(
request
.
POST
.
get
(
'category_ids'
,
'[]'
))
if
not
id_
:
return
r'缺少参数'
data
=
self
.
rpc
[
'neptune/commodity/brand/update'
](
id_
=
id_
,
cn_name
=
cn_name
,
en_name
=
en_name
,
alias
=
alias
,
area
=
area
,
icon
=
icon
,
description
=
description
,
is_online
=
is_online
,
classify_id
=
classify_id
)
.
unwrap
()
self
.
rpc
[
'neptune/commodity/brand/batch_add_categorys'
](
id_
=
id_
,
category_ids
=
category_ids
)
.
unwrap
()
return
data
api/category.py
0 → 100644
View file @
10dbb7bc
import
json
from
utils.base
import
APIView
,
get_offset_count
from
utils.logger
import
error_logger
class
CategoryListView
(
APIView
):
def
get
(
self
,
request
):
offset
,
count
=
get_offset_count
(
request
)
cn_name
=
request
.
GET
.
get
(
'cn_name'
)
data
=
self
.
rpc
[
'neptune/commodity/category/list'
](
offset
=
offset
,
count
=
count
,
cn_name
=
cn_name
)
.
unwrap
()
for
obj
in
data
:
obj
.
pop
(
'create_time'
)
obj
.
pop
(
'update_time'
)
obj
.
pop
(
'is_deleted'
)
return
data
api/classify.py
0 → 100644
View file @
10dbb7bc
import
json
from
utils.base
import
APIView
,
get_offset_count
from
utils.logger
import
error_logger
class
ClassifyListView
(
APIView
):
def
get
(
self
,
request
):
offset
,
count
=
get_offset_count
(
request
)
cn_name
=
request
.
GET
.
get
(
'cn_name'
)
data
=
self
.
rpc
[
'neptune/commodity/classify/list'
](
offset
=
offset
,
count
=
count
,
cn_name
=
cn_name
)
.
unwrap
()
for
obj
in
data
:
obj
.
pop
(
'create_time'
)
obj
.
pop
(
'update_time'
)
obj
.
pop
(
'is_deleted'
)
return
data
\ No newline at end of file
api/product.py
0 → 100644
View file @
10dbb7bc
import
json
from
utils.base
import
APIView
,
get_offset_count
from
utils.logger
import
error_logger
class
ProductListView
(
APIView
):
def
get_brand_infos
(
self
,
product_ids
):
brand_infos
=
self
.
rpc
[
'neptune/commodity/brand/products_brand_info'
](
product_ids
=
product_ids
)
.
unwrap
()
brand_product_dict
=
{
str
(
obj
.
get
(
'product_id'
)):
obj
for
obj
in
brand_infos
}
if
brand_infos
else
{}
return
brand_product_dict
def
get_category_infos
(
self
,
product_ids
):
category_infos
=
self
.
rpc
[
'neptune/commodity/category/products_category_info'
](
product_ids
=
product_ids
)
.
unwrap
()
ret
=
{}
if
not
category_infos
:
return
ret
for
obj
in
category_infos
:
product_id
=
obj
.
get
(
'project_id'
)
if
ret
.
get
(
str
(
product_id
)):
ret
[
str
(
product_id
)]
=
ret
.
get
(
str
(
product_id
))
.
append
(
obj
)
else
:
ret
[
str
(
product_id
)]
=
[
obj
]
return
ret
def
get_effect_infos
(
self
,
product_ids
):
effect_infos
=
self
.
rpc
[
'neptune/commodity/effect/products_effect_info'
](
product_ids
=
product_ids
)
.
unwrap
()
ret
=
{}
if
not
effect_infos
:
return
ret
for
obj
in
effect_infos
:
product_id
=
obj
.
get
(
'project_id'
)
if
ret
.
get
(
str
(
product_id
)):
ret
[
str
(
product_id
)]
=
ret
.
get
(
str
(
product_id
))
.
append
(
obj
)
else
:
ret
[
str
(
product_id
)]
=
[
obj
]
return
ret
def
get
(
self
,
request
):
offset
,
count
=
get_offset_count
(
request
)
id_
=
request
.
GET
.
get
(
'id'
,
None
)
cn_name
=
request
.
GET
.
get
(
'cn_name'
,
None
)
en_name
=
request
.
GET
.
get
(
'en_name'
,
None
)
alias
=
request
.
GET
.
get
(
'alias'
,
None
)
is_online
=
request
.
GET
.
get
(
'is_online'
,
None
)
has_area
=
request
.
GET
.
get
(
'has_area'
,
None
)
has_brand
=
request
.
GET
.
get
(
'has_brand'
,
None
)
has_image
=
request
.
GET
.
get
(
'has_image'
,
None
)
brand_id
=
request
.
GET
.
get
(
'brand_id'
,
None
)
category_id
=
request
.
GET
.
get
(
'category_id'
,
None
)
price_low
=
request
.
GET
.
get
(
'price_low'
,
None
)
price_high
=
request
.
GET
.
get
(
'price_high'
,
None
)
grade_low
=
request
.
GET
.
get
(
'grade_low'
,
None
)
grade_high
=
request
.
GET
.
get
(
'grade_high'
,
None
)
comment_nums_low
=
request
.
GET
.
get
(
'comment_nums_low'
,
None
)
comment_nums_high
=
request
.
GET
.
get
(
'comment_nums_high'
,
None
)
data
=
self
.
rpc
[
'neptune/commodity/product/list'
](
offset
=
offset
,
count
=
count
,
id_
=
id_
,
cn_name
=
cn_name
,
en_name
=
en_name
,
alias
=
alias
,
is_online
=
is_online
,
has_area
=
has_area
,
has_brand
=
has_brand
,
has_image
=
has_image
,
brand_id
=
brand_id
,
category_id
=
category_id
,
price_low
=
price_low
,
price_high
=
price_high
,
grade_low
=
grade_low
,
grade_high
=
grade_high
,
comment_nums_low
=
comment_nums_low
,
comment_nums_high
=
comment_nums_high
)
.
unwrap
()
product_ids
=
[
obj
.
get
(
'id'
)
for
obj
in
data
]
brand_product_dict
=
self
.
get_brand_infos
(
product_ids
)
category_product_dict
=
self
.
get_category_infos
(
product_ids
)
effect_product_dict
=
self
.
get_effect_infos
(
product_ids
)
for
obj
in
data
:
product_id
=
obj
.
get
(
'id'
)
obj
[
'brand_name'
]
=
brand_product_dict
.
get
(
str
(
product_id
))
.
get
(
'cn_name'
)
if
brand_product_dict
.
get
(
str
(
product_id
))
else
''
obj
[
'category_names'
]
=
[
obj
.
get
(
'cn_name'
)
for
obj
in
category_product_dict
.
get
(
str
(
product_id
))]
if
category_product_dict
.
get
(
str
(
product_id
))
else
[]
obj
[
'effect_names'
]
=
[
obj
.
get
(
'cn_name'
)
for
obj
in
effect_product_dict
.
get
(
str
(
product_id
))]
if
effect_product_dict
.
get
(
str
(
product_id
))
else
[]
obj
.
pop
(
'norms'
)
obj
.
pop
(
'country'
)
obj
.
pop
(
'platform'
)
count
=
self
.
rpc
[
'neptune/commodity/product/count'
](
id_
=
id_
,
cn_name
=
cn_name
,
en_name
=
en_name
,
alias
=
alias
,
is_online
=
is_online
,
has_area
=
has_area
,
has_brand
=
has_brand
,
has_image
=
has_image
,
brand_id
=
brand_id
,
category_id
=
category_id
,
price_low
=
price_low
,
price_high
=
price_high
,
grade_low
=
grade_low
,
grade_high
=
grade_high
,
comment_nums_low
=
comment_nums_low
,
comment_nums_high
=
comment_nums_high
)
.
unwrap
()
result
=
{
'data'
:
data
,
'total'
:
count
,
}
return
result
class
ProductInfoView
(
APIView
):
def
get_category_names
(
self
,
product_id
):
category_infos
=
self
.
rpc
[
'neptune/commodity/category/infos'
](
product_id
=
product_id
)
.
unwrap
()
if
not
category_infos
:
return
[]
return
[
obj
.
get
(
'cn_name'
)
for
obj
in
category_infos
]
def
get_effect_names
(
self
,
product_id
):
effect_infos
=
self
.
rpc
[
'neptune/commodity/effect/infos'
](
product_id
=
product_id
)
.
unwrap
()
if
not
effect_infos
:
return
[]
return
[
obj
.
get
(
'cn_name'
)
for
obj
in
effect_infos
]
def
get
(
self
,
request
):
id_
=
request
.
GET
.
get
(
'id'
)
data
=
self
.
rpc
[
'neptune/commodity/product/info'
](
id_
=
id_
)
.
unwrap
()
data
.
pop
(
'norms'
)
data
.
pop
(
'country'
)
data
.
pop
(
'platform'
)
brand_info
=
self
.
rpc
[
'neptune/commodity/brand/infos'
](
product_id
=
id_
)
.
unwrap
()
data
[
'brand_name'
]
=
brand_info
[
0
]
.
get
(
'cn_name'
)
if
brand_info
else
''
data
[
'category_names'
]
=
self
.
get_category_names
(
id_
)
data
[
'effect_names'
]
=
self
.
get_effect_names
(
id_
)
return
data
class
ProductCreateView
(
APIView
):
def
post
(
self
,
request
):
cn_name
=
request
.
POST
.
get
(
'cn_name'
,
None
)
en_name
=
request
.
POST
.
get
(
'en_name'
,
None
)
alias
=
request
.
POST
.
get
(
'alias'
,
None
)
image
=
request
.
POST
.
get
(
'image'
,
None
)
norms
=
request
.
POST
.
get
(
'norms'
,
None
)
grade
=
request
.
POST
.
get
(
'grade'
,
None
)
price
=
request
.
POST
.
get
(
'price'
,
None
)
country
=
request
.
POST
.
get
(
'country'
,
None
)
description
=
request
.
POST
.
get
(
'description'
,
None
)
comment_nums
=
request
.
POST
.
get
(
'comment_nums'
,
None
)
classify_id
=
request
.
POST
.
get
(
'classify_id'
,
None
)
if
not
cn_name
or
not
image
:
return
r'缺少参数'
data
=
self
.
rpc
[
'neptune/commodity/product/create'
](
cn_name
=
cn_name
,
en_name
=
en_name
,
alias
=
alias
,
image
=
image
,
norms
=
norms
,
grade
=
grade
,
price
=
price
,
country
=
country
,
description
=
description
,
comment_nums
=
comment_nums
,
classify_id
=
classify_id
)
.
unwrap
()
return
data
class
ProductUpdateView
(
APIView
):
def
post
(
self
,
request
):
id_
=
request
.
POST
.
get
(
'id'
)
cn_name
=
request
.
POST
.
get
(
'cn_name'
,
None
)
en_name
=
request
.
POST
.
get
(
'en_name'
,
None
)
alias
=
request
.
POST
.
get
(
'alias'
,
None
)
image
=
request
.
POST
.
get
(
'image'
,
None
)
norms
=
request
.
POST
.
get
(
'norms'
,
None
)
grade
=
request
.
POST
.
get
(
'grade'
,
None
)
price
=
request
.
POST
.
get
(
'price'
,
None
)
country
=
request
.
POST
.
get
(
'country'
,
None
)
description
=
request
.
POST
.
get
(
'description'
,
None
)
comment_nums
=
request
.
POST
.
get
(
'comment_nums'
,
None
)
classify_id
=
request
.
POST
.
get
(
'classify_id'
,
None
)
if
not
id_
:
return
r'缺少参数'
data
=
self
.
rpc
[
'neptune/commodity/product/update'
](
id_
=
id_
,
cn_name
=
cn_name
,
en_name
=
en_name
,
alias
=
alias
,
image
=
image
,
norms
=
norms
,
grade
=
grade
,
price
=
price
,
country
=
country
,
description
=
description
,
comment_nums
=
comment_nums
,
classify_id
=
classify_id
)
.
unwrap
()
return
data
api/urls.py
View file @
10dbb7bc
...
...
@@ -26,6 +26,8 @@ from .tools import *
from
.beauty
import
*
from
.word_parent
import
*
from
.activity
import
*
from
.brand
import
*
from
.product
import
*
urlpatterns
=
[
...
...
@@ -179,6 +181,18 @@ urlpatterns = [
url
(
r'^activity/update$'
,
ActivityUpdateView
.
as_view
()),
url
(
r'^activity/delete$'
,
ActivityDeleteView
.
as_view
()),
# 品牌
url
(
r'^brand/list$'
,
BrandListView
.
as_view
()),
url
(
r'^brand/info$'
,
BrandInfoView
.
as_view
()),
url
(
r'^brand/create$'
,
BrandCreateView
.
as_view
()),
url
(
r'^brand/update$'
,
BrandUpdateView
.
as_view
()),
# 商品
url
(
r'^product/list$'
,
ProductListView
.
as_view
()),
url
(
r'^product/create$'
,
ProductCreateView
.
as_view
()),
url
(
r'^product/update$'
,
ProductUpdateView
.
as_view
()),
url
(
r'^product/info$'
,
ProductInfoView
.
as_view
()),
]
search_urlpatterns
=
[
...
...
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