• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

广告小程序后端开发(2.Models设计)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 1.重建用户表:

1.在settings中配置:

AUTH_USER_MODEL='users.UserProfile'

2.apps/users/models.py中建立UserProfile表:

class UserProfile(AbstractUser):
    """
    用户表
    """
    nickName=models.CharField(max_length=30,default=‘’,verbose_name='微信名')
    avatarUrl = models.CharField(max_length=200, null=True, blank=True, verbose_name='用户头像URL')
    open_id = models.CharField(max_length=64, null=True, blank=True, verbose_name='OpenId')
    token = models.CharField(max_length=64, null=True, blank=True, verbose_name='token')
    gender = models.CharField(max_length=4, choices=(('0', '未知'), ('1', ''), ('2', '')), default='0',
                              verbose_name='性别')
    city = models.CharField(max_length=20, null=True, blank=True, verbose_name='用户所在市')
    longitude = models.CharField(max_length=10, null=True, blank=True, verbose_name='经度')
    latitude = models.CharField(max_length=10, null=True, blank=True, verbose_name='纬度')
    jifen=models.IntegerField(default=0,verbose_name='积分')
    yongjin=models.FloatField(default=0,verbose_name='佣金')
    fensi_num=models.IntegerField(default=0,verbose_name='粉丝数')

    class Meta:
        verbose_name='用户'
        verbose_name_plural = verbose_name
  def __str__(self):
    return self.nickName

3.执行数据更新命令:

python manage.py makemigrations
python manage.py migrate

2.建立地区表:

1.在apps/users/models.py中建立地区表:

class Area(models.Model):
        """
        地区表
        """
        CATEGORY_TYPE = (
            (1, '省级'),
            (2, '市级'),
            (3, '区县级'),
        )
        num=models.IntegerField(default=0,verbose_name='地区编码')
        name = models.CharField(default='', max_length=30, verbose_name='地名')
        category_type = models.IntegerField(choices=CATEGORY_TYPE, verbose_name='地区级别')
        parent_category = models.ForeignKey('self', null=True, blank=True, verbose_name='父类目录',
                                            related_name='sub_cat', on_delete=models.CASCADE)
        add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')

        class Meta:
            verbose_name = '地区'
            verbose_name_plural = verbose_name

        def __str__(self):
            return self.name

2.执行数据更新命令:

python manage.py makemigrations
python manage.py migrate

3.建立用户增加积分表

1.在apps/users/models.py中建立 用户增加积分表:

class AddJiFen(models.Model):
    """用户增加积分表"""
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    ad_jifen = models.IntegerField(default=0, verbose_name='积分')
    add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')

    class Meta:
        verbose_name = '用户增加积分表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user.nickName

2.执行数据更新命令:

python manage.py makemigrations
python manage.py migrate

2.ad的数据表设计:

1.安装处理图片的依赖包pillow:

pip install pillow

2.在apps/ad/models.py中:

from django.db import models
from datetime import datetime
from users.models import UserProfile,Area
from django.utils.safestring import mark_safe
# Create your models here.


class Category(models.Model):
"""
分类表
"""
name=models.CharField(default='',max_length=30,verbose_name='类别名')
category_type=models.IntegerField(choices=((1, '一级类目'),(2, '二级类目')),verbose_name='类别级别')
parent_category=models.ForeignKey('self',null=True,blank=True,verbose_name='父类目录',related_name='sub_cat',on_delete=models.CASCADE)
is_tab=models.BooleanField(default=False,verbose_name='是否导航',help_text='是否导航')
add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')

class Meta:
verbose_name='类别'
verbose_name_plural=verbose_name

def __str__(self):
return self.name


