ements and can run on an inexpensive Raspberry Pi. Save your machine energy!

Open Source

It's all on GitHub! Join us by contributing to make this project even better. Don't be shy to be a contributor!

kodosale - Gogs: Go Git Service

Nessuna descrizione

models.py 14KB

    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 jsonfield import JSONField from shortuuidfield import ShortUUIDField from TimeConvert import TimeConvert as tc from account.models import UserInfo from simditor.fields import RichTextField class AnchorInfo(BaseModelMixin): anchor_id = ShortUUIDField(_('anchor_id'), max_length=32, blank=True, help_text='主播唯一标识', unique=True) # 微信相关 unionid = models.CharField(_('unionid'), max_length=32, blank=True, help_text='微信 Unionid') openid = models.CharField(_('openid'), max_length=32, blank=True, help_text='微信 Openid') # 真实相关 banner = models.ImageField(_('banner'), upload_to=upload_path, blank=True, help_text='主播 Banner图') anchor_name = models.CharField(_('anchor_name'), max_length=255, blank=True, help_text='主播姓名', db_index=True) anchor_avatar = models.ImageField(_('anchor_avatar'), upload_to=upload_path, help_text='主播头像') anchor_intro = RichTextField(_('anchor_intro'), blank=True, help_text='主播介绍') class Meta: verbose_name = _('主播信息') verbose_name_plural = _('主播信息') def __unicode__(self): return self.pk @property def anchor_avatar_path(self): return upload_file_path(self.anchor_avatar) @property def anchor_avatar_url(self): return upload_file_url(self.anchor_avatar) @property def banner_path(self): return upload_file_path(self.banner) @property def banner_url(self): return upload_file_url(self.banner) class RoomInfo(BaseModelMixin): room_id = models.CharField(_('anchor_id'), max_length=32, help_text='房间唯一标识', db_index=True, unique=True) name = models.CharField(_('name'), max_length=255, blank=True, help_text='直播房间名', db_index=True) live_status = models.IntegerField(_('live_status'), default=0, blank=True, help_text='直播状态', db_index=True) start_time = models.IntegerField(_('start_time'), default=0, blank=True, help_text='直播计划开始时间', db_index=True) end_time = models.IntegerField(_('end_time'), default=0, blank=True, help_text='直播计划结束时间', db_index=True) cover_img = models.ImageField(_('cover_img'), upload_to=upload_path, null=True, help_text='直播间背景墙') wx_cover_img = models.CharField(_('wx_cover_img'), blank=True, max_length=255, help_text='微信直播背景墙', db_index=True) share_img = models.ImageField(_('share_img'), upload_to=upload_path, null=True, help_text='分享卡片图片') wx_share_img = models.CharField(_('wx_share_img'), blank=True, max_length=255, help_text='微信直播分享卡片图片', db_index=True) anchor_id = models.CharField(_('anchor_id'), blank=True, max_length=32, help_text='主播唯一标识') anchor_name = models.CharField(_('anchor_name'), blank=True, max_length=255, help_text='主播名称', db_index=True) # "goods": [ # { # "cover_img": "http://mmbiz.qpic.cn/mmbiz_png/FVribAGdErI2PmyST9ZM0JLbNM48I7TH2FlrwYOlnYqGaej8qKubG1EvK0QIkkwqvicrYTzVtjKmSZSeY5ianc3mw/0?wx_fmt=png", # "url": "pages/index/index.html", # "price": 1100, # "name": "fdgfgf" # } # ], goods = JSONField(_('goods'), blank=True, default=[], help_text='商品销售信息') class Meta: verbose_name = _('直播间信息') verbose_name_plural = _('直播间信息') def __unicode__(self): return self.pk @property def cover_img_path(self): return upload_file_path(self.cover_img) @property def cover_img_url(self): return upload_file_url(self.cover_img) @property def share_img_path(self): return upload_file_path(self.share_img) @property def share_img_url(self): return upload_file_url(self.share_img) @property def anchorData(self): return { 'room_id': self.room_id, 'name': self.name, 'live_status': self.live_status, 'cover_img': self.wx_cover_img, 'share_img': self.wx_share_img, } @property def admindata(self): anchor = AnchorInfo.objects.get(anchor_id=self.anchor_id) return { 'room_id': self.room_id, 'name': self.name, 'live_status': self.live_status, 'end_time': self.end_time, 'cover_img': self.wx_cover_img, 'anchor_name': self.anchor_name, 'share_img': self.wx_share_img, 'anchor_id': self.anchor_id, 'anchor_name': anchor.anchor_name, 'anchor_avatar': anchor.anchor_avatar_url } class liveGoodsInfo(BaseModelMixin): goods_id = ShortUUIDField(_('goods_id'), max_length=32, blank=True, help_text='商品ID', unique=True) wx_goods_id = models.CharField(_('wx_goods_id'), max_length=255, blank=True, help_text='微信商品ID', db_index=True) audit_id = models.CharField(_('audit_id'), default=0, max_length=255, blank=True, help_text='审核单ID', db_index=True) # 商品状态,0:未审核。1:审核中,2:审核通过,3:审核驳回 audit_status = models.IntegerField(_('audit_status'), default=0, blank=True, help_text='审核状态', db_index=True) goods_img = models.FileField(_('goods_img'), upload_to=upload_path, blank=True, help_text='商品图') # { # "goodsInfo": { # "coverImgUrl": "ZuYVNKk9sMP1X4m7FXdcDCKra251KDZTjS502UTV7gwalgLZXcrOhG6oNYX6c7AR", # "name":"TIT茶杯", # "priceType":1, # "price":"111", # "price2":"", # "url":"pages/index/index" # } # } coverImgUrl = models.CharField(_('coverImgUrl'), max_length=255, blank=True, help_text='微信mediaID', db_index=True) name = models.CharField(_('name'), max_length=34, help_text='商品', blank=True, db_index=True) # 价格类型,1:一口价,2:价格区间,3:显示折扣价;1:一口价,只需要传入price,price2不传;2:价格区间,price字段为左边界,price2字段为右边界,price和price2必传。3:折扣价,price字段为原价,price2字段为现价, price和price2必传 price_type = models.IntegerField(_('price_type'), blank=True, help_text='价格类型', db_index=True) price = models.IntegerField(_('price'), blank=True, help_text='price') price2 = models.IntegerField(_('price2'), blank=True, help_text='price2') url = models.CharField(_('url'), max_length=255, blank=True, help_text='小程序商品路径', db_index=True) class Meta: verbose_name = _('直播商品库') verbose_name_plural = _('直播商品库') def __unicode__(self): return self.pk @property def goods_img_path(self): return upload_file_path(self.goods_img) @property def goods_img_url(self): return upload_file_url(self.goods_img) @property def admindata(self): return { 'goods_id': self.goods_id, 'wx_goods_id': self.wx_goods_id, 'audit_id': self.audit_id, 'audit_status': self.audit_status, 'goods_img': self.goods_img_url, 'name': self.name, 'coverImgUrl': self.coverImgUrl, 'price_type': self.price_type, 'price': self.price, 'price2': self.price2, 'url': self.url } class RoomGoodsInfo(BaseModelMixin): room_id = models.CharField(_('room_id'), max_length=32, help_text='房间唯一标识', db_index=True) anchor_id = models.CharField(_('anchor_id'), max_length=32, blank=True, help_text='主播唯一标识') goods_id = models.CharField(_('goods_id'), max_length=32, blank=True, help_text='商品ID') inventory = models.IntegerField(_('inventory'), default=0, help_text='直播间库存数量') sale_infos = JSONField(_('sale_infos'), blank=True, default=[], help_text='直播间商品销售信息') class Meta: verbose_name = _('直播间商品信息') verbose_name_plural = _('直播间商品信息') def __unicode__(self): return self.pk class RoomUserInfo(BaseModelMixin): room_id = models.CharField(_('room_id'), max_length=32, help_text='房间唯一标识', db_index=True) anchor_id = models.CharField(_('anchor_id'), max_length=32, blank=True, help_text='主播唯一标识') user_id = models.CharField(_('user_id'), max_length=32, blank=True, help_text='用户唯一标识') openid = models.CharField(_('openid'), max_length=32, blank=True, help_text='用户 openid') share_openid = models.CharField(_('share_openid'), max_length=32, blank=True, help_text='分享用户 openid') live_status = models.IntegerField(_('live_status'), default=0, blank=True, help_text='直播状态', db_index=True) scene = models.CharField(_('scene'), max_length=32, blank=True, help_text='进入场景') is_new = models.BooleanField(_('is_new'), default=True, blank=True, help_text='是否是新用户') class Meta: verbose_name = _('直播间用户信息') verbose_name_plural = _('直播间用户信息') def __unicode__(self): return self.pk class RoomOrderInfo(BaseModelMixin): """ # Trade State of Wechat Query SUCCESS ——— 支付成功 REFUND ——— 转入退款 NOTPAY ——— 未支付 CLOSED ——— 已关闭 REVOKED ——— 已撤销(刷卡支付) USERPAYING ——— 用户支付中 PAYERROR ——— 支付失败(其他原因,如银行返回失败) """ WAITING_PAY = 0 PAID = 1 FAIL = 2 # DELETED = 9 PAY_STATUS = ( (WAITING_PAY, '待支付'), (PAID, '已支付'), (FAIL, '已失败'), # (DELETED, '已删除'), ) order_id = ShortUUIDField(_('order_id'), max_length=32, blank=True, help_text='订单唯一标识', unique=True) user_id = models.CharField(_('user_id'), max_length=32, help_text='用户唯一标识', db_index=True) room_id = models.CharField(_('room_id'), max_length=32, help_text='房间唯一标识', db_index=True) anchor_id = models.CharField(_('anchor_id'), max_length=32, blank=True, help_text='主播唯一标识') goods_id = models.CharField(_('goods_id'), max_length=32, blank=True, help_text='商品唯一标识') share_openid = models.CharField(_('share_openid'), max_length=32, blank=True, help_text='转发用户 openid') amount = models.IntegerField(_('amount'), default=0, help_text='数量') name = models.CharField(_('name'), max_length=255, blank=True, null=True, help_text='姓名') phone = models.CharField(_('phone'), max_length=255, blank=True, null=True, help_text='电话') province = models.CharField(_('province'), max_length=255, blank=True, null=True, help_text='省份') city = models.CharField(_('city'), max_length=255, blank=True, null=True, help_text='城市') county = models.CharField(_('county'), max_length=255, blank=True, null=True, help_text='区') address = models.CharField(_('address'), max_length=255, blank=True, null=True, help_text='地址') tracking_number = models.CharField(_('tracking_number'), max_length=255, blank=True, null=True, help_text='快递单号') has_send_template_message = models.BooleanField(_('has_send_template_message'), default=True, help_text='是否已发送模版消息', db_index=True) prepay_id = models.CharField(_('prepay_id'), max_length=64, blank=True, null=True, help_text='预支付交易会话标识') transaction_id = models.CharField(_('transaction_id'), max_length=32, blank=True, null=True, help_text='交易单号') body = models.CharField(_('body'), max_length=255, blank=True, null=True, help_text='商品描述') total_fee = models.IntegerField(_('total_fee'), default=0, help_text='总金额') trade_type = models.CharField(_('trade_type'), max_length=255, blank=True, null=True, help_text='支付方式') pay_status = models.IntegerField(_('pay_status'), choices=PAY_STATUS, default=WAITING_PAY, help_text='支付状态', db_index=True) paid_at = models.DateTimeField(_('paid_at'), blank=True, null=True, help_text=_('支付时间')) reback_status = models.BooleanField(_('reback_status'), default=False, help_text='退款状态', db_index=True) reback_at = models.DateTimeField(_('reback_at'), blank=True, null=True, help_text=_('退款时间')) # 微信统一下单 unifiedorder_result = models.TextField(_('unifiedorder_result'), blank=True, null=True, help_text=_('统一下单结果')) # 微信支付回调 notify_msg = models.TextField(_('notify_msg'), blank=True, null=True, help_text='回调信息') class Meta: verbose_name = _('直播间订单') verbose_name_plural = _('直播间订单') def __unicode__(self): return self.pk @property def admindata(self): room = RoomInfo.objects.get(room_id=self.room_id) anchor = AnchorInfo.objects.get(anchor_id=self.anchor_id) goods = liveGoodsInfo.objects.get(goods_id=self.goods_id) return { 'order_id': self.order_id, 'transaction_id': self.transaction_id, 'user_id': self.user_id, 'room_id': self.room_id, 'room_name': room.name, 'anchor_id': self.anchor_id, 'anchor_name': anchor.anchor_name, 'goods_id': self.goods_id, 'goods_name': goods.name, 'goods_img': goods.goods_img_url, 'name': self.name, 'phone': self.phone, 'province': self.province, 'city': self.city, 'county': self.county, 'address': self.address, 'tracking_number': self.tracking_number, 'amount': self.amount, 'total_fee': self.total_fee, 'pay_status': self.pay_status, 'paid_at': tc.local_string(utc_dt=self.paid_at, format='%Y-%m-%d %H:%M'), }