• vue---07 支付和订单


    为了方便开发,和以后项目的维护,我们再次创建子应用orders来完成接下来的订单和订单支付功能。

    cd luffy/apps
    python ../../manage.py startapp orders

    注册子应用,settings/dev.py,代码:

    INSTALLED_APPS = [
        # 子应用
        。。。
        
        'orders',
    ]

    订单模型

    from django.db import models
    
    # Create your models here.
    from luffy.utils.models import BaseModel
    from users.models import User
    from courses.models import Course
    class Order(BaseModel):
        """订单记录"""
        status_choices = (
            (0, '未支付'),
            (1, '已支付'),
            (2, '已取消'),
            (3, '超时取消'),
        )
        pay_choices = (
            (0, '支付宝'),
            (1, '微信支付')
        )
        order_title = models.CharField(max_length=150,verbose_name="订单标题")
        total_price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name="订单总价", default=0)
        real_price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name="实付金额", default=0)
        order_number = models.CharField(max_length=64,verbose_name="订单号")
        order_status = models.SmallIntegerField(choices=status_choices, default=0, verbose_name="订单状态")
        pay_type = models.SmallIntegerField(choices=pay_choices, default=0, verbose_name="支付方式")
        use_coupon = models.BooleanField(default=False,verbose_name="是否使用优惠券")
        coupon = models.IntegerField(null=True, verbose_name="用户优惠券ID")
        order_desc = models.TextField(max_length=500, verbose_name="订单描述")
        pay_time = models.DateTimeField(null=True, verbose_name="支付时间")
        user = models.ForeignKey(User, related_name='user_orders', on_delete=models.DO_NOTHING,verbose_name="下单用户")
    
        class Meta:
            db_table="ly_order"
            verbose_name= "订单记录"
            verbose_name_plural= "订单记录"
    
        def __str__(self):
            return "%s,总价: %s,实付: %s" % (self.order_title, self.total_price, self.real_price)
    
    
    class OrderDetail(BaseModel):
        """订单详情"""
        order = models.ForeignKey(Order, related_name='order_courses', on_delete=models.CASCADE, verbose_name="订单")
        course = models.ForeignKey(Course, related_name='course_orders', on_delete=models.CASCADE, verbose_name="课程")
        expire = models.IntegerField(default='-1', verbose_name="有效期周期")
        price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name="课程原价")
        real_price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name="课程实价")
        discount_name = models.CharField(max_length=120,default="",verbose_name="优惠活动类型")
        class Meta:
            db_table="ly_order_detail"
            verbose_name= "订单详情"
            verbose_name_plural= "订单详情"
    View Code

    把当前子应用注册到xadmin中

    在当前子应用下创建adminx.py,代码:

    import xadmin
    from .models import Order
    class OrderModelAdmin(object):
        """订单模型管理类"""
        pass
    
    xadmin.site.register(Order, OrderModelAdmin)
    
    
    from .models import OrderDetail
    class OrderDetailModelAdmin(object):
        """订单详情模型管理类"""
        pass
    
    xadmin.site.register(OrderDetail, OrderDetailModelAdmin)

    后端实现生成订单的api接口

  • 相关阅读:
    错误:The columns and the margins do not fit the page width.
    jasperreport使用动态jason数据源
    DynamicReport使用XML数据源+ireport的.jxml文件作为模板
    Report bands中文版
    iReport 使用json 数据源
    bat设置java环境变量
    解决DynamicReports中含有中文pdf版本不显示
    vba实现excel二级联动多选功能
    打字游戏 C语言
    fpga 任意分频 奇偶数 分频
  • 原文地址:https://www.cnblogs.com/yang950718/p/10928817.html
Copyright © 2020-2023  润新知