|
@@ -65,10 +65,11 @@ class VseesManagement(View):
|
|
|
vsees_id = request_dict.get('vsees_id', None)
|
|
|
product_type = request_dict.get('type', None)
|
|
|
if not all([vsees_id, product_type]):
|
|
|
- return response.json(444, 'vsees_id, product_type')
|
|
|
+ return response.json(444, 'vsees_id, type')
|
|
|
try:
|
|
|
- product_info_qs = vseesProductInfo.objects.filter(vsees__id=vsees_id, product_type=product_type,
|
|
|
- status=1).values('title', 'file_name', 'status')
|
|
|
+ product_info_qs = vseesProductInfo.objects.filter(vsees__id=vsees_id, type=product_type,
|
|
|
+ status=0).values('title', 'file_name', 'status').order_by(
|
|
|
+ '-add_time')
|
|
|
if not product_info_qs.exists():
|
|
|
return response.json(173)
|
|
|
return response.json(0, list(product_info_qs))
|
|
@@ -96,12 +97,12 @@ class VseesManagement(View):
|
|
|
product_type = request_dict.get('type', None)
|
|
|
|
|
|
if not all([file or url, title, product_type, vsees_id]):
|
|
|
- return response.json(444, 'error: file or url, title, product_type, vsees_id')
|
|
|
+ return response.json(444, 'error: file or url, title, type, vsees_id')
|
|
|
nowTime = int(time.time())
|
|
|
fileName = str(file)
|
|
|
device_type = int(product_type)
|
|
|
# 判断上架状态标题是否重复
|
|
|
- product_info_qs = vseesProductInfo.objects.filter(vsees__id=vsees_id, title=title, type=product_type, status=1)
|
|
|
+ product_info_qs = vseesProductInfo.objects.filter(vsees__id=vsees_id, title=title, type=product_type, status=0)
|
|
|
if product_info_qs.exists():
|
|
|
return response.json(174)
|
|
|
try:
|
|
@@ -110,7 +111,7 @@ class VseesManagement(View):
|
|
|
'vsees_id': vsees_id,
|
|
|
'title': title,
|
|
|
'type': device_type,
|
|
|
- 'status': 1,
|
|
|
+ 'status': 0,
|
|
|
'add_time': nowTime,
|
|
|
'upd_time': nowTime,
|
|
|
}
|
|
@@ -122,12 +123,12 @@ class VseesManagement(View):
|
|
|
return response.json(0)
|
|
|
# 添加说明书
|
|
|
elif device_type == 1:
|
|
|
- url = 'https://d2cjxvw3tr9apc.cloudfront.net/vsees/clarification'.format(fileName)
|
|
|
- file_key = 'vsees/clarification'
|
|
|
+ url = 'https://d2cjxvw3tr9apc.cloudfront.net/vsees/clarification/{}'.format(fileName)
|
|
|
+ file_key = 'vsees/clarification/{}'
|
|
|
# 添加固件
|
|
|
elif device_type == 2:
|
|
|
- url = 'https://d2cjxvw3tr9apc.cloudfront.net/vsees/firmware'.format(fileName)
|
|
|
- file_key = 'vsees/firmware'
|
|
|
+ url = 'https://d2cjxvw3tr9apc.cloudfront.net/vsees/firmware/{}'.format(fileName)
|
|
|
+ file_key = 'vsees/firmware/{}'
|
|
|
key = file_key.format(fileName)
|
|
|
s3 = cls.upload(file, key)
|
|
|
if s3:
|
|
@@ -162,31 +163,34 @@ class VseesManagement(View):
|
|
|
@classmethod
|
|
|
def upload_file(cls, request_dict, request, response):
|
|
|
"""
|
|
|
- 重新上传文件按钮
|
|
|
+ 重新上传文件
|
|
|
@request_dict product_id:产品信息id
|
|
|
@request_dict file:文件
|
|
|
@request_dict device_type:0:视频, 1:说明书, 2:固件
|
|
|
"""
|
|
|
file = request.FILES.get('file', None)
|
|
|
product_id = request_dict.get('product_id', None)
|
|
|
- device_type = request_dict.get('type', None)
|
|
|
- if not all([file, device_type, product_id]):
|
|
|
- return response.json(444, 'error: file, device_type, product_id')
|
|
|
+ product_type = request_dict.get('type', None)
|
|
|
+ if not all([file, product_type, product_id]):
|
|
|
+ return response.json(444, 'error: file, type, product_id')
|
|
|
nowTime = int(time.time())
|
|
|
fileName = str(file)
|
|
|
+ product_info_qs=vseesProductInfo.objects.filter(id=product_id, type=product_type, status=0)
|
|
|
+ if not product_info_qs.exists():
|
|
|
+ return response.json(177)
|
|
|
try:
|
|
|
# 说明
|
|
|
- if device_type == 1:
|
|
|
- url = 'https://d2cjxvw3tr9apc.cloudfront.net/vsees/clarification'.format(fileName)
|
|
|
- file_key = 'vsees/clarification'
|
|
|
+ if product_type == 1:
|
|
|
+ url = 'https://d2cjxvw3tr9apc.cloudfront.net/vsees/clarification/{}'.format(fileName)
|
|
|
+ file_key = 'vsees/clarification/{}'
|
|
|
# 固件
|
|
|
else:
|
|
|
- url = 'https://d2cjxvw3tr9apc.cloudfront.net/vsees/firmware'.format(fileName)
|
|
|
- file_key = 'vsees/firmware'
|
|
|
+ url = 'https://d2cjxvw3tr9apc.cloudfront.net/vsees/firmware/{}'.format(fileName)
|
|
|
+ file_key = 'vsees/firmware/{}'
|
|
|
key = file_key.format(fileName)
|
|
|
s3 = cls.upload(file, key)
|
|
|
if s3:
|
|
|
- vseesProductInfo.objects.filter(id=product_id).update(url=url, upd_time=nowTime)
|
|
|
+ vseesProductInfo.objects.filter(id=product_id).update(url=url, upd_time=nowTime, file_name=fileName)
|
|
|
return response.json(0)
|
|
|
return response.json(177)
|
|
|
except Exception as e:
|
|
@@ -204,7 +208,8 @@ class VseesManagement(View):
|
|
|
status = request_dict.get('status', None)
|
|
|
if not all([status, product_id]):
|
|
|
return response.json(444, 'error: status, product_id')
|
|
|
- if int(status) == 2:
|
|
|
+ # 只下架
|
|
|
+ if int(status) == 0:
|
|
|
return response.json(177)
|
|
|
vseesProductInfo.objects.filter(id=product_id).update(status=status)
|
|
|
return response.json(0)
|
|
@@ -222,7 +227,7 @@ class VseesManagement(View):
|
|
|
title = request_dict.get('title')
|
|
|
if not product_id:
|
|
|
return response.json(444, 'error: product_id')
|
|
|
- product_info_qs = vseesProductInfo.objects.filter(id=product_id, title=title, status=1)
|
|
|
+ product_info_qs = vseesProductInfo.objects.filter(id=product_id, title=title, status=0)
|
|
|
if product_info_qs.exists():
|
|
|
return response.json(174)
|
|
|
if title:
|
|
@@ -261,12 +266,12 @@ class VseesManagement(View):
|
|
|
try:
|
|
|
product_info_qs = vseesProductInfo.objects.all()
|
|
|
if not title and product_type:
|
|
|
- product_info_qs = product_info_qs.filter(vsees__id=vsees_id, status=1).values('title').order_by(
|
|
|
+ product_info_qs = product_info_qs.filter(vsees__id=vsees_id, status=0).values('title').order_by(
|
|
|
'-add_time')
|
|
|
return response.json(0, list(product_info_qs))
|
|
|
else:
|
|
|
product_info_qs = product_info_qs.filter(vsees__id=vsees_id, title=title, type=product_type,
|
|
|
- status=1).values('url').order_by('-add_time')
|
|
|
+ status=0).values('url').order_by('-add_time')
|
|
|
if not product_info_qs.exists():
|
|
|
return response.json(173)
|
|
|
return response.json(0, {'url': product_info_qs[0]['url']})
|