|
@@ -0,0 +1,58 @@
|
|
|
+# -*- encoding: utf-8 -*-
|
|
|
+"""
|
|
|
+@File : CloudServiceController.py
|
|
|
+@Time : 2022/12/8 10:23
|
|
|
+@Author : stephen
|
|
|
+@Email : zhangdongming@asj6.wecom.work
|
|
|
+@Software: PyCharm
|
|
|
+"""
|
|
|
+from django.views import View
|
|
|
+
|
|
|
+from Model.models import CouponCombo
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+
|
|
|
+
|
|
|
+class CloudServiceController(View):
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
+
|
|
|
+ def validation(self, request_dict, request, operation):
|
|
|
+ token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
|
+ lang = request_dict.get('lang', token.lang)
|
|
|
+ response = ResponseObject(lang)
|
|
|
+ if token.code != 0:
|
|
|
+ return response.json(token.code)
|
|
|
+ user_id = token.userID
|
|
|
+ if operation == 'save-photo':
|
|
|
+ return self.get_combo_list_by_coupon(user_id, response)
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def get_combo_list_by_coupon(cls, request_dict, response):
|
|
|
+ """
|
|
|
+ 根据优惠券获取套餐列表
|
|
|
+ @param request_dict: couponId 优惠券ID
|
|
|
+ @param request_dict: couponType 优惠券类型
|
|
|
+ @param response: 响应结果
|
|
|
+ """
|
|
|
+ coupon_id = int(request_dict.get('couponId', 0))
|
|
|
+ coupon_type = int(request_dict.get('couponType', 0))
|
|
|
+ if coupon_id == 0:
|
|
|
+ return response.json(444)
|
|
|
+ coupon_combo_qs = CouponCombo.objects.filter(coupon_type=coupon_type, coupon_id=coupon_id).values('combo_id')
|
|
|
+ combo_list = []
|
|
|
+ if not coupon_combo_qs.exists():
|
|
|
+ return combo_list
|
|
|
+ for item in coupon_combo_qs:
|
|
|
+ combo_list.append(item['combo_id'])
|
|
|
+ return combo_list
|