class Shop(db.Model): id = db.PrimaryKeyField() name = db.CharField(max_length=80) #商品名称 ename = db.CharField(max_length=100) #商品英文名称 price = db.CharField(max_length=30) #商品价格 cid = db.IntegerField() #商品分类 level = db.TinyIntegerField(max_length=1, default=3) #甜度 resume = db.CharField() #简单介绍 intro = db.TextField() #详细介绍 prompt = db.TextField() #提示 args = db.TextField() #参数内容 cover = db.CharField(max_length=20) #头图 views = db.SmallIntegerField(default=0) #点击率 orders = db.SmallIntegerField(default=0) #购买次 status = db.TinyIntegerField(max_length=1, default=0) #是否推荐 0不推荐 1推荐 #9删除 created = db.IntegerField(default=int(time.time())) #添加时间 def validate(self): if self.name and self.ename and self.cid: if not re.match('^[0-9a-z]+$', "".join( self.ename.lower().split())): raise Exception('英文名只能是字母和数字组合') else: raise Exception('请输入商品名,英文名或设置所属分类id') class Meta: db_table = 'shops' order_by = ('-created', )
class CreditLog(db.Model): id = db.PrimaryKeyField() uid = db.IntegerField(default=0) #用户Id mobile = db.CharField(max_length=11) #用户名 ctype = db.TinyIntegerField(max_length=1) #扣分 0奖励 1扣除 affect = db.SmallIntegerField(max_length=6) #积分 log = db.CharField(max_length=100) #说明 created = db.IntegerField(max_length=10, default=int(time.time())) #时间 class Meta: db_table = 'creditlogs' order_by = ('-id', )
class User(db.Model): """ 用户 """ id = db.PrimaryKeyField() mobile = db.CharField(unique = True, max_length=11, null = False) # 注册手机号 password = db.CharField(max_length=32) # 密码 realname = db.CharField(max_length=10) # 真实姓名 gender = db.TinyIntegerField(default=2) # 性别 0男 1女 2未知 qq = db.CharField(max_length=15) # qq birthday = db.DateField(default='1980-01-01') # 生日 tel = db.CharField(max_length=30) # 固定电话 credit = db.SmallIntegerField(default=0) # 积分 order = db.SmallIntegerField(default=0) # 订单 consult = db.SmallIntegerField(default=0) # 咨询 group = db.TinyIntegerField(**{'default' : 1}) # 用户组 0被禁止的用户 1正常用户 9管理员 signuped = db.IntegerField(default=int(time.time())) # 时间 lsignined = db.IntegerField(default=int(time.time())) # 最后登录时间 @staticmethod def create_password(raw): return hashlib.new("md5", raw).hexdigest() def check_password(self, raw): return hashlib.new("md5", raw).hexdigest() == self.password def validate(self): if self.mobile and vmobile(self.mobile): if User.select().where(User.mobile == self.mobile).count() > 0: raise Exception('此用户名已使用') else: raise Exception('请输入正确的手机号码') def updatesignin(self): self.lsignined = int(time.time()) self.save() class Meta: db_table = 'user'
class UserVcode(db.Model): mobile = db.CharField(max_length=11, null=False) #注册手机号 vcode = db.SmallIntegerField(max_length=4) created = db.IntegerField(index=True, default=int(time.time())) def validate(self): if self.mobile and vmobile(self.mobile): pass else: raise Exception('mobile is not validate') class Meta: db_table = 'uservcodes' indexes = ((('mobile', 'vcode'), True), )
class Apply(db.Model): """ 免费品尝 """ coname = db.CharField(max_length=80) # 公司名称 city = db.CharField(max_length=30) # 城市 region = db.CharField(max_length=30) # 区域 address = db.CharField(max_length=100) # 详细地址 pnumber = db.SmallIntegerField(default=1) # 公司人数 name = db.CharField(max_length=10) # 姓名 tel = db.CharField(max_length=30) # 固定电话 mobile = db.CharField(max_length=11) # 手机号码 applyed = db.IntegerField(default=int(time.time())) # 申请时间 def validate(self): if not self.coname: raise Exception('请输入公司名') if not self.region: raise Exception('请选择城市') if not self.region: raise Exception('请选择区域') if not self.address: raise Exception('请输入详细地址') if not self.name: raise Exception('请输入姓名') if not self.tel: raise Exception('请输入固定电话') if self.mobile and not vmobile(self.mobile): raise Exception('请输入正确的手机号码') class Meta: db_table = 'apply' order_by = ('-applyed',)