Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
saturn
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
赵磊
saturn
Commits
0d00e609
Commit
0d00e609
authored
Jun 26, 2019
by
haowang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add product api
parent
4c15a57a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
0 deletions
+105
-0
urls.py
api/urls.py
+5
-0
product.py
api/views/product.py
+100
-0
No files found.
api/urls.py
View file @
0d00e609
...
...
@@ -5,6 +5,7 @@ from .views import user
from
.views
import
topic
from
.views
import
tag
from
.views
import
reply
from
.views
import
product
urlpatterns
=
[
...
...
@@ -27,4 +28,8 @@ urlpatterns = [
# reply
url
(
r'^v1/reply/create_for_inner$'
,
reply
.
CreateReplyForInner
.
as_view
(),
name
=
'create_reply_for_inner'
),
# product
url
(
r'^v1/product/batch_create$'
,
product
.
ProductBatchCreate
.
as_view
(),
name
=
'product_batch_create'
),
url
(
r'^v1/brand/batch_create$'
,
product
.
BrandBatchCreate
.
as_view
(),
name
=
'brand_batch_create'
),
]
api/views/product.py
0 → 100644
View file @
0d00e609
import
json
from
api.views.base_view
import
BaseView
from
libs.user
import
get_user_by_ids
from
alpha_types.neptune
import
ERROR
from
alpha_types.neptune
import
PRODUCT_FLATFORM
from
engine.logger
import
info_logger
,
error_logger
class
ProductBatchCreate
(
BaseView
):
'''批量创建商品 爬虫入口'''
def
post
(
self
,
request
):
product_info
=
json
.
loads
(
request
.
POST
.
get
(
'data'
,
'[]'
))
if
not
product_info
:
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
result
=
[]
for
info
in
product_info
:
error
,
ret
=
self
.
process
(
info
)
if
error
:
return
self
.
error
(
error
)
result
.
append
(
ret
)
return
self
.
ok
(
data
=
result
)
def
process
(
self
,
info
):
if
not
info
:
return
None
,
None
brand_info
=
info
.
pop
(
'brand'
,
{})
composition_infos
=
info
.
pop
(
'composition'
,
[])
category_info
=
info
.
pop
(
'category'
,
{})
effect_info
=
info
.
pop
(
'effect'
,
{})
product_id
=
None
if
info
:
error
,
result
=
self
.
create_product
(
info
)
if
error
:
return
error
,
None
product_id
=
result
.
get
(
'id'
)
if
not
product_id
:
return
error
,
None
# 创建商品失败 未获取到商品ID
self
.
add_parallel_rpc_call_info
(
'create_brand'
,
'neptune/commodity/brand/create'
,
cn_name
=
brand_info
.
get
(
'cnName'
),
icon
=
brand_info
.
get
(
'imgSrc'
),
description
=
brand_info
.
get
(
'description'
),
en_name
=
brand_info
.
get
(
'en_name'
),
origin_brand_id
=
brand_info
.
get
(
'id'
),
platform
=
PRODUCT_FLATFORM
.
BEVOL
,
product_id
=
product_id
)
self
.
add_parallel_rpc_call_info
(
'batch_create_composition'
,
'neptune/commodity/composition/batch_create'
,
infos
=
composition_infos
,
platform
=
PRODUCT_FLATFORM
.
BEVOL
,
product_id
=
product_id
)
self
.
add_parallel_rpc_call_info
(
'create_category'
,
'neptune/commodity/category/create'
,
cn_name
=
category_info
.
get
(
'name'
),
platform
=
PRODUCT_FLATFORM
.
BEVOL
,
origin_category_id
=
category_info
.
get
(
'id'
),
product_id
=
product_id
)
self
.
add_parallel_rpc_call_info
(
'create_effect'
,
'neptune/commodity/effect/create'
,
cn_name
=
effect_info
.
get
(
'name'
),
origin_effect_id
=
effect_info
.
get
(
'id'
),
platform
=
PRODUCT_FLATFORM
.
BEVOL
,
product_id
=
product_id
)
self
.
shoot_rpc_calls_in_parallel
()
error
,
_
=
self
.
parallel_rpc_call_result
[
'create_brand'
]
if
error
:
return
error
,
None
error
,
_
=
self
.
parallel_rpc_call_result
[
'batch_create_composition'
]
if
error
:
return
error
,
None
error
,
_
=
self
.
parallel_rpc_call_result
[
'create_category'
]
if
error
:
return
error
,
None
error
,
_
=
self
.
parallel_rpc_call_result
[
'create_effect'
]
if
error
:
return
error
,
None
return
None
,
result
def
create_product
(
self
,
product_info
):
error
,
ret
=
self
.
call_rpc
(
'neptune/commodity/product/create'
,
cn_name
=
product_info
.
get
(
'cn_name'
),
norms
=
product_info
.
get
(
'norms'
),
grades
=
product_info
.
get
(
'grades'
),
price
=
product_info
.
get
(
'price'
),
en_name
=
product_info
.
get
(
'en_name'
),
country
=
product_info
.
get
(
'country'
),
origin_product_id
=
product_info
.
get
(
'id'
),
platform
=
PRODUCT_FLATFORM
.
BEVOL
)
return
error
,
ret
class
BrandBatchCreate
(
BaseView
):
'''批量创建品牌'''
def
post
(
self
,
request
):
brand_infos
=
request
.
POST
.
get
(
'data'
)
if
not
brand_infos
:
return
self
.
error
(
self
.
get_ErrorInfo
(
ERROR
.
PARAMS_INCOMPLETE
))
error
,
ret
=
self
.
call_rpc
(
'neptune/commodity/brand/batch_create'
,
infos
=
brand_infos
,
platform
=
PRODUCT_FLATFORM
.
BEVOL
)
return
error
,
ret
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