Commit bde8acc8 authored by 王浩's avatar 王浩

Merge branch 'haow/dev' into 'dev'

add api about product

See merge request alpha/sun!227
parents ff5d5136 600e008f
......@@ -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,
}
......
......@@ -11,10 +11,7 @@ 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
\ No newline at end of file
return data
......@@ -101,7 +101,7 @@ class PictorialTopics(APIView):
class PictorialFeedlListView(APIView):
def get(self, request):
order_by = request.GET.get('order_by', "-id")
offset = int(request.GET.get('page', 1))
offset = int(request.GET.get('offset', 1))
limit = int(request.GET.get('limit', 10))
try:
......@@ -143,4 +143,38 @@ class PictorialFeedDelete(APIView):
raise
return {
'message': '删除成功'
}
\ No newline at end of file
}
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
......@@ -110,6 +110,12 @@ class AddVirtFans(APIView):
fans_num_column = [item.value for item in columns[1]]
user_id_fans_num_data = list(zip(user_id_column[1:], fans_num_column[1:]))
#做一次数据清洗。 避免文件中的空行
user_id_fans_num_data = [
(user_id, fans_num) for user_id, fans_num in user_id_fans_num_data
if isinstance(user_id, int) and isinstance(fans_num, int)
]
try:
self.rpc['venus/sun/tools/add_virt_fans'](data=user_id_fans_num_data).unwrap()
except:
......
......@@ -244,3 +244,37 @@ class TopicBallot(APIView):
return {
"message": "更新成功"
}
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 = [
......@@ -61,6 +63,8 @@ urlpatterns = [
url(r'^topic/reply/create$', ReplyCreate.as_view()),
url(r'^topic/related_pictorial_info$', TopicRelatePictorialInfo.as_view()),
url(r'^topic/ballot$', TopicBallot.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()),
......@@ -147,7 +151,8 @@ urlpatterns = [
url(r'^pictorial/feed/list$', PictorialFeedlListView.as_view()),
url(r'^pictorial/feed/rank$', PictorialFeedlRank.as_view()),
url(r'^pictorial/feed/delete$', PictorialFeedDelete.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()),
......@@ -198,6 +203,12 @@ urlpatterns = [
url(r'^product/create$', ProductCreateView.as_view()),
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()),
]
......
......@@ -27,17 +27,21 @@ class WordParentInfoView(APIView):
class WordParentCreateView(APIView):
def post(self, request):
name = request.POST.get('name', None)
children_words = json.loads(request.POST.get('children_words', '[]'))
content_ad = request.POST.get('content_ad', '')
makeup_ad = request.POST.get('makeup_ad', '')
dress_ad = request.POST.get('dress_ad', '')
gender = request.POST.get('gender', 0)
if not name:
return r'缺少参数'
data = self.rpc['venus/sun/word_parent/add'](name=name, children_words=children_words, content_ad=content_ad, makeup_ad=makeup_ad, dress_ad=dress_ad, gender=gender).unwrap()
data = {}
data["name"] = request.POST.get('name', None)
children_words = request.POST.get('children_words')
data["children_words"] = json.loads(children_words) if children_words else []
data["content_ad"] = request.POST.get('content_ad', None)
data["makeup_ad"] = request.POST.get('makeup_ad', None)
data["dress_ad"] = request.POST.get('dress_ad', None)
data["gender"] = request.POST.get('gender', None)
makeup_pictorial_ids = request.POST.get('makeup_pictorial_ids')
clothing_pictorial_ids = request.POST.get('clothing_pictorial_ids')
data["makeup_pictorial_ids"] = json.loads(makeup_pictorial_ids) if makeup_pictorial_ids else []
data["clothing_pictorial_ids"] = json.loads(clothing_pictorial_ids) if clothing_pictorial_ids else []
data = self.rpc['venus/sun/word_parent/add'](data=data).unwrap()
return data
......@@ -45,18 +49,22 @@ class WordParentCreateView(APIView):
class WordParentUpdateView(APIView):
def post(self, request):
id_ = request.POST.get('id', None)
name = request.POST.get('name', None)
children_words = json.loads(request.POST.get('children_words', '[]'))
content_ad = request.POST.get('content_ad', None)
makeup_ad = request.POST.get('makeup_ad', None)
dress_ad = request.POST.get('dress_ad', None)
gender = request.POST.get('gender', None)
if not id_:
return r'缺少参数'
data = self.rpc['venus/sun/word_parent/edit'](id_=id_, name=name, children_words=children_words, content_ad=content_ad, makeup_ad=makeup_ad, dress_ad=dress_ad, gender=gender).unwrap()
data = {}
data["id"] = request.POST.get('id', None)
data["name"] = request.POST.get('name', None)
children_words = request.POST.get('children_words')
data["children_words"] = json.loads(children_words) if children_words else []
data["content_ad"] = request.POST.get('content_ad', None)
data["makeup_ad"] = request.POST.get('makeup_ad', None)
data["dress_ad"] = request.POST.get('dress_ad', None)
data["gender"] = request.POST.get('gender', None)
makeup_pictorial_ids = request.POST.get('makeup_pictorial_ids')
clothing_pictorial_ids = request.POST.get('clothing_pictorial_ids')
data["makeup_pictorial_ids"] = json.loads(makeup_pictorial_ids) if makeup_pictorial_ids else []
data["clothing_pictorial_ids"] = json.loads(clothing_pictorial_ids) if clothing_pictorial_ids else []
data = self.rpc['venus/sun/word_parent/edit'](data=data).unwrap()
if not data:
return r'更新失败'
......
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