@@ -145,27 +145,14 @@ def decrypt(request, v='v2'): |
||
| 145 | 145 |
mdli.decrypt_count += 1 |
| 146 | 146 |
mdli.save() |
| 147 | 147 |
|
| 148 |
+ #弃用老版本的劵形式,和会员系统统一 |
|
| 148 | 149 |
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 |
|
| 151 |
- |
|
| 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 |
- } |
|
| 150 |
+ has_unexpired_activity = False |
|
| 151 |
+ coupon_infos = {}
|
|
| 159 | 152 |
|
| 160 | 153 |
else: |
| 161 | 154 |
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] |
|
| 155 |
+ coupon_infos = [act.coupon_info3 for act in activities if act and act.has_unexpired_activity(model.model_uni_name)] |
|
| 169 | 156 |
|
| 170 | 157 |
return response(200, data={
|
| 171 | 158 |
'plaintext': plaintext, |
@@ -182,8 +169,8 @@ def decrypt(request, v='v2'): |
||
| 182 | 169 |
'img': model.imgdata1 if model else '', |
| 183 | 170 |
'img2': model.imgdata if model else {},
|
| 184 | 171 |
}, |
| 185 |
- 'has_unexpired_activity': has_unexpired_activity, |
|
| 186 |
- 'coupon_info': coupon_info, |
|
| 172 |
+ 'has_unexpired_activity': False, |
|
| 173 |
+ 'coupon_infos': coupon_infos, |
|
| 187 | 174 |
}) |
| 188 | 175 |
|
| 189 | 176 |
|
@@ -253,26 +240,12 @@ def decrypt2(request, v='v2'): |
||
| 253 | 240 |
mdli.save() |
| 254 | 241 |
|
| 255 | 242 |
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 |
- } |
|
| 243 |
+ has_unexpired_activity = False |
|
| 244 |
+ coupon_infos = {}
|
|
| 266 | 245 |
|
| 267 | 246 |
else: |
| 268 | 247 |
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) |
|
| 271 |
- |
|
| 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] |
|
| 248 |
+ coupon_infos = [act.coupon_info3 for act in activities if act.has_unexpired_activity(model.model_uni_name)] |
|
| 276 | 249 |
|
| 277 | 250 |
return response(200, data={
|
| 278 | 251 |
'plaintext': plaintext, |
@@ -289,6 +262,6 @@ def decrypt2(request, v='v2'): |
||
| 289 | 262 |
'img': model.imgdata1 if model else '', |
| 290 | 263 |
'img2': model.imgdata if model else {},
|
| 291 | 264 |
}, |
| 292 |
- 'has_unexpired_activity': has_unexpired_activity, |
|
| 293 |
- 'coupon_info': coupon_info, |
|
| 265 |
+ 'has_unexpired_activity': False, |
|
| 266 |
+ 'coupon_infos': coupon_infos, |
|
| 294 | 267 |
}) |
@@ -10,12 +10,14 @@ from django_response import response |
||
| 10 | 10 |
from pywe_miniapp import get_phone_number |
| 11 | 11 |
from pywe_storage import RedisStorage |
| 12 | 12 |
from TimeConvert import TimeConvert as tc |
| 13 |
+import json |
|
| 13 | 14 |
|
| 14 | 15 |
from logs.models import MchInfoEncryptLogInfo |
| 15 | 16 |
from account.models import UserInfo |
| 16 | 17 |
from integral.models import SaleclerkSubmitLogInfo |
| 17 | 18 |
from mch.models import (ActivityInfo, AdministratorInfo, BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, |
| 18 | 19 |
LatestAppInfo, LatestAppScreenInfo, ModelInfo, OperatorInfo) |
| 20 |
+from coupon.models import CouponInfo, UserCouponInfo |
|
| 19 | 21 |
from statistic.models import ConsumeModelSaleStatisticInfo, ConsumeSaleStatisticInfo, ConsumeUserStatisticInfo |
| 20 | 22 |
from utils.error.errno_utils import (AdministratorStatusCode, OperatorStatusCode, ProductBrandStatusCode, |
| 21 | 23 |
ProductModelStatusCode, UserStatusCode) |
@@ -213,8 +215,6 @@ def consumer_phone_api(request): |
||
| 213 | 215 |
@transaction.atomic |
| 214 | 216 |
def consumer_info_api(request): |
| 215 | 217 |
user_id = request.POST.get('user_id', '')
|
| 216 |
- iv = request.POST.get('iv', '')
|
|
| 217 |
- encryptedData = request.POST.get('encryptedData', '')
|
|
| 218 | 218 |
lat = request.POST.get('lat', .0)
|
| 219 | 219 |
lon = request.POST.get('lon', .0)
|
| 220 | 220 |
brandID = request.POST.get('brand_id', '') or request.POST.get('BrandID', '')
|
@@ -222,26 +222,20 @@ def consumer_info_api(request): |
||
| 222 | 222 |
distributorID = request.POST.get('DistributorID', '')
|
| 223 | 223 |
serialNo = request.POST.get('SerialNo', '')
|
| 224 | 224 |
verifyResult = request.POST.get('verifyResult', 0)
|
| 225 |
- purePhoneNumber = request.POST.get('purePhoneNumber', '')
|
|
| 226 | 225 |
code_version = request.POST.get('code_version', '')
|
| 226 |
+ activities = json.loads(request.POST.get('activities', '[]'))
|
|
| 227 | 227 |
|
| 228 | 228 |
if lat == 'undefined': |
| 229 | 229 |
lat = .0 |
| 230 | 230 |
if lon == 'undefined': |
| 231 | 231 |
lon = .0 |
| 232 | 232 |
|
| 233 |
- purePhoneNumber = purePhoneNumber or getPhoneNumber(request) |
|
| 234 |
- |
|
| 235 | 233 |
# 校验用户是否存在 |
| 236 | 234 |
try: |
| 237 | 235 |
user = UserInfo.objects.get(user_id=user_id) |
| 238 | 236 |
except UserInfo.DoesNotExist: |
| 239 | 237 |
return response(UserStatusCode.USER_NOT_FOUND) |
| 240 | 238 |
|
| 241 |
- # 更新用户手机号 |
|
| 242 |
- user.phone = purePhoneNumber |
|
| 243 |
- user.save() |
|
| 244 |
- |
|
| 245 | 239 |
try: |
| 246 | 240 |
brand = BrandInfo.objects.get(brand_id=brandID) |
| 247 | 241 |
except BrandInfo.DoesNotExist: |
@@ -295,17 +289,41 @@ def consumer_info_api(request): |
||
| 295 | 289 |
act = None |
| 296 | 290 |
during_activity = False |
| 297 | 291 |
else: |
| 298 |
- act = ActivityInfo.objects.filter(status=True).order_by('-pk').first()
|
|
| 299 |
- during_activity = True if act and act.has_unexpired_activity(model.model_uni_name) else False |
|
| 292 |
+ for act in activities: |
|
| 293 |
+ try: |
|
| 294 |
+ coupon = CouponInfo.objects.get(coupon_id=act['coupon_id']) |
|
| 295 |
+ activity = ActivityInfo.objects.get(activity_id=act['activity_id']) |
|
| 296 |
+ UserCouponInfo.objects.create( |
|
| 297 |
+ brand_id=coupon.brand_id, |
|
| 298 |
+ brand_name=coupon.brand_name, |
|
| 299 |
+ coupon_id=coupon.coupon_id, |
|
| 300 |
+ user_id=user_id, |
|
| 301 |
+ coupon_title=coupon.coupon_title, |
|
| 302 |
+ coupon_detail=coupon.coupon_detail, |
|
| 303 |
+ coupon_value=coupon.coupon_value, |
|
| 304 |
+ coupon_image=coupon.coupon_image, |
|
| 305 |
+ active_at=tc.utc_datetime(), |
|
| 306 |
+ expire_at=coupon.final_expire_at, |
|
| 307 |
+ coupon_valid_period=coupon.coupon_valid_period, |
|
| 308 |
+ coupon_limit_model_ids=coupon.coupon_limit_model_ids, |
|
| 309 |
+ coupon_from='PROMOTION', |
|
| 310 |
+ activity_id=activity.activity_id, |
|
| 311 |
+ activity_name=activity.activity_name, |
|
| 312 |
+ ) |
|
| 313 |
+ except: |
|
| 314 |
+ continue |
|
| 315 |
+ |
|
| 316 |
+ # 更新销售员提交的表 |
|
| 317 |
+ logs = SaleclerkSubmitLogInfo.objects.filter(code=serialNo, model_pk=model.pk) |
|
| 318 |
+ for log in logs: |
|
| 319 |
+ log.has_scan = True |
|
| 320 |
+ log.save() |
|
| 300 | 321 |
|
| 301 | 322 |
ymd = tc.local_string(format='%Y%m%d') |
| 302 | 323 |
|
| 303 | 324 |
# 记录用户信息提交记录 |
| 304 | 325 |
log = ConsumeInfoSubmitLogInfo.objects.create( |
| 305 | 326 |
user_id=user_id, |
| 306 |
- phone=purePhoneNumber, |
|
| 307 |
- iv=iv, |
|
| 308 |
- encryptedData=encryptedData, |
|
| 309 | 327 |
lat=lat, |
| 310 | 328 |
lon=lon, |
| 311 | 329 |
brand_id=brand.brand_id, |
@@ -320,10 +338,6 @@ def consumer_info_api(request): |
||
| 320 | 338 |
serialNo=serialNo, |
| 321 | 339 |
verifyResult=verifyResult, |
| 322 | 340 |
dupload=dupload, |
| 323 |
- submit_during_activity=during_activity, |
|
| 324 |
- activity_id=act.pk if during_activity else 0, |
|
| 325 |
- coupon_expire_at=act.coupon_expire_at if during_activity else None, |
|
| 326 |
- coupon_value=act.coupon_value if during_activity else 0, |
|
| 327 | 341 |
test_user=user.test_user, |
| 328 | 342 |
code_version=code_version, |
| 329 | 343 |
ym=ymd[:6], |
@@ -417,12 +431,6 @@ def consumer_info_api(request): |
||
| 417 | 431 |
'model_id': model.model_id, |
| 418 | 432 |
}) |
| 419 | 433 |
|
| 420 |
- # 更新销售员提交的表 |
|
| 421 |
- logs = SaleclerkSubmitLogInfo.objects.filter(code=serialNo, model_pk=model.pk) |
|
| 422 |
- for log in logs: |
|
| 423 |
- log.has_scan = True |
|
| 424 |
- log.save() |
|
| 425 |
- |
|
| 426 | 434 |
if not dupload: |
| 427 | 435 |
user.shots_num += 1 |
| 428 | 436 |
if user.level < UserInfo.MEMBER_BLACK_GOLD: |
@@ -0,0 +1,30 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+# Generated by Django 1.11.26 on 2020-04-11 13:43 |
|
| 3 |
+from __future__ import unicode_literals |
|
| 4 |
+ |
|
| 5 |
+from django.db import migrations, models |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+class Migration(migrations.Migration): |
|
| 9 |
+ |
|
| 10 |
+ dependencies = [ |
|
| 11 |
+ ('coupon', '0007_auto_20191230_1605'),
|
|
| 12 |
+ ] |
|
| 13 |
+ |
|
| 14 |
+ operations = [ |
|
| 15 |
+ migrations.AddField( |
|
| 16 |
+ model_name='usercouponinfo', |
|
| 17 |
+ name='acitvity_id', |
|
| 18 |
+ field=models.CharField(blank=True, db_index=True, default=b'MEMBER_BENEFITS', help_text='\u6d3b\u52a8\u552f\u4e00\u6807\u8bc6', max_length=32, null=True, verbose_name='acitvity_id'), |
|
| 19 |
+ ), |
|
| 20 |
+ migrations.AddField( |
|
| 21 |
+ model_name='usercouponinfo', |
|
| 22 |
+ name='acitvity_name', |
|
| 23 |
+ field=models.CharField(blank=True, db_index=True, default=b'MEMBER_BENEFITS', help_text='\u6d3b\u52a8\u540d\u79f0', max_length=32, null=True, verbose_name='activity_id'), |
|
| 24 |
+ ), |
|
| 25 |
+ migrations.AddField( |
|
| 26 |
+ model_name='usercouponinfo', |
|
| 27 |
+ name='coupon_from', |
|
| 28 |
+ field=models.CharField(blank=True, db_index=True, default=b'MEMBER_BENEFITS', help_text='\u52b5\u6765\u6e90', max_length=32, null=True, verbose_name='coupon_from'), |
|
| 29 |
+ ), |
|
| 30 |
+ ] |
@@ -0,0 +1,25 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+# Generated by Django 1.11.26 on 2020-04-11 14:54 |
|
| 3 |
+from __future__ import unicode_literals |
|
| 4 |
+ |
|
| 5 |
+from django.db import migrations, models |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+class Migration(migrations.Migration): |
|
| 9 |
+ |
|
| 10 |
+ dependencies = [ |
|
| 11 |
+ ('coupon', '0008_auto_20200411_2143'),
|
|
| 12 |
+ ] |
|
| 13 |
+ |
|
| 14 |
+ operations = [ |
|
| 15 |
+ migrations.AlterField( |
|
| 16 |
+ model_name='usercouponinfo', |
|
| 17 |
+ name='acitvity_id', |
|
| 18 |
+ field=models.CharField(blank=True, db_index=True, help_text='\u6d3b\u52a8\u552f\u4e00\u6807\u8bc6', max_length=32, null=True, verbose_name='acitvity_id'), |
|
| 19 |
+ ), |
|
| 20 |
+ migrations.AlterField( |
|
| 21 |
+ model_name='usercouponinfo', |
|
| 22 |
+ name='acitvity_name', |
|
| 23 |
+ field=models.CharField(blank=True, db_index=True, help_text='\u6d3b\u52a8\u540d\u79f0', max_length=32, null=True, verbose_name='activity_id'), |
|
| 24 |
+ ), |
|
| 25 |
+ ] |
@@ -0,0 +1,20 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+# Generated by Django 1.11.26 on 2020-04-11 14:54 |
|
| 3 |
+from __future__ import unicode_literals |
|
| 4 |
+ |
|
| 5 |
+from django.db import migrations, models |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+class Migration(migrations.Migration): |
|
| 9 |
+ |
|
| 10 |
+ dependencies = [ |
|
| 11 |
+ ('coupon', '0009_auto_20200411_2254'),
|
|
| 12 |
+ ] |
|
| 13 |
+ |
|
| 14 |
+ operations = [ |
|
| 15 |
+ migrations.AlterField( |
|
| 16 |
+ model_name='usercouponinfo', |
|
| 17 |
+ name='acitvity_name', |
|
| 18 |
+ field=models.CharField(blank=True, db_index=True, help_text='\u6d3b\u52a8\u540d\u79f0', max_length=32, null=True, verbose_name='acitvity_name'), |
|
| 19 |
+ ), |
|
| 20 |
+ ] |
@@ -0,0 +1,33 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+# Generated by Django 1.11.26 on 2020-04-11 15:16 |
|
| 3 |
+from __future__ import unicode_literals |
|
| 4 |
+ |
|
| 5 |
+from django.db import migrations, models |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+class Migration(migrations.Migration): |
|
| 9 |
+ |
|
| 10 |
+ dependencies = [ |
|
| 11 |
+ ('coupon', '0010_auto_20200411_2254'),
|
|
| 12 |
+ ] |
|
| 13 |
+ |
|
| 14 |
+ operations = [ |
|
| 15 |
+ migrations.RemoveField( |
|
| 16 |
+ model_name='usercouponinfo', |
|
| 17 |
+ name='acitvity_id', |
|
| 18 |
+ ), |
|
| 19 |
+ migrations.RemoveField( |
|
| 20 |
+ model_name='usercouponinfo', |
|
| 21 |
+ name='acitvity_name', |
|
| 22 |
+ ), |
|
| 23 |
+ migrations.AddField( |
|
| 24 |
+ model_name='usercouponinfo', |
|
| 25 |
+ name='activity_id', |
|
| 26 |
+ field=models.CharField(blank=True, db_index=True, help_text='\u6d3b\u52a8\u552f\u4e00\u6807\u8bc6', max_length=32, null=True, verbose_name='activity_id'), |
|
| 27 |
+ ), |
|
| 28 |
+ migrations.AddField( |
|
| 29 |
+ model_name='usercouponinfo', |
|
| 30 |
+ name='activity_name', |
|
| 31 |
+ field=models.CharField(blank=True, db_index=True, help_text='\u6d3b\u52a8\u540d\u79f0', max_length=32, null=True, verbose_name='activity_name'), |
|
| 32 |
+ ), |
|
| 33 |
+ ] |
@@ -42,6 +42,21 @@ class CouponInfo(BaseModelMixin): |
||
| 42 | 42 |
def __unicode__(self): |
| 43 | 43 |
return unicode(self.pk) |
| 44 | 44 |
|
| 45 |
+ @property |
|
| 46 |
+ def coupon_image_path(self): |
|
| 47 |
+ return upload_file_path(self.coupon_image) |
|
| 48 |
+ |
|
| 49 |
+ @property |
|
| 50 |
+ def coupon_image_url(self): |
|
| 51 |
+ return upload_file_url(self.coupon_image) |
|
| 52 |
+ |
|
| 53 |
+ |
|
| 54 |
+ @property |
|
| 55 |
+ def final_expire_at(self): |
|
| 56 |
+ if self.coupon_expire_type == CouponInfo.FIXED_EXPIRED_TIME: |
|
| 57 |
+ return self.coupon_expire_at |
|
| 58 |
+ return tc.utc_datetime(days=self.coupon_valid_period) |
|
| 59 |
+ |
|
| 45 | 60 |
|
| 46 | 61 |
class UserCouponInfo(BaseModelMixin): |
| 47 | 62 |
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True) |
@@ -66,6 +81,10 @@ class UserCouponInfo(BaseModelMixin): |
||
| 66 | 81 |
admin_id = models.CharField(_(u'admin_id'), max_length=32, blank=True, null=True, help_text=u'核销员唯一标识', db_index=True) |
| 67 | 82 |
used_at = models.DateTimeField(_(u'used_at'), blank=True, null=True, help_text=u'维修券核销时间') |
| 68 | 83 |
|
| 84 |
+ coupon_from = models.CharField(_(u'coupon_from'), default='MEMBER_BENEFITS', max_length=32, blank=True, null=True, help_text=u'劵来源', db_index=True) |
|
| 85 |
+ activity_id = models.CharField(_(u'activity_id'), max_length=32, blank=True, null=True, help_text=u'活动唯一标识', db_index=True) |
|
| 86 |
+ activity_name = models.CharField(_(u'activity_name'), max_length=32, blank=True, null=True, help_text=u'活动名称', db_index=True) |
|
| 87 |
+ |
|
| 69 | 88 |
class Meta: |
| 70 | 89 |
verbose_name = _(u'用户券信息') |
| 71 | 90 |
verbose_name_plural = _(u'用户券信息') |
@@ -227,7 +227,7 @@ class ConsumeInfoSubmitLogInfoAdmin(ReadOnlyModelAdmin, admin.ModelAdmin): |
||
| 227 | 227 |
|
| 228 | 228 |
|
| 229 | 229 |
class ActivityInfoAdmin(admin.ModelAdmin): |
| 230 |
- list_display = ('activity_name', 'model_uni_names', 'start_at', 'end_at', 'coupon_expire_type', 'coupon_valid_period', 'coupon_expire_at', 'coupon_value', 'status', 'created_at', 'updated_at')
|
|
| 230 |
+ list_display = ('activity_id', 'activity_name', 'model_uni_names', 'start_at', 'end_at', 'coupon_expire_type', 'coupon_valid_period', 'coupon_expire_at', 'coupon_value', 'status', 'created_at', 'updated_at')
|
|
| 231 | 231 |
list_filter = ('coupon_expire_type', 'status')
|
| 232 | 232 |
|
| 233 | 233 |
|
@@ -0,0 +1,26 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+# Generated by Django 1.11.26 on 2020-04-11 13:43 |
|
| 3 |
+from __future__ import unicode_literals |
|
| 4 |
+ |
|
| 5 |
+from django.db import migrations, models |
|
| 6 |
+import shortuuidfield.fields |
|
| 7 |
+ |
|
| 8 |
+ |
|
| 9 |
+class Migration(migrations.Migration): |
|
| 10 |
+ |
|
| 11 |
+ dependencies = [ |
|
| 12 |
+ ('mch', '0053_auto_20200407_1118'),
|
|
| 13 |
+ ] |
|
| 14 |
+ |
|
| 15 |
+ operations = [ |
|
| 16 |
+ migrations.AddField( |
|
| 17 |
+ model_name='activityinfo', |
|
| 18 |
+ name='activity_id', |
|
| 19 |
+ field=shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u6d3b\u52a8\u552f\u4e00\u6807\u8bc6', max_length=22, null=True, unique=True), |
|
| 20 |
+ ), |
|
| 21 |
+ migrations.AlterField( |
|
| 22 |
+ model_name='consumeinfosubmitloginfo', |
|
| 23 |
+ name='province', |
|
| 24 |
+ field=models.CharField(blank=True, db_index=True, help_text='\u7701\u4efd', max_length=32, null=True, verbose_name='province'), |
|
| 25 |
+ ), |
|
| 26 |
+ ] |
@@ -9,6 +9,8 @@ from jsonfield import JSONField |
||
| 9 | 9 |
from shortuuidfield import ShortUUIDField |
| 10 | 10 |
from TimeConvert import TimeConvert as tc |
| 11 | 11 |
|
| 12 |
+from coupon.models import CouponInfo |
|
| 13 |
+ |
|
| 12 | 14 |
|
| 13 | 15 |
class AdministratorInfo(BaseModelMixin): |
| 14 | 16 |
ADMINISTRATOR = 0 |
@@ -704,6 +706,7 @@ class ActivityInfo(BaseModelMixin): |
||
| 704 | 706 |
(CHANGED_EXPIRED_TIME, u'可变结束时间'), |
| 705 | 707 |
) |
| 706 | 708 |
|
| 709 |
+ activity_id = ShortUUIDField(_(u'activity_id'), max_length=32, blank=True, null=True, help_text=u'活动唯一标识', db_index=True, unique=True) |
|
| 707 | 710 |
activity_name = models.CharField(_(u'activity_name'), max_length=255, blank=True, null=True, help_text=u'活动名称') |
| 708 | 711 |
|
| 709 | 712 |
model_uni_names = JSONField(_(u'model_uni_names'), default=[], blank=True, null=True, help_text=u'型号统一名称列表') |
@@ -740,7 +743,7 @@ class ActivityInfo(BaseModelMixin): |
||
| 740 | 743 |
return u'{}年{}月{}日'.format(y, m, d)
|
| 741 | 744 |
|
| 742 | 745 |
def has_unexpired_activity(self, model_name): |
| 743 |
- return (self.model_uni_names and model_name in self.model_uni_names) and (self.start_at <= tc.utc_datetime() < self.end_at) |
|
| 746 |
+ return ((self.model_uni_names and model_name in self.model_uni_names) or not self.model_uni_names) and (self.start_at <= tc.utc_datetime() < self.end_at) |
|
| 744 | 747 |
|
| 745 | 748 |
def coupon_info(self, created_at=None): |
| 746 | 749 |
return {
|
@@ -748,6 +751,25 @@ class ActivityInfo(BaseModelMixin): |
||
| 748 | 751 |
'coupon_value': self.coupon_value, |
| 749 | 752 |
'coupon_has_expired': tc.utc_datetime() >= self.final_expire_at(created_at=created_at), |
| 750 | 753 |
} |
| 754 |
+ |
|
| 751 | 755 |
|
| 752 | 756 |
def coupon_info2(self, created_at=None): |
| 753 | 757 |
return self.coupon_info(created_at=created_at), |
| 758 |
+ |
|
| 759 |
+ @property |
|
| 760 |
+ def coupon_info3(self): |
|
| 761 |
+ try: |
|
| 762 |
+ coupon_info = CouponInfo.objects.get(coupon_id=self.coupon_id) |
|
| 763 |
+ return {
|
|
| 764 |
+ 'coupon_image': coupon_info.coupon_image_url, |
|
| 765 |
+ 'coupon_expire_at': coupon_info.coupon_expire_at, |
|
| 766 |
+ 'coupon_value': coupon_info.coupon_value, |
|
| 767 |
+ 'coupon_title': coupon_info.coupon_title, |
|
| 768 |
+ 'coupon_valid_period': coupon_info.coupon_valid_period, |
|
| 769 |
+ 'coupon_id': coupon_info.coupon_id, |
|
| 770 |
+ 'activity_id': self.activity_id, |
|
| 771 |
+ 'activity_name': self.activity_name, |
|
| 772 |
+ } |
|
| 773 |
+ except: |
|
| 774 |
+ return {}
|
|
| 775 |
+ |