Commit c26307b1 authored by 王浩's avatar 王浩

Merge branch 'haow/dev' into 'dev'

Haow/dev

See merge request !79
parents c2913230 d2a257c9
...@@ -4,6 +4,9 @@ from django.conf.urls import url ...@@ -4,6 +4,9 @@ from django.conf.urls import url
from .views import user from .views import user
from .views import topic from .views import topic
from .views import tag from .views import tag
from .views import reply
from .views import product
urlpatterns = [ urlpatterns = [
# grasp # grasp
...@@ -22,4 +25,11 @@ urlpatterns = [ ...@@ -22,4 +25,11 @@ urlpatterns = [
url(r'^v1/validate_3party_account$', user.Validate3PartyAccount.as_view(), name='validate_3party_account$'), url(r'^v1/validate_3party_account$', user.Validate3PartyAccount.as_view(), name='validate_3party_account$'),
url(r'^v1/user/batch_create_shadow_user$', user.BatchCreateShadowUser.as_view(), name='batch_create_shadow_user$'), url(r'^v1/user/batch_create_shadow_user$', user.BatchCreateShadowUser.as_view(), name='batch_create_shadow_user$'),
url(r'^v1/user/batch_update_user_level_fans$', user.BatchUpdateUserLevelFansNum.as_view(), name='batch_update_user_level_fans$'), url(r'^v1/user/batch_update_user_level_fans$', user.BatchUpdateUserLevelFansNum.as_view(), name='batch_update_user_level_fans$'),
# 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'),
] ]
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
if brand_info:
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)
if composition_infos:
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)
if category_info:
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)
if effect_info:
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()
if brand_info:
error, _ = self.parallel_rpc_call_result['create_brand']
if error:
return error, None
if composition_infos:
error, _ = self.parallel_rpc_call_result['batch_create_composition']
if error:
return error, None
if category_info:
error, _ = self.parallel_rpc_call_result['create_category']
if error:
return error, None
if effect_info:
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'), en_name=product_info.get('en_name'),
image=product_info.get('image', ''), norms=product_info.get('norms'),
grade=product_info.get('grade'), price=product_info.get('price'),
country=product_info.get('country'),
comment_nums=product_info.get('comment_nums'),
origin_product_id=product_info.get('id'), platform=PRODUCT_FLATFORM.BEVOL)
return error, ret
class BrandBatchCreate(BaseView):
'''批量创建品牌'''
def post(self, request):
brand_infos = json.loads(request.POST.get('data', '[]'))
if not brand_infos:
return self.error(self.get_ErrorInfo(ERROR.PARAMS_INCOMPLETE))
infos = [{
'id': item.get('origin_brand_id'),
'cn_name': item.get('cn_name'),
'en_name': item.get('en_name'),
'icon': item.get('icon'),
'description': item.get('description')
} for item in brand_infos]
error, _ = self.call_rpc('neptune/commodity/brand/batch_create',
infos=infos, platform=PRODUCT_FLATFORM.BEVOL)
if error:
return self.error(error)
return self.ok()
import json
from api.views.base_view import BaseView
class CreateReplyForInner(BaseView):
"""
内部使用,创建评论回复
"""
def post(self, request):
user_id = request.POST.get('user_id')
topic_id = request.POST.get('topic_id')
content = request.POST.get('content', '')
replied_id = request.POST.get('replied_id')
error, data = self.call_rpc('venus/community/reply/for_inner_create', user_id=user_id, topic_id=topic_id, content=content, replied_id=replied_id)
if error:
return self.error(error)
return self.ok(data=data)
...@@ -15,11 +15,11 @@ class CreateTagForBatch(BaseView): ...@@ -15,11 +15,11 @@ class CreateTagForBatch(BaseView):
tags = [] tags = []
if need_check: if need_check:
# 敏感词检测,获取可用的帖子 # 敏感词检测,获取可用的帖子
check_info = Sensitive.check([item["name"] for item in tag_list if item.get("name")]) check_info = Sensitive.check([item for item in tag_list if item])
for tag in tag_list: for tag in tag_list:
succ = check_info.get(tag.get("name")) if tag.get("name") else True succ = check_info.get(tag) if tag else True
if not succ: if not succ:
tags.append(tag) tags.append({"name": tag})
else: else:
tags = tag_list tags = tag_list
error, data = self.call_rpc('venus/community/tag/batch_create_not_classify', data=tags) error, data = self.call_rpc('venus/community/tag/batch_create_not_classify', data=tags)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment