|
@@ -787,26 +787,59 @@ class serveManagement(View):
|
|
|
@staticmethod
|
|
|
def addOrEditCouponLang(request_dict, response):
|
|
|
coupon_id = request_dict.get('couponID', None)
|
|
|
- coupon_type = int(request_dict.get('type', 0))
|
|
|
- use_range = request_dict.get('use_range', '')
|
|
|
- coupon_discount = request_dict.get('coupon_discount', '')
|
|
|
+ lang = request_dict.get('lang', None)
|
|
|
+ instruction = request_dict.get('instruction', '')
|
|
|
+ quota = request_dict.get('quota', '')
|
|
|
+ unit = request_dict.get('unit', '')
|
|
|
+ unit = request_dict.get('unit', '')
|
|
|
+ remark = request_dict.get('remark', None)
|
|
|
is_edit = request_dict.get('isEdit', None)
|
|
|
|
|
|
- if not all([coupon_type, use_range, coupon_discount]):
|
|
|
+ if not all([coupon_id, lang]):
|
|
|
return response.json(444)
|
|
|
|
|
|
try:
|
|
|
- coupon_data = {
|
|
|
- 'type': coupon_type,
|
|
|
- 'use_range': use_range,
|
|
|
- 'coupon_discount': coupon_discount
|
|
|
- }
|
|
|
- if is_edit:
|
|
|
- if not coupon_id:
|
|
|
+ # 查询优惠券是否存在
|
|
|
+ coupon_qs = CouponConfigModel.objects.get(id=coupon_id)
|
|
|
+ if not coupon_qs:
|
|
|
+ return response.json(173)
|
|
|
+ if is_edit: # 编辑
|
|
|
+ lang_id = request_dict.get('langID', None)
|
|
|
+ if not lang_id:
|
|
|
return response.json(444)
|
|
|
- CouponConfigModel.objects.filter(id=coupon_id).update(**coupon_data)
|
|
|
- else:
|
|
|
- CouponConfigModel.objects.create(**coupon_data)
|
|
|
+ Lang.objects.filter(
|
|
|
+ id=lang_id).update(
|
|
|
+ lang=lang,
|
|
|
+ instruction=instruction,
|
|
|
+ quota=quota,
|
|
|
+ unit=unit,
|
|
|
+ remark=remark
|
|
|
+ )
|
|
|
+ else: # 添加
|
|
|
+ lang_obj = Lang.objects.filter(
|
|
|
+ lang=lang,
|
|
|
+ instruction=instruction,
|
|
|
+ quota=quota,
|
|
|
+ unit=unit,
|
|
|
+ remark=remark
|
|
|
+ )
|
|
|
+ if not lang_obj.exists():
|
|
|
+ # 数据不存在,lang表创建数据
|
|
|
+ Lang.objects.create(
|
|
|
+ lang=lang,
|
|
|
+ instruction=instruction,
|
|
|
+ quota=quota,
|
|
|
+ unit=unit,
|
|
|
+ remark=remark
|
|
|
+ )
|
|
|
+ lang_obj = Lang.objects.filter(
|
|
|
+ lang=lang,
|
|
|
+ instruction=instruction,
|
|
|
+ quota=quota,
|
|
|
+ unit=unit,
|
|
|
+ remark=remark
|
|
|
+ )
|
|
|
+ coupon_qs.lang.add(*lang_obj) # coupon_config表添加语言数据
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|