|
@@ -0,0 +1,53 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+import base64
|
|
|
+import json
|
|
|
+import os
|
|
|
+import time
|
|
|
+from django.views.generic.base import View
|
|
|
+from Model.models import CouponModel
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+from django.db.models import Q, F, Count
|
|
|
+
|
|
|
+
|
|
|
+# 优惠券
|
|
|
+class CouponView(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):
|
|
|
+ response = ResponseObject()
|
|
|
+ if operation is None:
|
|
|
+ return response.json(444, 'error path')
|
|
|
+
|
|
|
+ else:
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if operation == 'UserCoupon': #用户优惠券
|
|
|
+ return self.query_user_coupon(request_dict, userID, response)
|
|
|
+ else:
|
|
|
+ return response.json(414)
|
|
|
+
|
|
|
+ def query_user_coupon(self, request_dict, userID, response): #用户优惠券列表
|
|
|
+ nowTime = int(time.time())
|
|
|
+ couponObj = CouponModel.objects.filter(userID_id=userID,use_status=0,distributeTime__lte=nowTime,
|
|
|
+ valid_time__gt=nowTime).annotate(coupon_id=F('id')).values(
|
|
|
+ "coupon_id","type","coupon_discount")
|
|
|
+ result = {
|
|
|
+ 'count':couponObj.count(),
|
|
|
+ 'couponList':list(couponObj),
|
|
|
+ }
|
|
|
+ return response.json(0, result)
|