| @@ -0,0 +1,33 @@ | ||
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | + | |
| 3 | +from django.contrib import admin | |
| 4 | + | |
| 5 | +from coupon.models import CouponInfo | |
| 6 | +from mch.models import ActivityInfo | |
| 7 | +from member.models import RightInfo | |
| 8 | + | |
| 9 | + | |
| 10 | +class CouponInfoAdmin(admin.ModelAdmin): | |
| 11 | +    list_display = ('coupon_id', 'coupon_expire_type', 'coupon_valid_period', 'coupon_expire_at', 'coupon_value', 'coupon_num', 'coupon_level1_amount', 'coupon_level2_amount', 'coupon_level3_amount', 'coupon_level4_amount', 'coupon_level5_amount', 'coupon_detail', 'status', 'created_at', 'updated_at') | |
| 12 | +    readonly_fields = ('coupon_id', 'created_at', 'updated_at') | |
| 13 | + fieldsets = ( | |
| 14 | +        (u'', { | |
| 15 | +            'fields': ('coupon_id', 'status', 'created_at', 'updated_at') | |
| 16 | + }), | |
| 17 | +        (u'活动券信息', { | |
| 18 | +            'classes': ('collapse', ), | |
| 19 | +            'fields': ('coupon_expire_type', 'coupon_valid_period', 'coupon_expire_at', 'coupon_value') | |
| 20 | + }), | |
| 21 | +        (u'会员券信息', { | |
| 22 | +            'classes': ('collapse', ), | |
| 23 | +            'fields': ('coupon_num', 'coupon_level1_amount', 'coupon_level2_amount', 'coupon_level3_amount', 'coupon_level4_amount', 'coupon_level5_amount', 'coupon_detail') | |
| 24 | + }), | |
| 25 | + ) | |
| 26 | + | |
| 27 | + def save_model(self, request, obj, form, change): | |
| 28 | + obj.save() | |
| 29 | + | |
| 30 | + # TODO: Update ActivityInfo/RightInfo | |
| 31 | + | |
| 32 | + | |
| 33 | +admin.site.register(CouponInfo, CouponInfoAdmin) | 
| @@ -0,0 +1,8 @@ | ||
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +from __future__ import unicode_literals | |
| 3 | + | |
| 4 | +from django.apps import AppConfig | |
| 5 | + | |
| 6 | + | |
| 7 | +class CouponConfig(AppConfig): | |
| 8 | + name = 'coupon' | 
| @@ -0,0 +1,43 @@ | ||
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +# Generated by Django 1.11.26 on 2019-12-21 06:19 | |
| 3 | +from __future__ import unicode_literals | |
| 4 | + | |
| 5 | +from django.db import migrations, models | |
| 6 | +import shortuuidfield.fields | |
| 7 | +import simditor.fields | |
| 8 | + | |
| 9 | + | |
| 10 | +class Migration(migrations.Migration): | |
| 11 | + | |
| 12 | + initial = True | |
| 13 | + | |
| 14 | + dependencies = [ | |
| 15 | + ] | |
| 16 | + | |
| 17 | + operations = [ | |
| 18 | + migrations.CreateModel( | |
| 19 | + name='CouponInfo', | |
| 20 | + fields=[ | |
| 21 | +                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | |
| 22 | +                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')), | |
| 23 | +                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')), | |
| 24 | +                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')), | |
| 25 | +                ('coupon_id', shortuuidfield.fields.ShortUUIDField(blank=True, db_index=True, editable=False, help_text='\u5238\u552f\u4e00\u6807\u8bc6', max_length=22, null=True, unique=True)), | |
| 26 | +                ('coupon_expire_type', models.IntegerField(choices=[(0, '\u56fa\u5b9a\u7ed3\u675f\u65f6\u95f4'), (1, '\u53ef\u53d8\u7ed3\u675f\u65f6\u95f4')], default=0, help_text='\u7ef4\u4fee\u5238\u7c7b\u578b', verbose_name='coupon_expire_type')), | |
| 27 | +                ('coupon_valid_period', models.IntegerField(default=0, help_text='\u7ef4\u4fee\u5238\u6709\u6548\u65f6\u95f4\uff08\u5355\u4f4d\uff1a\u5929\uff09', verbose_name='coupon_valid_period')), | |
| 28 | +                ('coupon_expire_at', models.DateTimeField(blank=True, help_text='\u7ef4\u4fee\u5238\u8fc7\u671f\u65f6\u95f4', null=True, verbose_name='coupon_expire_at')), | |
| 29 | +                ('coupon_value', models.IntegerField(default=0, help_text='\u7ef4\u4fee\u5238\u91d1\u989d\uff08\u5355\u4f4d\uff1a\u5206\uff09', verbose_name='coupon_value')), | |
| 30 | +                ('coupon_num', models.IntegerField(default=0, help_text='\u5238\u6bcf\u4f1a\u5458\u7ea7\u522b\u53d1\u653e\u5f20\u6570', verbose_name='coupon_num')), | |
| 31 | +                ('coupon_level1_amount', models.IntegerField(blank=True, default=0, help_text='\u91d1\u989d\uff08\u5355\u4f4d\uff1a\u5206\uff09', null=True, verbose_name='coupon_level1_amount')), | |
| 32 | +                ('coupon_level2_amount', models.IntegerField(blank=True, default=0, help_text='\u91d1\u989d\uff08\u5355\u4f4d\uff1a\u5206\uff09', null=True, verbose_name='coupon_level2_amount')), | |
| 33 | +                ('coupon_level3_amount', models.IntegerField(blank=True, default=0, help_text='\u91d1\u989d\uff08\u5355\u4f4d\uff1a\u5206\uff09', null=True, verbose_name='coupon_level3_amount')), | |
| 34 | +                ('coupon_level4_amount', models.IntegerField(blank=True, default=0, help_text='\u91d1\u989d\uff08\u5355\u4f4d\uff1a\u5206\uff09', null=True, verbose_name='coupon_level4_amount')), | |
| 35 | +                ('coupon_level5_amount', models.IntegerField(blank=True, default=0, help_text='\u91d1\u989d\uff08\u5355\u4f4d\uff1a\u5206\uff09', null=True, verbose_name='coupon_level5_amount')), | |
| 36 | +                ('coupon_detail', simditor.fields.RichTextField(blank=True, help_text='\u5238\u8be6\u60c5', null=True, verbose_name='coupon_detail')), | |
| 37 | + ], | |
| 38 | +            options={ | |
| 39 | + 'verbose_name': '\u5238\u4fe1\u606f', | |
| 40 | + 'verbose_name_plural': '\u5238\u4fe1\u606f', | |
| 41 | + }, | |
| 42 | + ), | |
| 43 | + ] | 
| @@ -0,0 +1,42 @@ | ||
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | + | |
| 3 | +from django.db import models | |
| 4 | +from django.utils.translation import ugettext_lazy as _ | |
| 5 | +from django_models_ext import BaseModelMixin | |
| 6 | +from shortuuidfield import ShortUUIDField | |
| 7 | + | |
| 8 | +from simditor.fields import RichTextField | |
| 9 | + | |
| 10 | + | |
| 11 | +class CouponInfo(BaseModelMixin): | |
| 12 | + FIXED_EXPIRED_TIME = 0 | |
| 13 | + CHANGED_EXPIRED_TIME = 1 | |
| 14 | + | |
| 15 | + COUPON_EXPIRED_TIME_TUPLE = ( | |
| 16 | + (FIXED_EXPIRED_TIME, u'固定结束时间'), | |
| 17 | + (CHANGED_EXPIRED_TIME, u'可变结束时间'), | |
| 18 | + ) | |
| 19 | + | |
| 20 | + coupon_id = ShortUUIDField(_(u'coupon_id'), max_length=32, blank=True, null=True, help_text=u'券唯一标识', db_index=True, unique=True) | |
| 21 | + | |
| 22 | + # 活动券信息 | |
| 23 | + coupon_expire_type = models.IntegerField(_(u'coupon_expire_type'), choices=COUPON_EXPIRED_TIME_TUPLE, default=FIXED_EXPIRED_TIME, help_text=_(u'维修券类型')) | |
| 24 | + coupon_valid_period = models.IntegerField(_(u'coupon_valid_period'), default=0, help_text=_(u'维修券有效时间(单位:天)')) | |
| 25 | + coupon_expire_at = models.DateTimeField(_(u'coupon_expire_at'), blank=True, null=True, help_text=_(u'维修券过期时间')) | |
| 26 | + coupon_value = models.IntegerField(_(u'coupon_value'), default=0, help_text=_(u'维修券金额(单位:分)')) | |
| 27 | + | |
| 28 | + # 会员券信息 | |
| 29 | + coupon_num = models.IntegerField(_(u'coupon_num'), default=0, help_text=_(u'券每会员级别发放张数')) | |
| 30 | + coupon_level1_amount = models.IntegerField(_(u'coupon_level1_amount'), default=0, blank=True, null=True, help_text=u'金额(单位:分)') | |
| 31 | + coupon_level2_amount = models.IntegerField(_(u'coupon_level2_amount'), default=0, blank=True, null=True, help_text=u'金额(单位:分)') | |
| 32 | + coupon_level3_amount = models.IntegerField(_(u'coupon_level3_amount'), default=0, blank=True, null=True, help_text=u'金额(单位:分)') | |
| 33 | + coupon_level4_amount = models.IntegerField(_(u'coupon_level4_amount'), default=0, blank=True, null=True, help_text=u'金额(单位:分)') | |
| 34 | + coupon_level5_amount = models.IntegerField(_(u'coupon_level5_amount'), default=0, blank=True, null=True, help_text=u'金额(单位:分)') | |
| 35 | + coupon_detail = RichTextField(_(u'coupon_detail'), blank=True, null=True, help_text=u'券详情') | |
| 36 | + | |
| 37 | + class Meta: | |
| 38 | + verbose_name = _(u'券信息') | |
| 39 | + verbose_name_plural = _(u'券信息') | |
| 40 | + | |
| 41 | + def __unicode__(self): | |
| 42 | + return unicode(self.pk) | 
| @@ -0,0 +1,6 @@ | ||
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +from __future__ import unicode_literals | |
| 3 | + | |
| 4 | +from django.test import TestCase | |
| 5 | + | |
| 6 | +# Create your tests here. | 
| @@ -0,0 +1,6 @@ | ||
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +from __future__ import unicode_literals | |
| 3 | + | |
| 4 | +from django.shortcuts import render | |
| 5 | + | |
| 6 | +# Create your views here. | 
| @@ -54,6 +54,7 @@ INSTALLED_APPS = ( | ||
| 54 | 54 | 'account', | 
| 55 | 55 | 'box', | 
| 56 | 56 | 'commands', | 
| 57 | + 'coupon', | |
| 57 | 58 | 'group', | 
| 58 | 59 | 'guideline', | 
| 59 | 60 | 'integral', | 
| @@ -196,6 +196,11 @@ class ActivityInfoAdmin(admin.ModelAdmin): | ||
| 196 | 196 |      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') | 
| 197 | 197 |      list_filter = ('coupon_expire_type', 'status') | 
| 198 | 198 |  | 
| 199 | + def save_model(self, request, obj, form, change): | |
| 200 | + obj.save() | |
| 201 | + | |
| 202 | + # TODO: Update coupon relative | |
| 203 | + | |
| 199 | 204 |  | 
| 200 | 205 | admin.site.register(AdministratorInfo, AdministratorInfoAdmin) | 
| 201 | 206 | admin.site.register(OperatorInfo, OperatorInfoAdmin) | 
| @@ -0,0 +1,20 @@ | ||
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +# Generated by Django 1.11.26 on 2019-12-21 06:19 | |
| 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 | +        ('mch', '0040_modelinfo_shot_member_name'), | |
| 12 | + ] | |
| 13 | + | |
| 14 | + operations = [ | |
| 15 | + migrations.AddField( | |
| 16 | + model_name='activityinfo', | |
| 17 | + name='coupon_id', | |
| 18 | + field=models.CharField(blank=True, db_index=True, help_text='\u5238\u552f\u4e00\u6807\u8bc6', max_length=32, null=True, verbose_name='coupon_id'), | |
| 19 | + ), | |
| 20 | + ] | 
| @@ -615,6 +615,8 @@ class ActivityInfo(BaseModelMixin): | ||
| 615 | 615 | start_at = models.DateTimeField(_(u'start_at'), help_text=_(u'start_at')) | 
| 616 | 616 | end_at = models.DateTimeField(_(u'end_at'), help_text=_(u'end_at')) | 
| 617 | 617 |  | 
| 618 | + coupon_id = models.CharField(_(u'coupon_id'), max_length=32, blank=True, null=True, help_text=u'券唯一标识', db_index=True) | |
| 619 | + | |
| 618 | 620 | coupon_expire_type = models.IntegerField(_(u'coupon_expire_type'), choices=COUPON_EXPIRED_TIME_TUPLE, default=FIXED_EXPIRED_TIME, help_text=_(u'维修券类型')) | 
| 619 | 621 | coupon_valid_period = models.IntegerField(_(u'coupon_valid_period'), default=0, help_text=_(u'维修券有效时间(单位:天)')) | 
| 620 | 622 | coupon_expire_at = models.DateTimeField(_(u'coupon_expire_at'), blank=True, null=True, help_text=_(u'维修券过期时间')) | 
| @@ -30,6 +30,11 @@ class RightInfoAdmin(admin.ModelAdmin): | ||
| 30 | 30 |      list_display = ('right_id', 'right_type', 'icon', 'title', 'subtitle', 'detail', 'level1', 'level2', 'level3', 'level4', 'level5', 'minlevel', 'position', 'is_send_coupon', 'coupon_valid_period', 'coupon_num', 'status', 'created_at', 'updated_at') | 
| 31 | 31 |      list_filter = ('right_type', 'is_send_coupon', 'status') | 
| 32 | 32 |  | 
| 33 | + def save_model(self, request, obj, form, change): | |
| 34 | + obj.save() | |
| 35 | + | |
| 36 | + # TODO: Update coupon relative | |
| 37 | + | |
| 33 | 38 |  | 
| 34 | 39 | class CouponInfoAdmin(admin.ModelAdmin): | 
| 35 | 40 |      list_display = ('coupon_id', 'user_id', 'coupon_valid_period', 'coupon_amount', 'coupon_detail', 'active_at', 'expire_at', 'right_id', 'right_type', 'icon', 'title', 'subtitle', 'detail', 'status', 'created_at', 'updated_at') | 
| @@ -0,0 +1,23 @@ | ||
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +# Generated by Django 1.11.26 on 2019-12-21 06:19 | |
| 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 | +        ('member', '0011_auto_20191212_1827'), | |
| 12 | + ] | |
| 13 | + | |
| 14 | + operations = [ | |
| 15 | + migrations.DeleteModel( | |
| 16 | + name='MemberCouponInfo', | |
| 17 | + ), | |
| 18 | + migrations.AddField( | |
| 19 | + model_name='rightinfo', | |
| 20 | + name='coupon_id', | |
| 21 | + field=models.CharField(blank=True, db_index=True, help_text='\u5238\u552f\u4e00\u6807\u8bc6', max_length=32, null=True, verbose_name='coupon_id'), | |
| 22 | + ), | |
| 23 | + ] | 
| @@ -92,6 +92,7 @@ class GoodsInfo(BaseModelMixin): | ||
| 92 | 92 | 'desc': self.desc, | 
| 93 | 93 | } | 
| 94 | 94 |  | 
| 95 | + | |
| 95 | 96 | class GoodsOrderInfo(BaseModelMixin): | 
| 96 | 97 | PHYSICAL = 0 | 
| 97 | 98 | VIRTUAL = 1 | 
| @@ -163,6 +164,9 @@ class RightInfo(BaseModelMixin): | ||
| 163 | 164 |  | 
| 164 | 165 | # 券相关 | 
| 165 | 166 | is_send_coupon = models.BooleanField(_(u'is_send_coupon'), default=False, help_text=_(u'是否发券'), db_index=True) | 
| 167 | + | |
| 168 | + coupon_id = models.CharField(_(u'coupon_id'), max_length=32, blank=True, null=True, help_text=u'券唯一标识', db_index=True) | |
| 169 | + | |
| 166 | 170 | coupon_valid_period = models.IntegerField(_(u'coupon_valid_period'), default=0, help_text=_(u'券有效时间(单位:天)')) | 
| 167 | 171 | coupon_num = models.IntegerField(_(u'coupon_num'), default=0, help_text=_(u'券每会员级别发放张数')) | 
| 168 | 172 | coupon_level1_amount = models.IntegerField(_(u'coupon_level1_amount'), default=0, blank=True, null=True, help_text=u'金额(单位:分)') | 
| @@ -476,55 +480,3 @@ class MemberActivitySigninInfo(BaseModelMixin): | ||
| 476 | 480 |  | 
| 477 | 481 | def __unicode__(self): | 
| 478 | 482 | return unicode(self.pk) | 
| 479 | - | |
| 480 | - | |
| 481 | -class MemberCouponInfo(BaseModelMixin): | |
| 482 | - DEEP_CLEANING = 0 | |
| 483 | - FREE_FOCUS = 1 | |
| 484 | - CLEAN_APPEARANCE = 2 | |
| 485 | - ACCIDENTAL_MAINTENANCE = 3 | |
| 486 | - MAINTENANCE_MANPOWER = 4 | |
| 487 | - | |
| 488 | - COUPON_TYPE_TUPLE = ( | |
| 489 | - (DEEP_CLEANING, u'深度清洁'), | |
| 490 | - (FREE_FOCUS, u'免费调焦'), | |
| 491 | - (CLEAN_APPEARANCE, u'外观清洁'), | |
| 492 | - (ACCIDENTAL_MAINTENANCE, u'意外维修'), | |
| 493 | - (MAINTENANCE_MANPOWER, u'维修人工') | |
| 494 | - ) | |
| 495 | - | |
| 496 | - brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True) | |
| 497 | - brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称') | |
| 498 | - | |
| 499 | - coupon_id = ShortUUIDField(_(u'coupon_id'), max_length=32, blank=True, null=True, help_text=u'券唯一标识', db_index=True, unique=True) | |
| 500 | - | |
| 501 | - user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True) | |
| 502 | - | |
| 503 | - coupon_type = models.IntegerField(_(u'coupon_type'), choices=COUPON_TYPE_TUPLE, default=DEEP_CLEANING, help_text=u'券类型', db_index=True) | |
| 504 | - coupon_start_at = models.DateTimeField(_(u'coupon_start_at'), blank=True, null=True, help_text=u'券生效时间') | |
| 505 | - coupon_expire_at = models.DateTimeField(_(u'coupon_expire_at'), blank=True, null=True, help_text=u'券过期时间') | |
| 506 | - coupon_value = models.IntegerField(_(u'coupon_value'), default=0, help_text=u'券金额(单位:分)') | |
| 507 | - | |
| 508 | - has_used = models.BooleanField(_(u'has_used'), default=False, help_text=u'是否已核销', db_index=True) | |
| 509 | - admin_id = models.CharField(_(u'admin_id'), max_length=32, blank=True, null=True, help_text=u'核销员唯一标识', db_index=True) | |
| 510 | - used_at = models.DateTimeField(_(u'used_at'), blank=True, null=True, help_text=u'维修券核销时间') | |
| 511 | - | |
| 512 | - class Meta: | |
| 513 | - verbose_name = _(u'会员券信息') | |
| 514 | - verbose_name_plural = _(u'会员券信息') | |
| 515 | - | |
| 516 | - def __unicode__(self): | |
| 517 | - return unicode(self.pk) | |
| 518 | - | |
| 519 | - @property | |
| 520 | - def data(self): | |
| 521 | -        return { | |
| 522 | - 'coupon_id': self.coupon_id, | |
| 523 | - 'coupon_type': self.coupon_type, | |
| 524 | - 'coupon_start_at': tc.local_string(self.coupon_start_at, format='%Y%m%d'), | |
| 525 | - 'coupon_expire_at': tc.local_string(self.coupon_expire_at, format='%Y%m%d'), | |
| 526 | - 'coupon_value': self.coupon_value, | |
| 527 | - 'has_used': self.has_used, | |
| 528 | - 'admin_id': self.admin_id, | |
| 529 | - 'used_at': tc.local_string(self.used_at, format='%Y%m%d'), | |
| 530 | - } |