Commit 900e796e authored by 王浩's avatar 王浩

Merge branch 'haow/dev' into 'test'

product management

See merge request alpha/sun!235
parents ea25f7d7 1af21e31
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_infos'] = [{'id': id_, 'cn_name': 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['grade'] = 0
obj['classify_info'] = []
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 = {
'list': 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()
classify_infos = self.rpc['neptune/commodity/classify/infos'](brand_id=id_).unwrap()
data['classify_infos'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')} for obj in classify_infos]
category_ids = self.rpc['neptune/commodity/brand/category_ids'](id_=id_).unwrap()
category_infos = self.rpc['neptune/commodity/category/infos'](ids=category_ids).unwrap()
data['category_infos'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')} for obj in category_infos]
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
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.get('list'):
obj.pop('platform')
return data
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()
return data
import json
from utils.base import APIView, get_offset_count
from utils.logger import error_logger
class EffectListView(APIView):
def get(self, request):
offset, count = get_offset_count(request)
cn_name = request.GET.get('cn_name')
data = self.rpc['neptune/commodity/effect/list'](
offset=offset, count=count, cn_name=cn_name).unwrap()
return data
......@@ -10,12 +10,13 @@ class PictorialListView(APIView):
offset = int(request.GET.get('page', 1))
limit = int(request.GET.get('limit', 10))
filters = self.handle_filter(request.GET.get('filter', '{}'))
product_id = request.GET.get('product_id')
if star_id:
filters.update({'star_id': star_id})
if user_id:
filters.update({'user_id': user_id})
try:
data = self.rpc['venus/sun/pictorial/list'](filters=filters, offset=(offset-1)*limit, limit=limit).unwrap()
data = self.rpc['venus/sun/pictorial/list'](filters=filters, offset=(offset-1)*limit, limit=limit, product_id=product_id).unwrap()
except Exception as e:
error_logger.error(u'获取画报列表失败%s' , e)
raise
......@@ -143,3 +144,37 @@ class PictorialFeedDelete(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': '更新成功'
}
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('product_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('product_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_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('product_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)
classify_product_dict = self.get_classify_infos(product_ids)
print(category_product_dict, effect_product_dict, classify_product_dict)
for obj in data:
product_id = obj.get('id')
obj['brand_info'] = {
'id': brand_product_dict.get(str(product_id)).get('id'),
'cn_name': brand_product_dict.get(str(product_id)).get('cn_name')} if brand_product_dict.get(str(product_id)) else ''
obj['category_infos'] = [{'id': obj.get('id'), 'cn_name': 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_infos'] = [{'id': obj.get('id'), 'cn_name': 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_infos'] = [{'id': obj.get('id'), 'cn_name': 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')
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 = {
'list': data,
'total': count,
}
return result
class ProductInfoView(APIView):
def get_category_infos(self, product_id):
category_infos = self.rpc['neptune/commodity/category/infos'](product_id=product_id).unwrap()
if not category_infos:
return []
return [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')} for obj in category_infos]
def get_effect_infos(self, product_id):
effect_infos = self.rpc['neptune/commodity/effect/infos'](product_id=product_id).unwrap()
if not effect_infos:
return []
return [{'id': obj.get('id'), 'cn_name': 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_info'] = {'id': brand_info[0].get('id'), 'cn_name': brand_info[0].get('cn_name')} if brand_info else {}
classify_infos = self.rpc['neptune/commodity/classify/infos'](product_ids=[id_]).unwrap()
data['classify_infos'] = [{'id': obj.get('id'), 'cn_name': obj.get('cn_name')} for obj in classify_infos]
data['category_infos'] = self.get_category_infos(id_)
data['effect_infos'] = self.get_effect_infos(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_ids = json.loads(request.POST.get('classify_ids', '[]'))
category_ids = json.loads(request.POST.get('category_ids', '[]'))
effect_ids = json.loads(request.POST.get('effect_ids', '[]'))
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_ids=classify_ids,
category_ids=category_ids, effect_ids=effect_ids, is_online=is_online).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_ids = json.loads(request.POST.get('classify_ids', '[]'))
category_ids = json.loads(request.POST.get('category_ids', '[]'))
effect_ids = json.loads(request.POST.get('effect_ids', '[]'))
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_ids=classify_ids,
category_ids=category_ids, effect_ids=effect_ids, is_online=is_online).unwrap()
return data
......@@ -17,6 +17,7 @@ class TopicListView(APIView):
filters = json.loads(request.GET.get('filter', "{}"))
sorts_by = list(map(lambda i: int(i), request.GET.getlist('sort_params[]', [3])))
drop_score = request.GET.get('drop_score', None)
product_id = request.GET.get('product_id', None)
if user_id:
filters.update({'user_id': user_id})
......@@ -40,7 +41,7 @@ class TopicListView(APIView):
try:
data = self.rpc['venus/sun/topic/list'](
topic_ids=topic_ids, pictorial_id=pictorial_id
topic_ids=topic_ids, pictorial_id=pictorial_id, product_id=product_id,
).unwrap()
except Exception as e:
error_logger.error(u'获取帖子列表失败%s', e)
......@@ -244,3 +245,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': '更新成功'
}
......@@ -26,6 +26,11 @@ from .tools import *
from .beauty import *
from .word_parent import *
from .activity import *
from .brand import *
from .product import *
from .category import *
from .classify import *
from .effect import *
urlpatterns = [
......@@ -59,6 +64,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()),
......@@ -145,7 +152,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()),
......@@ -185,6 +193,27 @@ 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()),
# 商品类目
url(r'^category/list$', CategoryListView.as_view()),
# 商品分类
url(r'^classify/list$', ClassifyListView.as_view()),
# 商品功效
url(r'^effect/list$', EffectListView.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