Commit eb202909 authored by haowang's avatar haowang

add api about product

parent 0d6aa3bb
......@@ -39,7 +39,7 @@ class BrandListView(APIView):
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,
'list': data,
'total': total,
}
......
......@@ -12,9 +12,6 @@ class CategoryListView(APIView):
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')
for obj in data.get('list'):
obj.pop('platform')
return data
......@@ -11,10 +11,4 @@ class ClassifyListView(APIView):
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
......@@ -95,3 +95,37 @@ class PictorialTopics(APIView):
return {
'message': '更新成功'
}
class PictorialProductAdd(APIView):
"""画报添加商品关系"""
def post(self, request):
id_ = request.POST.get('id')
product_id = request.POST.get('product_id')
try:
self.rpc['venus/sun/pictorial/add_product'](id_=id_, product_id=product_id).unwrap()
except Exception as e:
error_logger.error(u'编辑%s画报信息失败%s' % (id_, e))
raise
return {
'message': '更新成功'
}
class PictorialProductDel(APIView):
"""画报删除商品关系"""
def post(self, request):
id_ = request.POST.get('id')
product_id = request.POST.get('product_id')
try:
self.rpc['venus/sun/pictorial/del_product'](id_=id_, product_id=product_id).unwrap()
except Exception as e:
error_logger.error(u'编辑%s画报信息失败%s' % (id_, e))
raise
return {
'message': '更新成功'
}
......@@ -37,6 +37,19 @@ class ProductListView(APIView):
ret[str(product_id)] = [obj]
return ret
def get_classify_infos(self, product_ids):
classify_infos = self.rpc['neptune/commodity/classify/infos'](product_ids=product_ids).unwrap()
ret = {}
if not classify_infos:
return ret
for obj in classify_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)
......@@ -65,6 +78,7 @@ class ProductListView(APIView):
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)
classify_product_dict = self.get_classify_infos(product_ids)
for obj in data:
product_id = obj.get('id')
......@@ -73,6 +87,8 @@ class ProductListView(APIView):
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['classify_names'] = [obj.get('cn_name')
for obj in classify_product_dict.get(str(product_id))] if classify_product_dict.get(str(product_id)) else []
obj.pop('norms')
obj.pop('country')
......@@ -133,14 +149,14 @@ class ProductCreateView(APIView):
description = request.POST.get('description', None)
comment_nums = request.POST.get('comment_nums', None)
classify_id = request.POST.get('classify_id', None)
is_online = request.POST.get('is_online')
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()
country=country, description=description, comment_nums=comment_nums, classify_id=classify_id, is_online=is_online).unwrap()
return data
......@@ -160,13 +176,13 @@ class ProductUpdateView(APIView):
description = request.POST.get('description', None)
comment_nums = request.POST.get('comment_nums', None)
classify_id = request.POST.get('classify_id', None)
is_online = request.POST.get('is_online')
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()
country=country, description=description, comment_nums=comment_nums, classify_id=classify_id, is_online=is_online).unwrap()
return data
......@@ -227,3 +227,37 @@ class TopicRelatePictorialInfo(APIView):
error_logger.error(u'获取帖子画报列表失败%s', e)
raise
return {'data': data}
class TopicProductAdd(APIView):
"""帖子添加商品关系"""
def post(self, request):
id_ = request.POST.get('id')
product_id = request.POST.get('product_id')
try:
self.rpc['venus/sun/topic/add_product'](id_=id_, product_id=product_id).unwrap()
except Exception as e:
error_logger.error(u'编辑%s帖子信息失败%s' % (id_, e))
raise
return {
'message': '更新成功'
}
class TopicProductDel(APIView):
"""帖子删除商品关系"""
def post(self, request):
id_ = request.POST.get('id')
product_id = request.POST.get('product_id')
try:
self.rpc['venus/sun/topic/del_product'](id_=id_, product_id=product_id).unwrap()
except Exception as e:
error_logger.error(u'编辑%s帖子信息失败%s' % (id_, e))
raise
return {
'message': '更新成功'
}
......@@ -28,6 +28,8 @@ from .word_parent import *
from .activity import *
from .brand import *
from .product import *
from .category import *
from .classify import *
urlpatterns = [
......@@ -60,6 +62,8 @@ urlpatterns = [
url(r'^topic/reply/batch_delete$', ReplyUpdateOrCreateView.as_view()),
url(r'^topic/reply/create$', ReplyCreate.as_view()),
url(r'^topic/related_pictorial_info$', TopicRelatePictorialInfo.as_view()),
url(r'^topic/product/add$', TopicProductAdd.as_view()),
url(r'^topic/product/del$', TopicProductDel.as_view()),
# star相关
url(r'^celebrity/list$', CelebrityListView.as_view()),
......@@ -143,6 +147,8 @@ urlpatterns = [
url(r'^pictorial/create$', PictorialUpdateOrCreate.as_view()),
url(r'^pictorial/topics$', PictorialTopics.as_view()),
url(r'^pictorial/user/list$', PictorialUserList.as_view()),
url(r'^pictorial/product/add$', PictorialProductAdd.as_view()),
url(r'^pictorial/product/del$', PictorialProductDel.as_view()),
#运营位
url(r'^topic/home_recommend/list', TopicHomeRecommendList.as_view()),
......@@ -193,6 +199,12 @@ urlpatterns = [
url(r'^product/update$', ProductUpdateView.as_view()),
url(r'^product/info$', ProductInfoView.as_view()),
# 商品类目
url(r'^category/list$', CategoryListView.as_view()),
# 商品分类
url(r'^classify/list$', ClassifyListView.as_view()),
]
search_urlpatterns = [
......
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