class Good(models.Model):
"""广告或店铺"""
title=models.CharField(max_length=15,null=True,blank=True,verbose_name='标题',help_text='最多15字')
desc = models.TextField(default='', max_length=400, verbose_name='描述',help_text='最多400字')
address = models.CharField(max_length=200, default="", verbose_name="详细地址")
mobile = models.CharField(max_length=11, default="", verbose_name="电话")
pv = models.IntegerField(default=0, verbose_name='浏览量')
category = models.ForeignKey(Category, verbose_name="分类", on_delete=models.CASCADE)
area = models.ForeignKey(Area, null=True, blank=True, verbose_name="地区", on_delete=models.CASCADE)
stage = models.IntegerField(default=1, choices=((1, '待审核'),(2, '已发布'),(3,'未通过')), verbose_name="阶段")
user = models.ForeignKey(UserProfile, verbose_name="发布者", on_delete=models.CASCADE)
type = models.IntegerField(default=1, choices=((1, '广告'), (2, '店铺')), verbose_name="类型")
image = models.ImageField(max_length=200,default='smallapp/1.png', upload_to='smallapp/',verbose_name='小程序码')
last_visit_time=models.DateTimeField(default=datetime.now, verbose_name='最后浏览时间')
add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')
xian_top=models.IntegerField(default=0, choices=((0,'未置顶'),(1, '置顶'),(2, '超级置顶')), verbose_name="是否县置顶")
shi_top = models.IntegerField(default=0, choices=((0, '未置顶'), (1, '置顶'), (2, '超级置顶')), verbose_name="是否市置顶")
sheng_top = models.IntegerField(default=0, choices=((0, '未置顶'), (1, '置顶'), (2, '超级置顶')), verbose_name="是否省置顶")

class Meta:
verbose_name = "发布广告或店铺"
verbose_name_plural = verbose_name

def __str__(self):
return self.title

def image_url(self):
return mark_safe('<img src="/media/{0}" class="field_img">'.format(self.image))

image_url.short_description = '小程序码'


class Prize(models.Model):
"""奖品"""
title = models.CharField(max_length=15, null=True, blank=True, verbose_name='标题', help_text='最多15字')
url=models.CharField(max_length=200, null=True, blank=True, verbose_name='小程序url')
area = models.ForeignKey(Area, null=True, blank=True, verbose_name="地区", on_delete=models.CASCADE)
get_num=models.IntegerField(default=0,verbose_name='被领取数')
price = models.IntegerField(default=0, verbose_name='所需积分')
all_num=models.IntegerField(default=0,verbose_name='发布数')
desc = models.TextField(default='', max_length=400, verbose_name='描述', help_text='最多400字')
usage = models.TextField(default='', max_length=200, verbose_name='使用方式', help_text='最多200字')
image = models.ImageField(max_length=200, default='', upload_to='prizeimg/', verbose_name='奖品图片')
end_time = models.DateTimeField(default=datetime.now, verbose_name='过期时间')
add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')

class Meta:
verbose_name = "奖品"
verbose_name_plural = verbose_name

def __str__(self):
return self.title

def image_url(self):
return mark_safe('<img src="/media/{0}" class="field_img">'.format(self.image))

image_url.short_description = '奖品图片'


class Images(models.Model):
"""
图片
"""
is_banner=models.BooleanField(default=False,verbose_name='是否是轮播图')
image = models.ImageField(max_length=200, upload_to='images/')
good = models.ForeignKey(Good, verbose_name="广告或店铺",blank=True,null=True, on_delete=models.CASCADE)
add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')

class Meta:
verbose_name = "图片"
verbose_name_plural = verbose_name

def image_url(self):
return mark_safe('<img src="/media/{0}" class="field_img">'.format(self.image))

image_url.short_description = '图片'


class Top(models.Model):
"""
置顶表
"""
good = models.ForeignKey(Good, verbose_name="广告或店铺",blank=True,null=True, on_delete=models.CASCADE)
xian_end_time = models.DateTimeField(default=datetime.now, verbose_name='县置顶截止时间')
shi_end_time = models.DateTimeField(default=datetime.now, verbose_name='市置顶截止时间')
sheng_end_time = models.DateTimeField(default=datetime.now, verbose_name='省置顶截止时间')
super_xian_end_time = models.DateTimeField(default=datetime.now, verbose_name='县超级置顶截止时间')
super_shi_end_time = models.DateTimeField(default=datetime.now, verbose_name='市超级置顶截止时间')
super_sheng_end_time = models.DateTimeField(default=datetime.now, verbose_name='省超级置顶截止时间')
add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')
class Meta:
verbose_name = "置顶表"
verbose_name_plural = verbose_name

def __str__(self):
return self.good.title

 

 

3.执行数据更新命令:

python manage.py makemigrations
python manage.py migrate

3.trade数据表设计:

1.apps/trade/models.py中:

from django.db import models
from datetime import datetime
from users.models import UserProfile,Area
from ad.models import Good

# Create your models here.


