|
# -*- coding: utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_models_ext import BaseModelMixin, upload_file_path, upload_file_url, upload_path
from shortuuidfield import ShortUUIDField
from TimeConvert import TimeConvert as tc
from mch.models import ModelInfo
from simditor.fields import RichTextField
class GoodsInfo(BaseModelMixin):
PHYSICAL = 0
VIRTUAL = 1
GOOD_TYPE_TUPLE = (
(PHYSICAL, u'实物'),
(VIRTUAL, u'虚拟'),
)
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
good_id = ShortUUIDField(_(u'good_id'), max_length=32, blank=True, null=True, help_text=u'商品唯一标识', db_index=True, unique=True)
good_type = models.IntegerField(_(u'good_type'), choices=GOOD_TYPE_TUPLE, default=VIRTUAL, help_text=u'商品类型', db_index=True)
title = models.CharField(_(u'title'), max_length=255, blank=True, null=True, help_text=u'商品名称')
desc = RichTextField(_(u'desc'), blank=True, null=True, help_text=u'商品描述')
image = models.ImageField(_(u'image'), upload_to=upload_path, blank=True, null=True, help_text=u'商品图片')
is_slider = models.BooleanField(_(u'is_slider'), default=True, help_text=u'是否为轮播商品', db_index=True)
slider_image = models.ImageField(_(u'slider_image'), upload_to=upload_path, blank=True, null=True, help_text=u'商品轮播图片')
integral = models.IntegerField(_(u'integral'), default=99999, help_text=u'兑换所需积分')
fee = models.IntegerField(_(u'fee'), default=99999, help_text=u'兑换需额外支付金额,单位分')
minlevel = models.IntegerField(_(u'minlevel'), default=0, help_text=u'兑换最低会员级别')
position = models.IntegerField(_(u'position'), default=1, help_text=u'排序', db_index=True)
class Meta:
verbose_name = _(u'会员商品信息')
verbose_name_plural = _(u'会员商品信息')
def __unicode__(self):
return unicode(self.pk)
@property
def image_path(self):
return upload_file_path(self.image)
@property
def image_url(self):
return upload_file_url(self.image)
@property
def slider_image_path(self):
return upload_file_path(self.slider_image)
@property
def slider_image_url(self):
return upload_file_url(self.slider_image)
@property
def data(self):
return {
'good_id': self.good_id,
'good_type': self.good_type,
'title': self.title,
'image': self.image_url,
'slider_image': self.slider_image_url,
'integral': self.integral,
'fee': self.fee,
'minlevel': self.minlevel,
'able': True,
}
@property
def details(self):
return {
'good_id': self.good_id,
'good_type': self.good_type,
'title': self.title,
'image': self.image_url,
'slider_image': self.slider_image_url,
'integral': self.integral,
'fee': self.fee,
'minlevel': self.minlevel,
'able': True,
'desc': self.desc,
}
class GoodsOrderInfo(BaseModelMixin):
PHYSICAL = 0
VIRTUAL = 1
GOOD_TYPE_TUPLE = (
(PHYSICAL, u'实物'),
(VIRTUAL, u'虚拟'),
)
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
order_id = ShortUUIDField(_(u'order_id'), max_length=32, blank=True, null=True, help_text=u'订单唯一标识', db_index=True, unique=True)
user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True)
good_id = models.CharField(_(u'good_id'), max_length=32, blank=True, null=True, help_text=u'商品唯一标识', db_index=True)
good_type = models.IntegerField(_(u'good_type'), choices=GOOD_TYPE_TUPLE, default=VIRTUAL, help_text=u'商品类型', db_index=True)
title = models.CharField(_(u'title'), max_length=255, blank=True, null=True, help_text=u'商品名称')
name = models.CharField(_(u'name'), max_length=255, blank=True, null=True, help_text=u'姓名')
phone = models.CharField(_(u'phone'), max_length=255, blank=True, null=True, help_text=u'电话')
address = models.CharField(_(u'address'), max_length=255, blank=True, null=True, help_text=u'地址')
tracking_number = models.CharField(_(u'tracking_number'), max_length=255, blank=True, null=True, help_text=u'快递单号')
has_send_template_message = models.BooleanField(_(u'has_send_template_message'), default=True, help_text=u'是否已发送模版消息', db_index=True)
class Meta:
verbose_name = _(u'会员商品订单信息')
verbose_name_plural = _(u'会员商品订单信息')
def __unicode__(self):
return unicode(self.pk)
class RightInfo(BaseModelMixin):
PHYSICAL = 0
VIRTUAL = 1
COUPON = 2
RIGHT_TYPE_TUPLE = (
(PHYSICAL, u'实物'),
(VIRTUAL, u'虚拟'),
(COUPON, u'优惠券'),
)
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
right_id = ShortUUIDField(_(u'right_id'), max_length=32, blank=True, null=True, help_text=u'权益唯一标识', db_index=True, unique=True)
right_type = models.IntegerField(_(u'right_type'), choices=RIGHT_TYPE_TUPLE, default=VIRTUAL, help_text=u'权益类型', db_index=True)
icon = models.ImageField(_(u'icon'), upload_to=upload_path, blank=True, null=True, help_text=u'权益图标')
title = models.CharField(_(u'title'), max_length=255, blank=True, null=True, help_text=u'权益名称')
subtitle = models.CharField(_(u'subtitle'), max_length=255, blank=True, null=True, help_text=u'权益二级名称')
detail = RichTextField(_(u'detail'), blank=True, null=True, help_text=u'权益详情')
level1 = models.CharField(_(u'level1'), max_length=255, blank=True, null=True, help_text=u'level1')
level2 = models.CharField(_(u'level2'), max_length=255, blank=True, null=True, help_text=u'level2')
level3 = models.CharField(_(u'level3'), max_length=255, blank=True, null=True, help_text=u'level3')
level4 = models.CharField(_(u'level4'), max_length=255, blank=True, null=True, help_text=u'level4')
level5 = models.CharField(_(u'level5'), max_length=255, blank=True, null=True, help_text=u'level5')
minlevel = models.IntegerField(_(u'minlevel'), default=0, help_text=u'权益最低会员级别')
position = models.IntegerField(_(u'position'), default=1, help_text=u'排序', db_index=True)
# 券相关
is_send_coupon = models.BooleanField(_(u'is_send_coupon'), default=False, help_text=_(u'是否发券'), db_index=True)
coupon_valid_period = models.IntegerField(_(u'coupon_valid_period'), default=0, help_text=_(u'券有效时间(单位:天)'))
coupon_num = models.IntegerField(_(u'coupon_num'), default=0, help_text=_(u'券每会员级别发放张数'))
coupon_level1_amount = models.IntegerField(_(u'coupon_level1_amount'), default=0, blank=True, null=True, help_text=u'金额(单位:分)')
coupon_level2_amount = models.IntegerField(_(u'coupon_level2_amount'), default=0, blank=True, null=True, help_text=u'金额(单位:分)')
coupon_level3_amount = models.IntegerField(_(u'coupon_level3_amount'), default=0, blank=True, null=True, help_text=u'金额(单位:分)')
coupon_level4_amount = models.IntegerField(_(u'coupon_level4_amount'), default=0, blank=True, null=True, help_text=u'金额(单位:分)')
coupon_level5_amount = models.IntegerField(_(u'coupon_level5_amount'), default=0, blank=True, null=True, help_text=u'金额(单位:分)')
coupon_detail = RichTextField(_(u'coupon_detail'), blank=True, null=True, help_text=u'券详情')
class Meta:
verbose_name = _(u'会员权益信息')
verbose_name_plural = _(u'会员权益信息')
def __unicode__(self):
return unicode(self.pk)
@property
def icon_path(self):
return upload_file_path(self.icon)
@property
def icon_url(self):
return upload_file_url(self.icon)
@property
def data(self):
return {
'right_id': self.right_id,
'right_type': self.right_type,
'icon': self.icon_url,
'title': self.title,
'subtitle': self.subtitle,
'detail': self.detail,
'level1': self.level1,
'level2': self.level2,
'level3': self.level3,
'level4': self.level4,
'level5': self.level5,
'minlevel': self.minlevel,
'able': True,
'left_num': 3,
'left_tip': 3,
}
class CouponInfo(BaseModelMixin):
PHYSICAL = 0
VIRTUAL = 1
COUPON = 2
RIGHT_TYPE_TUPLE = (
(PHYSICAL, u'实物'),
(VIRTUAL, u'虚拟'),
(COUPON, u'优惠券'),
)
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
coupon_id = ShortUUIDField(_(u'coupon_id'), max_length=32, blank=True, null=True, help_text=u'券唯一标识', db_index=True, unique=True)
user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True)
coupon_valid_period = models.IntegerField(_(u'coupon_valid_period'), default=0, help_text=_(u'券有效时间(单位:天)'))
coupon_amount = models.IntegerField(_(u'coupon_amount'), default=0, blank=True, null=True, help_text=u'券金额(单位:分)')
coupon_detail = RichTextField(_(u'coupon_detail'), blank=True, null=True, help_text=u'券详情')
active_at = models.DateTimeField(_(u'active_at'), blank=True, null=True, help_text=_(u'生效时间'))
expire_at = models.DateTimeField(_(u'expire_at'), blank=True, null=True, help_text=_(u'过期时间'))
right_id = models.CharField(_(u'right_id'), max_length=32, blank=True, null=True, help_text=u'权益唯一标识', db_index=True)
right_type = models.IntegerField(_(u'right_type'), choices=RIGHT_TYPE_TUPLE, default=VIRTUAL, help_text=u'权益类型', db_index=True)
icon = models.ImageField(_(u'icon'), upload_to=upload_path, blank=True, null=True, help_text=u'权益图标')
title = models.CharField(_(u'title'), max_length=255, blank=True, null=True, help_text=u'权益名称')
subtitle = models.CharField(_(u'subtitle'), max_length=255, blank=True, null=True, help_text=u'权益二级名称')
detail = RichTextField(_(u'detail'), blank=True, null=True, help_text=u'权益详情')
has_used = models.BooleanField(_(u'has_used'), default=False, help_text=u'是否已核销', db_index=True)
admin_id = models.CharField(_(u'admin_id'), max_length=32, blank=True, null=True, help_text=u'核销员唯一标识', db_index=True)
used_at = models.DateTimeField(_(u'used_at'), blank=True, null=True, help_text=u'维修券核销时间')
class Meta:
verbose_name = _(u'会员券信息')
verbose_name_plural = _(u'会员券信息')
def __unicode__(self):
return unicode(self.pk)
@property
def icon_path(self):
return upload_file_path(self.icon)
@property
def icon_url(self):
return upload_file_url(self.icon)
@property
def data(self):
return {
'coupon_id': self.coupon_id,
'coupon_valid_period': self.coupon_valid_period,
'coupon_amount': self.coupon_amount,
'coupon_detail': self.coupon_detail,
'active_at': tc.local_string(self.active_at, format='%Y%m%d'),
'expire_at': tc.local_string(self.expire_at, format='%Y%m%d'),
'right_id': self.right_id,
'right_type': self.right_type,
'icon': self.icon_url,
'title': self.title,
'subtitle': self.subtitle,
'detail': self.detail,
'has_used': self.has_used,
'admin_id': self.admin_id,
'used_at': self.used_at,
}
class ShotTypeInfo(BaseModelMixin):
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
shot_type_id = ShortUUIDField(_(u'shot_type_id'), max_length=32, blank=True, null=True, help_text=u'镜头类型唯一标识', db_index=True, unique=True)
shot_type_name = models.CharField(_(u'shot_type_name'), max_length=255, blank=True, null=True, help_text=u'镜头类型名称')
position = models.IntegerField(_(u'position'), default=1, help_text=u'排序', db_index=True)
class Meta:
verbose_name = _(u'镜头类型信息')
verbose_name_plural = _(u'镜头类型信息')
def __unicode__(self):
return unicode(self.pk)
@property
def shots(self):
models = ModelInfo.objects.filter(shot_type_id=self.shot_type_id, status=True)
return [model.member_shot_data for model in models]
@property
def data(self):
return {
'type_id': self.shot_type_id,
'type_name': self.shot_type_name,
'shots': self.shots,
}
class MemberActivityInfo(BaseModelMixin):
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
activity_id = ShortUUIDField(_(u'activity_id'), max_length=32, blank=True, null=True, help_text=u'活动唯一标识', db_index=True, unique=True)
title = models.CharField(_(u'title'), max_length=255, blank=True, null=True, help_text=u'活动名称')
subtitle = models.CharField(_(u'subtitle'), max_length=255, blank=True, null=True, help_text=u'活动二级名称')
date = models.DateField(_(u'date'), blank=True, null=True, help_text=u'活动时间')
city = models.CharField(_(u'city'), max_length=255, blank=True, null=True, help_text=u'活动城市')
location = models.CharField(_(u'location'), max_length=255, blank=True, null=True, help_text=u'活动地点')
lat = models.FloatField(_(u'lat'), default=1.0, help_text=u'纬度')
lon = models.FloatField(_(u'lon'), default=1.0, help_text=u'经度')
integral = models.IntegerField(_(u'integral'), default=0, help_text=u'会员积分')
image = models.ImageField(_(u'image'), upload_to=upload_path, blank=True, null=True, help_text=u'活动内容图片')
cover = models.ImageField(_(u'cover'), upload_to=upload_path, blank=True, null=True, help_text=u'活动列表图片')
is_slider = models.BooleanField(_(u'is_slider'), default=True, help_text=u'是否为轮播活动', db_index=True)
slider_image = models.ImageField(_(u'slider_image'), upload_to=upload_path, blank=True, null=True, help_text=u'活动轮播图片')
content_rich_text = RichTextField(_(u'content_rich_text'), blank=True, null=True, help_text=u'活动描述')
share_img_link = models.CharField(_(u'share_img_link'), max_length=255, blank=True, null=True, help_text=u'活动图片分享')
share_h5_link = models.CharField(_(u'share_h5_link'), max_length=255, blank=True, null=True, help_text=u'活动H5分享')
position = models.IntegerField(_(u'position'), default=1, help_text=u'排序', db_index=True)
class Meta:
verbose_name = _(u'会员活动信息')
verbose_name_plural = _(u'会员活动信息')
def __unicode__(self):
return unicode(self.pk)
@property
def image_path(self):
return upload_file_path(self.image)
@property
def image_url(self):
return upload_file_url(self.image)
@property
def cover_path(self):
return upload_file_path(self.cover)
@property
def cover_url(self):
return upload_file_url(self.cover)
@property
def slider_image_path(self):
return upload_file_path(self.slider_image)
@property
def slider_image_url(self):
return upload_file_url(self.slider_image)
@property
def final_state(self):
tdate = tc.local_date()
if tdate < self.date:
return u'报名中'
if tdate == self.date:
return u'活动中'
return u'已结束'
def is_signed(self, user_id):
# 是否已报名
return MemberActivitySignupInfo.objects.filter(user_id=user_id, activity_id=self.activity_id, status=True).exists()
def data(self, user_id):
return {
'id': self.activity_id,
'activity_id': self.activity_id,
'title': self.title,
'subtitle': self.subtitle,
'date': tc.local_string(self.date, format='%Y-%m-%d'),
'city': self.city,
'location': self.location,
'lat': self.lat,
'lon': self.lon,
'integral': self.integral,
'cover_url': self.cover_url,
'share_img_link': self.share_img_link,
'share_h5_link': self.share_h5_link,
'slider_image': self.slider_image_url,
'state': self.final_state,
'is_signed': self.is_signed(user_id),
}
def details(self, user_id):
return {
'id': self.activity_id,
'activity_id': self.activity_id,
'title': self.title,
'subtitle': self.subtitle,
'date': tc.local_string(self.date, format='%Y-%m-%d'),
'city': self.city,
'location': self.location,
'lat': self.lat,
'lon': self.lon,
'integral': self.integral,
'content_rich_text': self.content_rich_text,
'cover_url': self.cover_url,
'share_img_link': self.share_img_link,
'share_h5_link': self.share_h5_link,
'slider_image': self.slider_image_url,
'state': self.final_state,
'is_signed': self.is_signed(user_id),
}
class MemberActivitySignupInfo(BaseModelMixin):
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
signup_id = ShortUUIDField(_(u'signup_id'), max_length=32, blank=True, null=True, help_text=u'活动报名唯一标识', db_index=True, unique=True)
user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True)
activity_id = models.CharField(_(u'activity_id'), max_length=32, blank=True, null=True, help_text=u'活动唯一标识', db_index=True)
title = models.CharField(_(u'title'), max_length=255, blank=True, null=True, help_text=u'活动名称')
name = models.CharField(_(u'name'), max_length=255, blank=True, null=True, help_text=u'姓名')
phone = models.CharField(_(u'phone'), max_length=255, blank=True, null=True, help_text=u'电话')
class Meta:
verbose_name = _(u'会员活动报名信息')
verbose_name_plural = _(u'会员活动报名信息')
unique_together = (
('user_id', 'activity_id'),
)
def __unicode__(self):
return unicode(self.pk)
class MemberActivitySigninInfo(BaseModelMixin):
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
signin_id = ShortUUIDField(_(u'signin_id'), max_length=32, blank=True, null=True, help_text=u'活动签到唯一标识', db_index=True, unique=True)
user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True)
activity_id = models.CharField(_(u'activity_id'), max_length=32, blank=True, null=True, help_text=u'活动唯一标识', db_index=True)
title = models.CharField(_(u'title'), max_length=255, blank=True, null=True, help_text=u'活动名称')
class Meta:
verbose_name = _(u'会员活动签到信息')
verbose_name_plural = _(u'会员活动签到信息')
unique_together = (
('user_id', 'activity_id'),
)
def __unicode__(self):
return unicode(self.pk)
class MemberCouponInfo(BaseModelMixin):
DEEP_CLEANING = 0
FREE_FOCUS = 1
CLEAN_APPEARANCE = 2
ACCIDENTAL_MAINTENANCE = 3
MAINTENANCE_MANPOWER = 4
COUPON_TYPE_TUPLE = (
(DEEP_CLEANING, u'深度清洁'),
(FREE_FOCUS, u'免费调焦'),
(CLEAN_APPEARANCE, u'外观清洁'),
(ACCIDENTAL_MAINTENANCE, u'意外维修'),
(MAINTENANCE_MANPOWER, u'维修人工')
)
brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
coupon_id = ShortUUIDField(_(u'coupon_id'), max_length=32, blank=True, null=True, help_text=u'券唯一标识', db_index=True, unique=True)
user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True)
coupon_type = models.IntegerField(_(u'coupon_type'), choices=COUPON_TYPE_TUPLE, default=DEEP_CLEANING, help_text=u'券类型', db_index=True)
coupon_start_at = models.DateTimeField(_(u'coupon_start_at'), blank=True, null=True, help_text=u'券生效时间')
coupon_expire_at = models.DateTimeField(_(u'coupon_expire_at'), blank=True, null=True, help_text=u'券过期时间')
coupon_value = models.IntegerField(_(u'coupon_value'), default=0, help_text=u'券金额(单位:分)')
has_used = models.BooleanField(_(u'has_used'), default=False, help_text=u'是否已核销', db_index=True)
admin_id = models.CharField(_(u'admin_id'), max_length=32, blank=True, null=True, help_text=u'核销员唯一标识', db_index=True)
used_at = models.DateTimeField(_(u'used_at'), blank=True, null=True, help_text=u'维修券核销时间')
class Meta:
verbose_name = _(u'会员券信息')
verbose_name_plural = _(u'会员券信息')
def __unicode__(self):
return unicode(self.pk)
@property
def data(self):
return {
'coupon_id': self.coupon_id,
'coupon_type': self.coupon_type,
'coupon_start_at': tc.local_string(self.coupon_start_at, format='%Y%m%d'),
'coupon_expire_at': tc.local_string(self.coupon_expire_at, format='%Y%m%d'),
'coupon_value': self.coupon_value,
'has_used': self.has_used,
'admin_id': self.admin_id,
'used_at': tc.local_string(self.used_at, format='%Y%m%d'),
}
|