|
@@ -123,6 +123,8 @@ class serveManagement(View):
|
|
return self.addOrEditCouponLang(request_dict, response)
|
|
return self.addOrEditCouponLang(request_dict, response)
|
|
elif operation == 'deleteCouponLang': # 删除优惠券语言
|
|
elif operation == 'deleteCouponLang': # 删除优惠券语言
|
|
return self.deleteCouponLang(request_dict, response)
|
|
return self.deleteCouponLang(request_dict, response)
|
|
|
|
+ elif operation == 'addCouponLangConfig': # 添加优惠券语言
|
|
|
|
+ return self.add_coupon_lang_config(request_dict, response)
|
|
|
|
|
|
# 优惠券使用
|
|
# 优惠券使用
|
|
elif operation == 'getCouponUsingList': # 查询优惠券使用
|
|
elif operation == 'getCouponUsingList': # 查询优惠券使用
|
|
@@ -1030,6 +1032,58 @@ class serveManagement(View):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def add_coupon_lang_config(request_dict, response):
|
|
|
|
+ coupon_id = request_dict.get('couponID')
|
|
|
|
+ lang_configs = request_dict.get('langConfig')
|
|
|
|
+
|
|
|
|
+ # 校验 coupon_id 和 langConfig 是否存在
|
|
|
|
+ if not coupon_id or not lang_configs:
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ # 解析 langConfig 字段
|
|
|
|
+ lang_configs = json.loads(lang_configs)
|
|
|
|
+ coupon = CouponConfigModel.objects.filter(id=coupon_id).first()
|
|
|
|
+
|
|
|
|
+ if not coupon:
|
|
|
|
+ return response.json(173)
|
|
|
|
+
|
|
|
|
+ # 先查询所有现有的语言配置
|
|
|
|
+ existing_langs = {lang.lang: lang for lang in coupon.lang.all()}
|
|
|
|
+
|
|
|
|
+ for lang_config in lang_configs:
|
|
|
|
+ lang = lang_config.get("lang")
|
|
|
|
+ if not lang:
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ if lang in existing_langs:
|
|
|
|
+ # 更新已有的语言配置
|
|
|
|
+ lang_obj = existing_langs[lang]
|
|
|
|
+ lang_obj.instruction = lang_config.get("instruction")
|
|
|
|
+ lang_obj.quota = lang_config.get("quota")
|
|
|
|
+ lang_obj.unit = lang_config.get("unit")
|
|
|
|
+ lang_obj.remark = lang_config.get("remark")
|
|
|
|
+ lang_obj.save() # 使用 save() 方法保存更改
|
|
|
|
+ else:
|
|
|
|
+ # 创建新的语言配置
|
|
|
|
+ coupon_lang = CouponLang(
|
|
|
|
+ lang=lang,
|
|
|
|
+ instruction=lang_config.get("instruction"),
|
|
|
|
+ quota=lang_config.get("quota"),
|
|
|
|
+ unit=lang_config.get("unit"),
|
|
|
|
+ remark=lang_config.get("remark")
|
|
|
|
+ )
|
|
|
|
+ coupon_lang.save() # 使用 save() 方法保存新配置
|
|
|
|
+ coupon.lang.add(coupon_lang) # 添加到 coupon 的 lang 关联
|
|
|
|
+
|
|
|
|
+ return response.json(0)
|
|
|
|
+
|
|
|
|
+ except json.JSONDecodeError as e:
|
|
|
|
+ return response.json(500, f"JSON Decode Error: {repr(e)}")
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response.json(500, f"error_line: {e.__traceback__.tb_lineno}, error_msg: {repr(e)}")
|
|
|
|
+
|
|
@staticmethod
|
|
@staticmethod
|
|
def getCouponUsingList(request_dict, response):
|
|
def getCouponUsingList(request_dict, response):
|
|
username = request_dict.get('username', None)
|
|
username = request_dict.get('username', None)
|