|
@@ -153,55 +153,104 @@ class EvaluationActivityView(View):
|
|
|
bucket = "ansjerfilemanager"
|
|
|
s3_obj = AmazonS3Util(ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME)
|
|
|
s3_url = 'https://{}.s3.{}.amazonaws.com.cn/'.format(bucket, REGION_NAME)
|
|
|
- if carousel_image:
|
|
|
- carousel_image_path = '前端/EvaluationActivity/carousel_image_{}.jpg'.format(issue)
|
|
|
- s3_obj.upload_file_obj(
|
|
|
- bucket,
|
|
|
- carousel_image_path,
|
|
|
- carousel_image,
|
|
|
- {"ContentType": carousel_image.content_type, "ACL": "public-read"},
|
|
|
- )
|
|
|
- carousel_image_url = s3_url + carousel_image_path
|
|
|
- if activity_id:
|
|
|
- FreeEvaluationActivity.objects.filter(id=activity_id).update(carousel_image_url=carousel_image_url)
|
|
|
- if details_image:
|
|
|
- details_image_path = '前端/EvaluationActivity/details_image_{}.jpg'.format(issue)
|
|
|
- s3_obj.upload_file_obj(
|
|
|
- bucket,
|
|
|
- details_image_path,
|
|
|
- details_image,
|
|
|
- {"ContentType": details_image.content_type, "ACL": "public-read"},
|
|
|
- )
|
|
|
- details_image_url = s3_url + details_image_path
|
|
|
- if activity_id:
|
|
|
- FreeEvaluationActivity.objects.filter(id=activity_id).update(details_image_url=details_image_url)
|
|
|
+
|
|
|
with transaction.atomic():
|
|
|
if activity_id: # 编辑活动
|
|
|
- FreeEvaluationActivity.objects.filter(id=activity_id).update(issue=issue, product_name=product_name,
|
|
|
- product_number=product_number,
|
|
|
- original_price=original_price,
|
|
|
- is_show=is_show, update_time=now_time,
|
|
|
- activity_name=activity_name)
|
|
|
+ activity = FreeEvaluationActivity.objects.get(id=activity_id)
|
|
|
+ activity.activity_name = activity_name
|
|
|
+ activity.issue = issue
|
|
|
+ activity.product_number = product_number
|
|
|
+ activity.product_name = product_name
|
|
|
+ activity.original_price = original_price
|
|
|
+ activity.is_show = is_show
|
|
|
+ activity.update_time = now_time
|
|
|
+
|
|
|
+ # 上传轮播图
|
|
|
+ if carousel_image:
|
|
|
+ carousel_image_path = '前端/EvaluationActivity/carousel_image_{}.jpg'.format(activity_id)
|
|
|
+ s3_obj.upload_file_obj(
|
|
|
+ bucket,
|
|
|
+ carousel_image_path,
|
|
|
+ carousel_image,
|
|
|
+ {"ContentType": carousel_image.content_type, "ACL": "public-read"},
|
|
|
+ )
|
|
|
+ activity.carousel_image_url = s3_url + carousel_image_path
|
|
|
+
|
|
|
+ # 上传详情图
|
|
|
+ if details_image:
|
|
|
+ details_image_path = '前端/EvaluationActivity/details_image_{}.jpg'.format(activity_id)
|
|
|
+ s3_obj.upload_file_obj(
|
|
|
+ bucket,
|
|
|
+ details_image_path,
|
|
|
+ details_image,
|
|
|
+ {"ContentType": details_image.content_type, "ACL": "public-read"},
|
|
|
+ )
|
|
|
+ activity.details_image_url = s3_url + details_image_path
|
|
|
+
|
|
|
+ activity.save()
|
|
|
+
|
|
|
+ # 处理活动时间节点
|
|
|
ActivityTime.objects.filter(activity_id=activity_id).delete()
|
|
|
for index, item in enumerate(activity_process):
|
|
|
- ActivityTime.objects.create(activity_id=activity_id, node_content=item['node_content'],
|
|
|
- start_time=item['start_time'], end_time=item['end_time'],
|
|
|
- sort=index)
|
|
|
- else: # 增加活动
|
|
|
+ ActivityTime.objects.create(
|
|
|
+ activity_id=activity_id,
|
|
|
+ node_content=item['node_content'],
|
|
|
+ start_time=item['start_time'],
|
|
|
+ end_time=item['end_time'],
|
|
|
+ sort=index
|
|
|
+ )
|
|
|
+ else: # 添加活动
|
|
|
if not all([carousel_image, details_image]):
|
|
|
return response.json(404)
|
|
|
- activity_qs = FreeEvaluationActivity.objects.create(activity_name=activity_name, issue=issue,
|
|
|
- product_number=product_number,
|
|
|
- carousel_image_url=carousel_image_url,
|
|
|
- is_show=is_show, product_name=product_name,
|
|
|
- original_price=original_price,
|
|
|
- details_image_url=details_image_url,
|
|
|
- created_time=now_time, update_time=now_time)
|
|
|
+
|
|
|
+ # 创建活动对象(先不保存图片URL)
|
|
|
+ activity = FreeEvaluationActivity.objects.create(
|
|
|
+ activity_name=activity_name,
|
|
|
+ issue=issue,
|
|
|
+ product_number=product_number,
|
|
|
+ product_name=product_name,
|
|
|
+ original_price=original_price,
|
|
|
+ is_show=is_show,
|
|
|
+ created_time=now_time,
|
|
|
+ update_time=now_time,
|
|
|
+ carousel_image_url='', # 初始化为空
|
|
|
+ details_image_url=''
|
|
|
+ )
|
|
|
+ activity_id = activity.id
|
|
|
+
|
|
|
+ # 上传轮播图并更新URL
|
|
|
+ carousel_image_path = '前端/EvaluationActivity/carousel_image_{}.jpg'.format(activity_id)
|
|
|
+ s3_obj.upload_file_obj(
|
|
|
+ bucket,
|
|
|
+ carousel_image_path,
|
|
|
+ carousel_image,
|
|
|
+ {"ContentType": carousel_image.content_type, "ACL": "public-read"},
|
|
|
+ )
|
|
|
+ activity.carousel_image_url = s3_url + carousel_image_path
|
|
|
+
|
|
|
+ # 上传详情图并更新URL
|
|
|
+ details_image_path = '前端/EvaluationActivity/details_image_{}.jpg'.format(activity_id)
|
|
|
+ s3_obj.upload_file_obj(
|
|
|
+ bucket,
|
|
|
+ details_image_path,
|
|
|
+ details_image,
|
|
|
+ {"ContentType": details_image.content_type, "ACL": "public-read"},
|
|
|
+ )
|
|
|
+ activity.details_image_url = s3_url + details_image_path
|
|
|
+
|
|
|
+ activity.save() # 保存图片URL
|
|
|
+
|
|
|
+ # 创建活动时间节点
|
|
|
for index, item in enumerate(activity_process):
|
|
|
- ActivityTime.objects.create(activity_id=activity_qs.id, node_content=item['node_content'],
|
|
|
- start_time=item['start_time'], end_time=item['end_time'],
|
|
|
- sort=index)
|
|
|
- return response.json(0)
|
|
|
+ ActivityTime.objects.create(
|
|
|
+ activity_id=activity_id,
|
|
|
+ node_content=item['node_content'],
|
|
|
+ start_time=item['start_time'],
|
|
|
+ end_time=item['end_time'],
|
|
|
+ sort=index
|
|
|
+ )
|
|
|
+
|
|
|
+ return response.json(0)
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|