six_001
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
from django.db import models
|
||||
from uuid6 import uuid8
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
|
||||
class wecom企微用户标签(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
idKeywecom企微用户标签 = models.UUIDField(primary_key=True, default=uuid8)
|
||||
id_str = models.CharField(max_length=128, default=generator.generate_str)
|
||||
groupTag标签组ID = models.CharField(max_length=128, db_comment="标签组名")
|
||||
groupTag标签组名 = models.CharField(max_length=128, db_comment="标签组名")
|
||||
groupTag标签创建时间 = models.IntegerField()
|
||||
tag子标签ID = models.CharField(max_length=128, )
|
||||
tag子标签名称 = models.CharField(max_length=128, )
|
||||
tag子标签创建时间 = models.IntegerField()
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "wecom企微用户标签" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = ["-dateAndTime", "-updateTime"]
|
||||
@@ -0,0 +1,18 @@
|
||||
from django.db import models
|
||||
from uuid6 import uuid8
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name
|
||||
|
||||
|
||||
class wecom素材库(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
idKeywecom素材库 = models.UUIDField(primary_key=True, default=uuid8)
|
||||
address = models.JSONField()
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "wecom素材库" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = ["-idKeywecom素材库"]
|
||||
@@ -0,0 +1,36 @@
|
||||
# 企微用户的数据表
|
||||
from django.db import models
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
defautl_img = (
|
||||
"https://oss.fujugongxiang.com/six/%E7%A6%8F%E8%81%9A%E8%B4%A1%E7%BF%94%E5%B0%8F%E7%A8%8B%E5%BA%8F/home%E9%A1%B5%E9%9D%A2%E4%B8%BB%E5"
|
||||
"%9B%BE/%E5%A4%B4%E5%83%8F.png")
|
||||
|
||||
|
||||
class wecom企微用户(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
idKeyWecom企微用户 = models.CharField(primary_key=True, default=generator.generate_str, )
|
||||
wecom企微ID = models.CharField(max_length=128, )
|
||||
wecom企微状态State = models.CharField(max_length=128, default="", null=True)
|
||||
wecom对好友打的标签 = models.JSONField(default=list, blank=True, null=True, ) # 'tag_id': [],
|
||||
wecom对好友的备注名称 = models.CharField(max_length=128, ) # 'remark': '胡蝶',
|
||||
wecom对好友的添加时间 = models.BigIntegerField(blank=True, null=True, ) # 时间戳类型
|
||||
wecom对好友的备注信息 = models.CharField(max_length=128, default="")
|
||||
wecom企微对好友添加的手机号码 = models.JSONField(default=list, blank=True, null=True, ) # 'remark_mobiles': [],
|
||||
wecom企微好友添加方式 = models.CharField(max_length=128, ) # 'oper_userid': 'wmj4zANAAAGqQ7gHSPJb3yUw_PW6bXCg'
|
||||
wecom好友UNIONID = models.CharField(max_length=128, ) # 'unionid': 'oy4Jw6Lyfyj1VvgZFodzq9oqJzHE'
|
||||
wecom好友昵称 = models.CharField(max_length=128, ) # 'name': '胡蝶',
|
||||
wecom好友头像 = models.TextField(default="https://hudie.xiao.band/default_avacitve.jpeg") # 'avatar': 'http://wx.qlogo.cn/mmhead/hIz3ylFIYSibsiaymBicSrKXruslWCA0wcu9TNtnXbAeT8WpsthMVJfpj69h9bPHibC1NbFLzgUTnM0/0',
|
||||
wecom好友性别 = models.CharField(max_length=128, )
|
||||
wecom好友的ID = models.CharField(max_length=128, ) # 'external_userid': 'wmj4zANAAAGqQ7gHSPJb3yUw_PW6bXCg',
|
||||
wecom好友关系状态 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "wecom企微用户" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = ["-dateAndTime", "-updateTime"]
|
||||
@@ -0,0 +1,31 @@
|
||||
from django.db import models
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
|
||||
class wecom企微群(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
idKeyWecom企微群 = models.CharField(primary_key=True, default=generator.generate_str, )
|
||||
chat_id群 = models.CharField(max_length=128, )
|
||||
chat群名称 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
chat群主ID = models.CharField(max_length=128, blank=True, null=True, )
|
||||
chat群成员外部好友external_userid = models.CharField(max_length=128, blank=True, null=True, )
|
||||
chat群成员外部好友unionid = models.CharField(max_length=128, blank=True, null=True, )
|
||||
chat群成员外部好友名称 = models.CharField(max_length=128, blank=True, null=True, ) # 如果是微信用户,则返回其在微信中设置的名字
|
||||
chat群成员外部好友群名称 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
chat群成员外部好友类型 = models.IntegerField(blank=True, null=True, )
|
||||
# 1 - 由群成员邀请入群(直接邀请入群) 2 - 由群成员邀请入群(通过邀请链接入群) 3 - 通过扫描群二维码入群
|
||||
chat群成员外部好友加入方式 = models.IntegerField(blank=True, null=True, )
|
||||
chat群成员外部好友邀请者 = models.CharField(max_length=128, blank=True, null=True, ) # 邀请者目前仅当是由本企业内部成员邀请入群时会返回该值
|
||||
chat群管理员列表 = models.JSONField(default=list)
|
||||
chat群创建时间 = models.IntegerField(blank=True, null=True, ) # 时间戳
|
||||
chat群成员加入时间 = models.IntegerField(blank=True, null=True, )
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "wecom企微群" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = ["-dateAndTime", "-updateTime"]
|
||||
@@ -0,0 +1,29 @@
|
||||
from django.db import models
|
||||
from uuid6 import uuid8
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name, weiuser
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
|
||||
class wecom推广码(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
idKey = models.UUIDField(primary_key=True, default=uuid8)
|
||||
id_str = models.CharField(max_length=128, default=generator.generate_str)
|
||||
codeConfigId = models.CharField(max_length=128, )
|
||||
codeType = models.IntegerField(blank=True, null=True, ) # 联系方式类型,1-单人, 2-多人
|
||||
codeQrCode = models.CharField(max_length=256, blank=True, null=True, ) # 二维码图片链接
|
||||
codeRemark = models.CharField(max_length=128, blank=True, null=True, ) # 备注的信息
|
||||
codeState = models.CharField(max_length=128, blank=True, null=True, ) # 唯一的值(重要)
|
||||
codeUser = models.JSONField(blank=True, null=True, ) # 使用该联系方式的用户userID列表,在type为1时为必填,且只能有一个
|
||||
code省 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
code市 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
code区 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
wai外键weiuser表 = models.ForeignKey(to=weiuser, on_delete=models.CASCADE, )
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "wecom推广码" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = ["-dateAndTime", "-updateTime"]
|
||||
@@ -0,0 +1,28 @@
|
||||
from django.db import models
|
||||
from uuid6 import uuid8
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
|
||||
class weiuser地图定位(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
idKey = models.UUIDField(primary_key=True, default=uuid8)
|
||||
id_str = models.CharField(max_length=128, default=generator.generate_str)
|
||||
map用户uniond = models.CharField(max_length=128, )
|
||||
map用户openid = models.CharField(max_length=128, )
|
||||
map经度longitude = models.DecimalField(max_digits=10, decimal_places=6, blank=True, null=True, )
|
||||
map纬度latitude = models.DecimalField(max_digits=10, decimal_places=6, blank=True, null=True, )
|
||||
map省 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
map市 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
map区 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
map街道 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
map街道号码 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "weiuser地图定位" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = ["dateAndTime", "updateTime"]
|
||||
@@ -0,0 +1,22 @@
|
||||
from django.db import models
|
||||
from uuid6 import uuid8
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
|
||||
class map地图IP转地址(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
id_map = models.UUIDField(primary_key=True, default=uuid8)
|
||||
id_str = models.CharField(max_length=128, default=generator.generate_str)
|
||||
map用户unionid = models.CharField(max_length=128, )
|
||||
map用户openid = models.CharField(max_length=128, )
|
||||
map解析结果 = models.JSONField()
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "map地图IP转地址" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = ["-id_map"]
|
||||
@@ -0,0 +1,20 @@
|
||||
from django.db import models
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
|
||||
class miniSub订阅消息模板(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
idKey = models.CharField(primary_key=True, default=generator.generate_str, )
|
||||
sub订阅用户ID = models.CharField(max_length=128, ) # 小程序的openid
|
||||
sub订阅次数 = models.IntegerField(default=0)
|
||||
sub订阅模板ID = models.CharField(max_length=128, )
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "miniSub订阅消息模板" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = ["dateAndTime", "updateTime"]
|
||||
@@ -0,0 +1,80 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from uuid6 import uuid8
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
|
||||
class WechatTransferOrder(models.Model):
|
||||
"""
|
||||
微信商家转账订单记录表
|
||||
用于存储发起请求参数、微信返回的中间状态以及最终回调结果
|
||||
"""
|
||||
|
||||
# === 核心业务字段 ===
|
||||
|
||||
# 商户单据号 (发起时生成,全局唯一)
|
||||
class TransferOrderState(models.TextChoices):
|
||||
"""
|
||||
商家转账订单状态枚举
|
||||
涵盖发起时的中间状态和回调时的终态
|
||||
"""
|
||||
# --- 中间状态 (非终态) ---
|
||||
ACCEPTED = "ACCEPTED", _("已受理 (可原单重试)")
|
||||
PROCESSING = "PROCESSING", _("资金锁定中")
|
||||
WAIT_USER_CONFIRM = "WAIT_USER_CONFIRM", _("待用户确认")
|
||||
TRANSFERING = "TRANSFERING", _("转账中")
|
||||
CANCELING = "CANCELING", _("撤销中")
|
||||
# --- 终态 ---
|
||||
SUCCESS = "SUCCESS", _("转账成功")
|
||||
FAIL = "FAIL", _("转账失败")
|
||||
CANCELLED = "CANCELLED", _("已撤销")
|
||||
|
||||
id_主键_转账 = models.UUIDField(primary_key=True, default=uuid8, editable=True, )
|
||||
id_str = models.CharField(max_length=128, default=generator.generate_str)
|
||||
out_bill_no = models.CharField(max_length=120)
|
||||
# 微信转账单号 (回调时返回,发起时可能为空或为预生成值)
|
||||
transfer_bill_no = models.CharField(max_length=64, db_comment="微信转账单号", blank=True, null=True, )
|
||||
|
||||
# 订单状态
|
||||
state = models.CharField(max_length=32, choices=TransferOrderState, )
|
||||
|
||||
# 转账金额 (单位:分)
|
||||
transfer_amount = models.IntegerField(db_comment="转账金额(分)", )
|
||||
|
||||
# 收款用户 OpenID
|
||||
openid = models.CharField(max_length=64, db_comment="收款用户OpenID", blank=True, null=True, )
|
||||
|
||||
# 商户号
|
||||
mch_id = models.CharField(max_length=32, db_comment="商户号", blank=True, null=True, )
|
||||
|
||||
# === 异常与扩展字段 ===
|
||||
|
||||
# 失败原因 (仅在 state=FAIL 时有值)
|
||||
fail_reason = models.CharField(max_length=128, db_comment="失败原因代码", blank=True, null=True, )
|
||||
|
||||
# 失败详细描述 (可选,如果需要存储更详细的错误信息)
|
||||
fail_message = models.TextField(db_comment="失败详细描述", blank=True, null=True)
|
||||
|
||||
# 加密包信息 (发起时返回,用于特定场景下的重试或解密)
|
||||
package_info = models.TextField(db_comment="加密包信息", blank=True, null=True, )
|
||||
|
||||
# === 时间字段 ===
|
||||
|
||||
# 微信返回的创建时间 (发起接口返回的 create_time)
|
||||
wx_create_time = models.DateTimeField(db_comment="微信单据创建时间", null=True, blank=True)
|
||||
|
||||
# 微信返回的更新时间 (回调接口返回的 update_time)
|
||||
wx_update_time = models.DateTimeField(db_comment="微信单据更新时间", null=True, blank=True)
|
||||
|
||||
# 业务创建时间 (本地记录创建时间)
|
||||
created_at = models.DateTimeField(auto_now_add=True, db_comment="本地创建时间")
|
||||
|
||||
# 本地最后更新时间 (每次状态变更自动更新)
|
||||
updated_at = models.DateTimeField(auto_now=True, db_comment="本地最后更新时间")
|
||||
|
||||
class Meta:
|
||||
db_table = "WechatTransferOrder" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
# 联合索引优化查询:常按状态和创建时间查询
|
||||
app_label = models_app_name
|
||||
@@ -0,0 +1,79 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy
|
||||
from uuid6 import uuid8
|
||||
|
||||
from django_定时器.幸运拼团数据库 import lucky拼团
|
||||
from wechat_数据库.洗衣液商品数据库.六果洗衣液商品 import goods商品Choices
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
|
||||
class order订单(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
|
||||
class order订单choosies物流状态(models.TextChoices):
|
||||
待发货 = "待发货", gettext_lazy("待发货") # 用户支付订单时的状态
|
||||
待揽件 = "待揽件", gettext_lazy("待揽件") # 用户支付成功后的状态
|
||||
已发货 = "已发货", gettext_lazy("已发货") # 物流状态变为 已揽件时的状态
|
||||
已签收 = "已签收", gettext_lazy("已签收") # 物流状态变为 用户已签收时的状态
|
||||
待评价 = "待评价", gettext_lazy("待评价") # 交易完成后 的状态
|
||||
待收货 = "待收货", gettext_lazy("待收货") # 物流签收后, 小程序发出来的状态
|
||||
|
||||
id_主键_order订单 = models.UUIDField(primary_key=True, default=uuid8)
|
||||
id_str = models.CharField(max_length=128, default=generator.generate_str)
|
||||
order支付商家侧订单号 = models.CharField(max_length=128)
|
||||
order支付微信官方订单号 = models.CharField(max_length=128, null=True, blank=True)
|
||||
order支付者openid = models.CharField(max_length=128)
|
||||
order支付者unionid = models.CharField(max_length=128)
|
||||
order分享者unionid = models.CharField(max_length=128, default="六果")
|
||||
wai外键lucky拼团表 = models.ForeignKey(to=lucky拼团, on_delete=models.CASCADE, blank=True, null=True, )
|
||||
# order商品ID = models.CharField( max_length=128, )
|
||||
order购物车商品数据 = models.JSONField(default=list, null=True, blank=True)
|
||||
order购物车商品总价 = models.IntegerField()
|
||||
order购物车商品数量 = models.IntegerField()
|
||||
order支付数据 = models.JSONField(default=dict)
|
||||
order支付状态 = models.CharField(max_length=128, default="支付中")
|
||||
order用户配送地址 = models.JSONField(default=dict)
|
||||
order物流状态 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
order物流订单号 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
order物流数据 = models.JSONField(default=dict)
|
||||
order订单类型 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
order物流公司订单编号 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "order订单" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = ["-id_主键_order订单"]
|
||||
|
||||
|
||||
class order订单商品数据(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
|
||||
order订单商品数_id = models.UUIDField(primary_key=True, default=uuid8)
|
||||
order_id_str = models.CharField(max_length=128, default=generator.generate_str)
|
||||
order_id商品 = models.CharField(max_length=128, default=generator.generate_str)
|
||||
order_订单数量 = models.IntegerField(null=True, blank=True)
|
||||
order订单总金额 = models.IntegerField(null=True, blank=True)
|
||||
order_商品品牌 = models.CharField(max_length=128, )
|
||||
order_商品标题 = models.CharField(max_length=128, )
|
||||
order_商品信息 = models.JSONField(null=True, blank=True)
|
||||
order_商品标签 = models.JSONField(null=True, blank=True)
|
||||
order_商品详情图片 = models.JSONField(null=True, blank=True)
|
||||
order_商品销售规格 = models.JSONField(null=True, blank=True, )
|
||||
order_商品销售场景 = models.CharField(max_length=128, choices=goods商品Choices, null=True, blank=True,
|
||||
default=goods商品Choices.商城商品.value)
|
||||
order_分享积分 = models.JSONField(null=True, blank=True, )
|
||||
order_商品搜索标签 = models.JSONField(null=True, blank=True, )
|
||||
order_商家推荐标签 = models.JSONField(null=True, blank=True, )
|
||||
order_其它参数 = models.JSONField(null=True, blank=True)
|
||||
wai_订单 = models.ForeignKey(to=order订单, on_delete=models.CASCADE, null=True, blank=True)
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "order订单商品数据" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
@@ -0,0 +1,79 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy
|
||||
from ulid import ULID
|
||||
from uuid6 import uuid8
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class goods商品Choices( models.TextChoices ):
|
||||
幸运拼团 = "幸运拼团", gettext_lazy( "幸运拼团" )
|
||||
商城商品 = "商城商品", gettext_lazy( "商城商品" )
|
||||
赢免单 = "赢免单", gettext_lazy( "赢免单" )
|
||||
|
||||
|
||||
|
||||
|
||||
class goods商品( models.Model ):
|
||||
"""城市信息表"""
|
||||
|
||||
objects = models.Manager( ) #
|
||||
id_主键_goods商品 = models.UUIDField( primary_key=True, default=uuid8 )
|
||||
id_str = models.CharField( max_length=128, default=generator.generate_str )
|
||||
goods商品数据 = models.JSONField( )
|
||||
goods商品类型 = models.CharField( max_length=128, choices=goods商品Choices,
|
||||
default=goods商品Choices.商城商品.value )
|
||||
dateAndTime = models.DateTimeField( auto_now_add=True, db_comment="创建时间" ) # 数据创建时间
|
||||
updateTime = models.DateTimeField( auto_now=True, db_comment="更新时间" ) # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "goods商品" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = [ "dateAndTime", "updateTime" ]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Goods( models.Model ):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager( ) #
|
||||
|
||||
idKey = models.UUIDField( primary_key=True, default=uuid8 )
|
||||
goods_id商品 = models.CharField( max_length=128, default=ULID)
|
||||
goods_商品品牌 = models.CharField( max_length=128, )
|
||||
goods_商品标题 = models.CharField( max_length=128, )
|
||||
goods_商品信息 = models.JSONField( default=dict, null=True, blank=True )
|
||||
goods_商品标签 = models.JSONField( default=list, null=True, blank=True )
|
||||
goods_商品销售规格 = models.JSONField( null=True, blank=True, default=list )
|
||||
goods_商品销售场景 = models.CharField( max_length=128, choices=goods商品Choices, null=True, blank=True )
|
||||
goods_商品搜索标签 = models.JSONField( null=True, blank=True, default=list )
|
||||
goods_商家推荐标签 = models.JSONField( null=True, blank=True, default=list )
|
||||
goods_其它参数 = models.JSONField( null=True, blank=True )
|
||||
dateAndTime = models.DateTimeField( auto_now_add=True, db_comment="创建时间" ) # 数据创建时间
|
||||
updateTime = models.DateTimeField( auto_now=True, db_comment="更新时间" ) # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "Goods" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
洗衣液商品数据 = {
|
||||
"商品销售参数": [ { "价格": 300, "会员价": 280, "销售规格": "8斤装" },
|
||||
{ "价格": 500, "会员价": 380, "销售规格": "20斤装" }, ],
|
||||
"销售数量": 1,
|
||||
"商品标题": "六果香 8斤装(超划算) 源自天然酵素迅速渗入衣物,去除99种污渍99%除菌🦠一洗即净,守护健康",
|
||||
"商品信息参数": {
|
||||
"品牌": "六果香", "净重": "8斤装", "香型": "熏衣草",
|
||||
"洁净": "源自天然酵素迅速渗入衣物,去除99种污渍", "除菌🦠": "99%除菌🦠,污渍菌螨,一洗即净,守护健康",
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy
|
||||
from uuid6 import uuid8
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name, weiuser
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
|
||||
class weiuser微信用户地址(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
|
||||
class choicesAddress(models.TextChoices):
|
||||
是默认地址 = "是默认地址", gettext_lazy("是默认地址")
|
||||
不是默认地址 = "不是默认地址", gettext_lazy("不是默认地址")
|
||||
|
||||
# idKey = models.CharField(primary_key=True, default=generator.generate_str, )
|
||||
id_主键_配送地址 = models.UUIDField(primary_key=True, default=uuid8)
|
||||
id_str = models.CharField(max_length=128, default=generator.generate_str)
|
||||
mini_openid = models.CharField()
|
||||
mini_unionid = models.CharField()
|
||||
address = models.JSONField()
|
||||
# key_weiuser = models.ForeignKey(to=weiuser, on_delete=models.SET_NULL, null=True,blank=True, ) ## 删除用户时,级联删除地址
|
||||
isDefaultAddress = models.CharField(choices=choicesAddress, max_length=120, )
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "weiuser微信用户地址" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = ["-id_主键_配送地址", ]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
user = weiuser.objects.get(unionid="")
|
||||
@@ -0,0 +1,207 @@
|
||||
"""注释"""
|
||||
from django.db import models
|
||||
from uuid6 import uuid8
|
||||
|
||||
from wechat_数据库.雪花算法.雪花算法工具 import generator
|
||||
|
||||
"""
|
||||
输入 :当前用户实例(self)
|
||||
输出 :包含所有下级用户的 扁平化列表 (多级结构被展开)
|
||||
递归逻辑 :
|
||||
先获取当前用户的直接下级(通过 self.subordinates.all())
|
||||
对每个下级用户 递归调用自身,继续向下查找
|
||||
合并所有结果到一个列表中
|
||||
用户A
|
||||
├─ 用户B
|
||||
│ ├─ 用户C
|
||||
│ └─ 用户D
|
||||
└─ 用户E
|
||||
|
||||
[用户B, 用户C, 用户D, 用户E] # 按深度优先顺序
|
||||
语法: wei = weiuser.objects.get(unionid="元宝零售")
|
||||
print( wei.get_all_subordinates( ) )
|
||||
结果: [<weiuser: weiuser object (oy4Jw6A1T3WkKOOhMxcbQTDSM8rs)>]
|
||||
|
||||
"""
|
||||
defautl_img = (
|
||||
"https://oss.fujugongxiang.com/six/%E7%A6%8F%E8%81%9A%E8%B4%A1%E7%BF%94%E5%B0%8F%E7%A8%8B%E5%BA%8F/home%E9%A1%B5%E9%9D%A2%E4%B8%BB%E5"
|
||||
"%9B%BE/%E5%A4%B4%E5%83%8F.png")
|
||||
|
||||
from django.utils.translation import gettext_lazy
|
||||
|
||||
models_app_name = "django_app"
|
||||
|
||||
|
||||
class weiuser用户角色表choicesStatus(models.TextChoices):
|
||||
"""商家转账订单状态"""
|
||||
推广员 = "推广员", gettext_lazy("推广员")
|
||||
企微员工 = "企微员工", gettext_lazy("企微员工")
|
||||
无状态 = "无状态", gettext_lazy("无状态")
|
||||
普通会员 = "普通会员", gettext_lazy("普通会员")
|
||||
六果科技有限公司 = "六果科技有限公司", gettext_lazy("六果科技有限公司")
|
||||
群好友 = "群好友", gettext_lazy("群好友")
|
||||
|
||||
|
||||
class weiuser(models.Model):
|
||||
"""用户基础信息表"""
|
||||
objects = models.Manager() #
|
||||
|
||||
class ChoicesStatus(models.TextChoices):
|
||||
"""商家转账订单状态"""
|
||||
推广员 = "推广员", gettext_lazy("推广员")
|
||||
企微员工 = "企微员工", gettext_lazy("企微员工")
|
||||
无状态 = "无状态", gettext_lazy("无状态")
|
||||
|
||||
unionid = models.CharField(primary_key=True, max_length=120)
|
||||
user_角色权限 = models.CharField(choices=weiuser用户角色表choicesStatus, default=weiuser用户角色表choicesStatus.普通会员)
|
||||
user_企微角色权限 = models.CharField(max_length=128, null=True, blank=True, )
|
||||
mini_openid = models.CharField(max_length=100, db_comment="自身id", null=True, blank=True, unique=True)
|
||||
wechat_openid = models.CharField(max_length=100, db_comment="服务号自身id", null=True, blank=True, unique=True)
|
||||
wecom_openid = models.CharField(max_length=100, db_comment="企微自身id", null=True, blank=True, unique=True)
|
||||
external_userid = models.CharField(max_length=100, db_comment="外部联系人ID", null=True, blank=True, )
|
||||
uesr_手机号码 = models.CharField(null=True, blank=True, )
|
||||
user_昵称 = models.CharField(max_length=120, db_comment="用户的昵称", default="匿名用户")
|
||||
user_头像 = models.CharField(max_length=245, db_comment="用户头像",
|
||||
default="https://hudie.xiao.band/%E6%9C%AA%E5%91%BD%E5%90%8D.png")
|
||||
user_用户当前的等级 = models.IntegerField(default=1, ) # 自身的等级
|
||||
user_省份 = models.CharField(max_length=128, null=True, blank=True, )
|
||||
user_城市 = models.CharField(max_length=128, null=True, blank=True, )
|
||||
user_区县 = models.CharField(max_length=128, null=True, blank=True, )
|
||||
user_街道信息 = models.CharField(max_length=128, null=True, blank=True, )
|
||||
user_绑定企微usrID账号 = models.CharField(max_length=128, null=True, blank=True, )
|
||||
user_绑定企微UNIONID = models.CharField(max_length=128, null=True, blank=True, )
|
||||
user_IP地址 = models.GenericIPAddressField(null=True, blank=True, )
|
||||
user_绑定用工关系 = models.CharField(max_length=128, null=True, blank=True, )
|
||||
codeConfigId = models.TextField(blank=True, null=True, ) # 企微的标签ID
|
||||
codeQrCode = models.TextField(blank=True, null=True, ) # 企微的二维码
|
||||
codeRemark = models.TextField(blank=True, null=True, ) # 企微备注的信息
|
||||
parent = models.ForeignKey(to="self", on_delete=models.SET_NULL, related_name="children", null=True,
|
||||
blank=True, ) # 模式:保护模式,有数据话是不能删除的;
|
||||
add_time = models.DateTimeField(null=True, blank=True, db_comment="用户添加好友的时间")
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "weiuser" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
ordering = ["-dateAndTime", "-updateTime"]
|
||||
|
||||
def get_all_subordinates(self):
|
||||
"""递归获取所有下级(包括间接下级)"""
|
||||
subs = []
|
||||
for sub in self.children.all():
|
||||
subs.append(sub)
|
||||
subs.extend(sub.get_all_subordinates())
|
||||
return subs
|
||||
|
||||
# ↓↓↓ 新增方法:获取所有上级(递归实现)↓↓↓
|
||||
def get_all_superiors(self):
|
||||
"""
|
||||
返回列表格式:[直接上级, 上上级, 上上上级...]
|
||||
"""
|
||||
superiors = []
|
||||
# 递归终止条件:没有上级时停止
|
||||
if self.parent:
|
||||
superiors.append(self.parent)
|
||||
# 递归获取上级的上级
|
||||
superiors.extend(self.parent.get_all_superiors())
|
||||
return superiors
|
||||
|
||||
def get_nth_level_superior(self, n):
|
||||
"""
|
||||
获取第n级上级
|
||||
:param n: 上级层级 (1=直接上级, 2=上上级, 以此类推)
|
||||
:return: Weiuser对象或None
|
||||
"""
|
||||
"""
|
||||
获取当前用户往上 n 级的父元素
|
||||
:param n: 要查询的上级层级数 (必须 >=1)
|
||||
:return: weiuser 对象或 None (如果不存在)
|
||||
"""
|
||||
if n < 1:
|
||||
raise ValueError("n 必须大于或等于 1")
|
||||
|
||||
current = self
|
||||
# 循环向上查询 n 次
|
||||
for _ in range(n):
|
||||
if not current.parent:
|
||||
return None # 没有父级时提前终止
|
||||
current = current.parent
|
||||
return current
|
||||
|
||||
"""
|
||||
这种实现方式更加简洁,但需要注意:
|
||||
它使用了链式递归调用,可能会增加递归深度
|
||||
每次递归都会重新检查字段是否存在,虽然安全但效率稍低
|
||||
性能考虑
|
||||
对于树形结构操作,递归实现通常更简洁,但在实际应用中需要注意:
|
||||
Python递归深度限制:默认1000层,可通过sys.setrecursionlimit()调整
|
||||
性能开销:递归调用比循环有更高的开销
|
||||
内存使用:递归会占用更多栈空间
|
||||
在大多数实际应用中,树结构的深度不会超过100层,因此递归实现通常是可行的。但如果预期树结构会非常深(如超过1000层),建议使用循环实现或混合实现。
|
||||
"""
|
||||
|
||||
def find_ancestor_by_field(self, field_name, target_value, include_self=False):
|
||||
"""
|
||||
从当前用户向上查找,找到第一个指定字段等于目标值的祖先
|
||||
:param field_name: 要查找的字段名
|
||||
:param target_value: 目标值
|
||||
:param include_self: 是否包含自身
|
||||
:return: Weiuser对象或None
|
||||
"""
|
||||
# 验证字段名是否有效 - 修复方法
|
||||
if not hasattr(self, field_name):
|
||||
raise ValueError(f"无效字段名: {field_name}")
|
||||
|
||||
# 如果包含自身且满足条件,直接返回
|
||||
if include_self and getattr(self, field_name) == target_value:
|
||||
return self
|
||||
|
||||
# 向上遍历祖先
|
||||
current = self.parent
|
||||
while current:
|
||||
if getattr(current, field_name) == target_value:
|
||||
return current
|
||||
current = current.parent
|
||||
return None
|
||||
|
||||
def find查找指定的上级(self, field_name, target_value, include_self=False):
|
||||
"""
|
||||
从当前用户向上查找,找到第一个指定字段等于目标值的祖先
|
||||
:param field_name: 要查找的字段名
|
||||
:param target_value: 目标值
|
||||
:param include_self: 是否包含自身
|
||||
:return: Weiuser对象或None
|
||||
"""
|
||||
# 验证字段名是否有效 - 修复方法
|
||||
if not hasattr(self, field_name):
|
||||
raise ValueError(f"无效字段名: {field_name}")
|
||||
|
||||
# 如果包含自身且满足条件,直接返回
|
||||
if include_self and getattr(self, field_name) == target_value:
|
||||
return self
|
||||
|
||||
# 向上遍历祖先
|
||||
current = self.parent
|
||||
while current:
|
||||
if getattr(current, field_name) == target_value:
|
||||
return current
|
||||
current = current.parent
|
||||
return None
|
||||
|
||||
|
||||
# class weiuser用户角色表(models.Model):
|
||||
# """城市信息表"""
|
||||
# objects = models.Manager() #
|
||||
# idKeyweiuser用户角色表 = models.UUIDField(primary_key=True, default=uuid8)
|
||||
# id_str = models.CharField(max_length=128, default=generator.generate_str)
|
||||
# user用户角色名称 = models.CharField(max_length=128, choices=weiuser用户角色表choicesStatus,
|
||||
# default=weiuser用户角色表choicesStatus.普通会员.value)
|
||||
# user用户的unionid = models.CharField(max_length=128, )
|
||||
# dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
# updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
#
|
||||
# class Meta:
|
||||
# db_table = "weiuser用户角色表" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
# app_label = models_app_name
|
||||
# ordering = ["-dateAndTime", "-updateTime"]
|
||||
@@ -0,0 +1,48 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy
|
||||
from ulid import ULID
|
||||
from uuid6 import uuid8
|
||||
|
||||
from wechat_数据库.用户数据库.小程序登陆用户 import models_app_name
|
||||
|
||||
|
||||
class share积分类型choosies(models.TextChoices):
|
||||
商品详情分享群好友 = "商品详情分享群好友", gettext_lazy("商品详情分享群好友")
|
||||
幸运拼团分享 = "幸运拼团分享", gettext_lazy("幸运拼团分享")
|
||||
好友支付助力 = "好友支付助力", gettext_lazy("好友支付助力")
|
||||
每日签到 = "每日签到", gettext_lazy("每日签到")
|
||||
首次添加企微好友 = "首次添加企微好友", gettext_lazy("首次添加企微好友")
|
||||
推荐好友添加企微 = "推荐好友添加企微", gettext_lazy("推荐好友添加企微")
|
||||
|
||||
|
||||
class share积分表(models.Model):
|
||||
"""城市信息表"""
|
||||
objects = models.Manager() #
|
||||
|
||||
id_主键 = models.UUIDField(primary_key=True, default=uuid8)
|
||||
id_str = models.CharField(max_length=128, default=ULID)
|
||||
share分享者unionid = models.CharField(max_length=128, )
|
||||
share分享者openid = models.CharField(max_length=128, blank=True, null=True, )
|
||||
share分享类型 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
share分享者昵称 = models.CharField(max_length=128, blank=True, null=True, )
|
||||
share分享者头像 = models.TextField(blank=True, null=True, )
|
||||
share分享者积分值 = models.IntegerField(default=0)
|
||||
share点击者unionid = models.CharField(max_length=128, blank=True, null=True, )
|
||||
share点击者openid = models.CharField(max_length=128, blank=True, null=True, )
|
||||
share点击者昵称 = models.CharField(max_length=128)
|
||||
share点击者头像 = models.TextField(null=True, blank=True, )
|
||||
share分享的商品ID = models.CharField(null=True, blank=True, )
|
||||
share支付订单商家侧的订单号 = models.CharField(max_length=128, null=True, blank=True, )
|
||||
share支付用户提现状态 = models.CharField(max_length=128, null=True, blank=True, )
|
||||
share支付微信侧返回的提现状态 = models.CharField(max_length=128, null=True, blank=True, )
|
||||
share支付提现微信公司生成的转账数据 = models.JSONField(null=True, blank=True, default=dict)
|
||||
share积分是否可以提现的状态 = models.CharField(null=True, blank=True, )
|
||||
|
||||
share日期 = models.DateField(blank=True, null=True)
|
||||
share日期时间 = models.DateTimeField(blank=True, null=True, )
|
||||
dateAndTime = models.DateTimeField(auto_now_add=True, db_comment="创建时间") # 数据创建时间
|
||||
updateTime = models.DateTimeField(auto_now=True, db_comment="更新时间") # 更新时间(需要用 save() )
|
||||
|
||||
class Meta:
|
||||
db_table = "share积分表" # 给数据表自定义一个名称;默认的会是在 应用名+类名
|
||||
app_label = models_app_name
|
||||
@@ -0,0 +1,70 @@
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
||||
class SnowflakeIDGenerator:
|
||||
# 目标:总比特数约40位,十进制最多12位(2^40 ≈ 1.1e12)
|
||||
# 时间戳用28位(可覆盖约8.5年),机器ID用6位(64台),序列号用6位(每毫秒64个)
|
||||
TIMESTAMP_BITS = 28
|
||||
WORKER_ID_BITS = 6
|
||||
SEQUENCE_BITS = 6
|
||||
|
||||
# 起始时间戳(2025-01-01 00:00:00 UTC),单位毫秒
|
||||
CUSTOM_EPOCH = 1735689600000
|
||||
|
||||
MAX_WORKER_ID = -1 ^ (-1 << WORKER_ID_BITS)
|
||||
MAX_SEQUENCE = -1 ^ (-1 << SEQUENCE_BITS)
|
||||
|
||||
# 移位计算
|
||||
WORKER_ID_SHIFT = SEQUENCE_BITS
|
||||
TIMESTAMP_SHIFT = SEQUENCE_BITS + WORKER_ID_BITS
|
||||
|
||||
def __init__(self, worker_id, sequence=0):
|
||||
if worker_id > self.MAX_WORKER_ID or worker_id < 0:
|
||||
raise ValueError(f"Worker ID must be between 0 and {self.MAX_WORKER_ID}")
|
||||
self.worker_id = worker_id
|
||||
self.sequence = sequence
|
||||
self.last_timestamp = -1
|
||||
self.lock = threading.Lock()
|
||||
|
||||
def _wait_next_ms(self, last_ts):
|
||||
ts = self._now()
|
||||
while ts <= last_ts:
|
||||
ts = self._now()
|
||||
return ts
|
||||
|
||||
def _now(self):
|
||||
return int(time.time() * 1000)
|
||||
|
||||
def generate_id(self):
|
||||
with self.lock:
|
||||
ts = self._now()
|
||||
if ts < self.last_timestamp:
|
||||
raise Exception("Clock moved backwards")
|
||||
if ts == self.last_timestamp:
|
||||
self.sequence = (self.sequence + 1) & self.MAX_SEQUENCE
|
||||
if self.sequence == 0:
|
||||
ts = self._wait_next_ms(self.last_timestamp)
|
||||
else:
|
||||
self.sequence = 0
|
||||
self.last_timestamp = ts
|
||||
|
||||
# 相对时间(毫秒),只取低TIMESTAMP_BITS位
|
||||
relative_ts = (ts - self.CUSTOM_EPOCH) & ((1 << self.TIMESTAMP_BITS) - 1)
|
||||
new_id = (relative_ts << self.TIMESTAMP_SHIFT) | \
|
||||
(self.worker_id << self.WORKER_ID_SHIFT) | \
|
||||
self.sequence
|
||||
return new_id
|
||||
|
||||
def generate_str(self):
|
||||
return str(self.generate_id())
|
||||
|
||||
|
||||
# 全局生成器实例 (worker_id和datacenter_id需在分布式环境中保证唯一)
|
||||
# 单机开发环境可暂时固定,生产环境建议通过配置中心或启动参数传入
|
||||
generator = SnowflakeIDGenerator(worker_id=1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(generator.generate_id())
|
||||
print(type(generator.generate_id()))
|
||||
print(generator.generate_str())
|
||||
Reference in New Issue
Block a user