@@ -103,7 +103,7 @@ def encrypt(request): |
||
| 103 | 103 |
|
| 104 | 104 |
|
| 105 | 105 |
@logit(res=True) |
| 106 |
-def decrypt(request): |
|
| 106 |
+def decrypt(request, v='v2'): |
|
| 107 | 107 |
ciphertext = request.POST.get('ciphertext', '')
|
| 108 | 108 |
|
| 109 | 109 |
prefix, cipherlen, ciphertext = ciphertext.split('+', 2)
|
@@ -145,16 +145,27 @@ def decrypt(request): |
||
| 145 | 145 |
mdli.decrypt_count += 1 |
| 146 | 146 |
mdli.save() |
| 147 | 147 |
|
| 148 |
- act = ActivityInfo.objects.filter(status=True).order_by('-pk').first()
|
|
| 149 |
- has_unexpired_activity = True if act and act.has_unexpired_activity(model.model_uni_name) else False |
|
| 148 |
+ if v == 'v1': |
|
| 149 |
+ act = ActivityInfo.objects.filter(status=True).order_by('-pk').first()
|
|
| 150 |
+ has_unexpired_activity = True if act and act.has_unexpired_activity(model.model_uni_name) else False |
|
| 150 | 151 |
|
| 151 |
- coupon_info = {
|
|
| 152 |
- 'coupon_expire_at': act.final_coupon_expire_at(created_at=None), |
|
| 153 |
- 'coupon_value': act.coupon_value, |
|
| 154 |
- } if has_unexpired_activity else {
|
|
| 155 |
- 'coupon_expire_at': '', |
|
| 156 |
- 'coupon_value': 0, |
|
| 157 |
- } |
|
| 152 |
+ coupon_info = {
|
|
| 153 |
+ 'coupon_expire_at': act.final_coupon_expire_at(created_at=None), |
|
| 154 |
+ 'coupon_value': act.coupon_value, |
|
| 155 |
+ } if has_unexpired_activity else {
|
|
| 156 |
+ 'coupon_expire_at': '', |
|
| 157 |
+ 'coupon_value': 0, |
|
| 158 |
+ } |
|
| 159 |
+ |
|
| 160 |
+ else: |
|
| 161 |
+ activities = ActivityInfo.objects.filter(status=True).order_by('-pk')
|
|
| 162 |
+ unexpired_activities = [True if act and act.has_unexpired_activity(model.model_uni_name) else False for act in activities] |
|
| 163 |
+ has_unexpired_activity = any(unexpired_activities) |
|
| 164 |
+ |
|
| 165 |
+ coupon_info = [{
|
|
| 166 |
+ 'coupon_expire_at': act.final_coupon_expire_at(created_at=None), |
|
| 167 |
+ 'coupon_value': act.coupon_value, |
|
| 168 |
+ } for act in unexpired_activities] |
|
| 158 | 169 |
|
| 159 | 170 |
return response(200, data={
|
| 160 | 171 |
'plaintext': plaintext, |
@@ -168,8 +179,8 @@ def decrypt(request): |
||
| 168 | 179 |
'Model': (model.model_full_name or model.model_name) if model else '', |
| 169 | 180 |
'DistributorID': distributor_pk, |
| 170 | 181 |
'SerialNo': sn, |
| 171 |
- 'img': model.imgdata1, |
|
| 172 |
- 'img2': model.imgdata |
|
| 182 |
+ 'img': model.imgdata1 if model else '', |
|
| 183 |
+ 'img2': model.imgdata if model else {},
|
|
| 173 | 184 |
}, |
| 174 | 185 |
'has_unexpired_activity': has_unexpired_activity, |
| 175 | 186 |
'coupon_info': coupon_info, |
@@ -177,7 +188,7 @@ def decrypt(request): |
||
| 177 | 188 |
|
| 178 | 189 |
|
| 179 | 190 |
@logit(res=True) |
| 180 |
-def decrypt2(request): |
|
| 191 |
+def decrypt2(request, v='v2'): |
|
| 181 | 192 |
code_ticket = request.POST.get('code_ticket', '')
|
| 182 | 193 |
code = request.POST.get('code', '')
|
| 183 | 194 |
user_id = request.POST.get('user_id', '')
|
@@ -241,16 +252,27 @@ def decrypt2(request): |
||
| 241 | 252 |
mdli.decrypt_count += 1 |
| 242 | 253 |
mdli.save() |
| 243 | 254 |
|
| 244 |
- act = ActivityInfo.objects.filter(status=True).order_by('-pk').first()
|
|
| 245 |
- has_unexpired_activity = True if act and act.has_unexpired_activity(model.model_uni_name) else False |
|
| 255 |
+ if v == 'v1': |
|
| 256 |
+ act = ActivityInfo.objects.filter(status=True).order_by('-pk').first()
|
|
| 257 |
+ has_unexpired_activity = True if act and act.has_unexpired_activity(model.model_uni_name) else False |
|
| 258 |
+ |
|
| 259 |
+ coupon_info = {
|
|
| 260 |
+ 'coupon_expire_at': act.final_coupon_expire_at(created_at=None), |
|
| 261 |
+ 'coupon_value': act.coupon_value, |
|
| 262 |
+ } if has_unexpired_activity else {
|
|
| 263 |
+ 'coupon_expire_at': '', |
|
| 264 |
+ 'coupon_value': 0, |
|
| 265 |
+ } |
|
| 266 |
+ |
|
| 267 |
+ else: |
|
| 268 |
+ activities = ActivityInfo.objects.filter(status=True).order_by('-pk')
|
|
| 269 |
+ unexpired_activities = [True if act and act.has_unexpired_activity(model.model_uni_name) else False for act in activities] |
|
| 270 |
+ has_unexpired_activity = any(unexpired_activities) |
|
| 246 | 271 |
|
| 247 |
- coupon_info = {
|
|
| 248 |
- 'coupon_expire_at': act.final_coupon_expire_at(created_at=None), |
|
| 249 |
- 'coupon_value': act.coupon_value, |
|
| 250 |
- } if has_unexpired_activity else {
|
|
| 251 |
- 'coupon_expire_at': '', |
|
| 252 |
- 'coupon_value': 0, |
|
| 253 |
- } |
|
| 272 |
+ coupon_info = [{
|
|
| 273 |
+ 'coupon_expire_at': act.final_coupon_expire_at(created_at=None), |
|
| 274 |
+ 'coupon_value': act.coupon_value, |
|
| 275 |
+ } for act in unexpired_activities] |
|
| 254 | 276 |
|
| 255 | 277 |
return response(200, data={
|
| 256 | 278 |
'plaintext': plaintext, |
@@ -264,8 +286,8 @@ def decrypt2(request): |
||
| 264 | 286 |
'Model': (model.model_full_name or model.model_name) if model else '', |
| 265 | 287 |
'DistributorID': distributor_pk, |
| 266 | 288 |
'SerialNo': sn, |
| 267 |
- 'img': model.imgdata1, |
|
| 268 |
- 'img2': model.imgdata |
|
| 289 |
+ 'img': model.imgdata1 if model else '', |
|
| 290 |
+ 'img2': model.imgdata if model else {},
|
|
| 269 | 291 |
}, |
| 270 | 292 |
'has_unexpired_activity': has_unexpired_activity, |
| 271 | 293 |
'coupon_info': coupon_info, |
@@ -208,8 +208,10 @@ urlpatterns += [ |
||
| 208 | 208 |
|
| 209 | 209 |
urlpatterns += [ |
| 210 | 210 |
url(r'^encrypt$', encrypt_views.encrypt, name='encrypt'), |
| 211 |
- url(r'^decrypt$', encrypt_views.decrypt, name='decrypt'), |
|
| 212 |
- url(r'^decrypt2$', encrypt_views.decrypt2, name='decrypt2'), |
|
| 211 |
+ url(r'^decrypt$', encrypt_views.decrypt, {'v': 'v1'}, name='decrypt'),
|
|
| 212 |
+ url(r'^decrypt2$', encrypt_views.decrypt2, {'v': 'v1'}, name='decrypt2'),
|
|
| 213 |
+ url(r'^v2/decrypt$', encrypt_views.decrypt, {'v': 'v2'}, name='decrypt'),
|
|
| 214 |
+ url(r'^v2/decrypt2$', encrypt_views.decrypt2, {'v': 'v2'}, name='decrypt2'),
|
|
| 213 | 215 |
] |
| 214 | 216 |
|
| 215 | 217 |
urlpatterns += [ |