class Price(models.Model):
    """置顶服务价格表"""
    top_type = models.CharField(max_length=4, choices=(('0', '置顶'), ('1', '超级置顶')), default='0',verbose_name='置顶类型')
    price=models.FloatField(default=0,verbose_name="价格")
    fanwei=models.CharField(max_length=4, choices=(('0', '全县'), ('1', '全市'),('2', '全省')), default='0',verbose_name='置顶类型')
    days=models.IntegerField(default=0,verbose_name='天数')
    add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间')

    class Meta:
        verbose_name = '置顶服务价格表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s-%s(%d)".format(self.top_type,self.fanwei, self.days)


class Order(models.Model):
    """置顶订单"""
    user = models.ForeignKey(UserProfile, verbose_name="购买者", on_delete=models.CASCADE)
    good=models.ForeignKey(Good,null=True, blank=True, verbose_name="广告或店铺", on_delete=models.CASCADE)
    order_sn = models.CharField(max_length=32, null=True, blank=True, unique=True, verbose_name="订单号")
    pay_status = models.CharField(choices=(("TRADE_SUCCESS", "成功"),("TRADE_CLOSED", "超时关闭"),("paying", "待支付")),
                                  default="paying", max_length=30, verbose_name="订单状态")
    trade_no = models.CharField(max_length=100, unique=True, null=True, blank=True, verbose_name="交易号")
    order_mount = models.FloatField(default=0.0, verbose_name="订单金额")
    pay_time = models.DateTimeField(null=True, blank=True, verbose_name="支付时间")
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "订单表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return str(self.order_sn)


class ShoppingCar(models.Model):
    """购物车表(置顶)"""
    user = models.ForeignKey(UserProfile, verbose_name="购买者", on_delete=models.CASCADE)
    order = models.ForeignKey(Order, verbose_name="订单", on_delete=models.CASCADE)
    top_good=models.ForeignKey(Price, verbose_name="置顶服务种类",related_name="goods", on_delete=models.CASCADE)
    goods_num = models.IntegerField(default=1, verbose_name="置顶服务数量",help_text='目前只支持每次每种置顶服务购买数量为1')
    price=models.FloatField(default=0.0, verbose_name="订单金额")
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "购物车表"
        verbose_name_plural = verbose_name

 

2.执行数据更新命令:

python manage.py makemigrations
python manage.py migrate

4.user_operation数据表设计:

1.apps/user_operation/models.py中:

from django.db import models
from datetime import datetime
from users.models import UserProfile
from ad.models import Prize
# Create your models here.


class Message(models.Model):
    """用户消息表"""
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    content=models.TextField(default='', max_length=200, verbose_name='消息内容',help_text='最多200字')
    is_read=models.BooleanField(default=False,verbose_name="是否已读")
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "用户消息表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.content


class GetPrize(models.Model):
    """兑奖表"""
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    prize=models.ForeignKey(Prize, verbose_name="奖品", on_delete=models.CASCADE)
    status = models.CharField(choices=(("0", "待发货"), ("1", "已发货"), ("2", "已签收")),default="0",
                              max_length=8, verbose_name="奖品发放状态")
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "兑奖表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.prize


class UserAdress(models.Model):
    """用户收货地址"""
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    address=models.CharField(max_length=300,verbose_name='收货地址',default='',help_text='最多300字')
    phone=models.CharField(max_length=11,verbose_name='电话',default='')
    name=models.CharField(max_length=15,verbose_name='收件人',default='')
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "用户收货地址"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Fans(models.Model):
    """粉丝表"""
    user=models.ForeignKey(UserProfile, verbose_name="用户", related_name='user',on_delete=models.CASCADE)
    fans=models.ForeignKey(UserProfile, verbose_name="粉丝", related_name='fans',on_delete=models.CASCADE)
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "粉丝表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user


class MakeMoney(models.Model):
    """佣金记录表"""
    user = models.ForeignKey(UserProfile, verbose_name="用户", related_name='u',on_delete=models.CASCADE)
    fans = models.ForeignKey(UserProfile, verbose_name="粉丝", related_name='f',help_text='从哪个粉丝的消费中分成的',
                             on_delete=models.CASCADE)
    money=models.FloatField(default=0,verbose_name='佣金')
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "佣金记录表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user


class GetCash(models.Model):
    """提现记录表"""
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    money = models.FloatField(default=0, verbose_name='提现金额')
    add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "提现记录表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user

2.执行数据更新命令:

python manage.py makemigrations
python manage.py migrate

3.其中“提现记录表”是暂时的,等到后期如果微信的“企业提款到零钱”功能可以开放使用,则要对这个表进行修改。

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap