加入了 GVSDSDK 模块,进行了 QModel 兼容层的尝试,生产环境可用
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from django.db import models
|
||||
from gvsdsdk.model_base import QModel
|
||||
|
||||
|
||||
# ==================== 1. 角色表 ====================
|
||||
class Role(models.Model):
|
||||
class Role(QModel):
|
||||
"""角色表"""
|
||||
role_id = models.AutoField(primary_key=True, verbose_name='角色ID')
|
||||
role_code = models.CharField(max_length=50, unique=True, db_index=True, verbose_name='角色编码')
|
||||
@@ -25,7 +26,7 @@ class Role(models.Model):
|
||||
|
||||
|
||||
# ==================== 2. 权限表 ====================
|
||||
class Permission(models.Model):
|
||||
class Permission(QModel):
|
||||
"""权限表"""
|
||||
perm_id = models.AutoField(primary_key=True, verbose_name='权限ID')
|
||||
perm_code = models.CharField(max_length=100, unique=True, db_index=True, verbose_name='权限编码')
|
||||
@@ -47,7 +48,7 @@ class Permission(models.Model):
|
||||
|
||||
|
||||
# ==================== 3. 角色-权限关联表 ====================
|
||||
class RolePermission(models.Model):
|
||||
class RolePermission(QModel):
|
||||
"""角色权限关联表"""
|
||||
id = models.AutoField(primary_key=True)
|
||||
role = models.ForeignKey(Role, on_delete=models.CASCADE, db_index=True, verbose_name='角色')
|
||||
@@ -65,7 +66,7 @@ class RolePermission(models.Model):
|
||||
|
||||
|
||||
# ==================== 4. 用户-角色关联表 ====================
|
||||
class UserRole(models.Model):
|
||||
class UserRole(QModel):
|
||||
"""用户角色关联表"""
|
||||
id = models.AutoField(primary_key=True)
|
||||
account_id = models.CharField(max_length=11, db_index=True, verbose_name='账号ID') # 对应 UserMain 的 phone 字段
|
||||
@@ -83,7 +84,7 @@ class UserRole(models.Model):
|
||||
return f"{self.account_id} -> {self.role.role_name}"
|
||||
|
||||
|
||||
class AbnormalUserLog(models.Model):
|
||||
class AbnormalUserLog(QModel):
|
||||
"""记录恶意尝试越权操作的用户信息"""
|
||||
# 账号信息
|
||||
account_id = models.CharField(max_length=20, db_index=True, verbose_name='账号ID(phone)')
|
||||
@@ -126,7 +127,7 @@ class AbnormalUserLog(models.Model):
|
||||
|
||||
|
||||
|
||||
class ShangjiaRiTongji(models.Model):
|
||||
class ShangjiaRiTongji(QModel):
|
||||
yonghuid = models.CharField(max_length=7, db_index=True, verbose_name='商家用户ID')
|
||||
riqi = models.DateField(db_index=True, verbose_name='日期') # 年月日
|
||||
|
||||
@@ -156,7 +157,7 @@ class ShangjiaRiTongji(models.Model):
|
||||
|
||||
|
||||
|
||||
class DashouRiTongji(models.Model):
|
||||
class DashouRiTongji(QModel):
|
||||
yonghuid = models.CharField(max_length=7, db_index=True, verbose_name='打手用户ID')
|
||||
riqi = models.DateField(db_index=True, verbose_name='日期') # 年月日
|
||||
|
||||
@@ -185,7 +186,7 @@ class DashouRiTongji(models.Model):
|
||||
|
||||
|
||||
|
||||
class ZuzhangRiTongji(models.Model):
|
||||
class ZuzhangRiTongji(QModel):
|
||||
yonghuid = models.CharField(max_length=7, db_index=True, verbose_name='组长用户ID')
|
||||
riqi = models.DateField(db_index=True, verbose_name='日期') # 年月日
|
||||
|
||||
@@ -207,7 +208,7 @@ class ZuzhangRiTongji(models.Model):
|
||||
|
||||
|
||||
|
||||
class GuanshiRiTongji(models.Model):
|
||||
class GuanshiRiTongji(QModel):
|
||||
yonghuid = models.CharField(max_length=7, db_index=True, verbose_name='管事用户ID')
|
||||
riqi = models.DateField(db_index=True, verbose_name='日期') # 年月日
|
||||
|
||||
@@ -228,7 +229,7 @@ class GuanshiRiTongji(models.Model):
|
||||
|
||||
|
||||
|
||||
class GuanshiXufeiRiTongji(models.Model):
|
||||
class GuanshiXufeiRiTongji(QModel):
|
||||
yonghuid = models.CharField(max_length=7, db_index=True, verbose_name='管事用户ID')
|
||||
riqi = models.DateField(db_index=True, verbose_name='日期') # 年月日
|
||||
|
||||
@@ -248,7 +249,7 @@ class GuanshiXufeiRiTongji(models.Model):
|
||||
|
||||
# models.py 中添加
|
||||
|
||||
class TixianRiTongji(models.Model):
|
||||
class TixianRiTongji(QModel):
|
||||
"""
|
||||
每日提现统计表(按身份统计当天提现总额)
|
||||
"""
|
||||
|
||||
@@ -11,6 +11,7 @@ from .view import (GetRolePermissionView,
|
||||
ModifyProductTypeZoneView, GetRateView, ModifyRateView, PopupNoticeListAPIView, PopupNoticeModifyAPIView,ShopListView,
|
||||
ShopModifyView, ShopPublicTypeAndAuditView, ShopListForProductView, ShopProductModifyView,
|
||||
ShopProductTypeMappingView, ProductListView, ProductModifyView, KefuChatPermissionsView,
|
||||
FineApplyView, PunishDashouView,
|
||||
FaKuanTongJiView, FaKuanLieBiaoView, FaKuanChuLiView, FaKuanChuangJianView,
|
||||
HqbkxxView,BkxgView,CaiwuView,CwhybkhqView, HybkjtsjView, SzxxView, CwddhqlxView, CwhqjtddsjView,
|
||||
CwqtczhqView, KhpzhqView, ChzsgcView,KhgglView, ShgxgsjView, ZxkfghdsView)
|
||||
@@ -79,6 +80,8 @@ urlpatterns = [
|
||||
path('hthqfklb', FaKuanLieBiaoView.as_view(),name='后台罚单列表'), # 罚款列表
|
||||
path('glyclfk', FaKuanChuLiView.as_view(),name='后台罚单操作'), # 处理罚款
|
||||
path('htfksc', FaKuanChuangJianView.as_view(),name='后台生成罚单'), # 创建罚款
|
||||
path('kffkdssq', FineApplyView.as_view(), name='客服罚款申请'), # 客服罚款申请
|
||||
path('kpcf', PunishDashouView.as_view(), name='客服处罚打手'), # 客服处罚打手
|
||||
|
||||
path('hqbkxx', HqbkxxView.as_view(), name='获取板块数据'), # 获取板块数据
|
||||
path('bkxg', BkxgView.as_view(), name='板块增删改查'), # 板块增删改
|
||||
|
||||
@@ -13,6 +13,8 @@ from django.db.models import F
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
|
||||
from gvsdsdk.fluent import db, func, FQ
|
||||
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -39,7 +41,7 @@ def _record_abnormal(account_id, request, attempt_type, detail=''):
|
||||
request_params = json.dumps(request.query_params.dict(), ensure_ascii=False) if request.query_params else ''
|
||||
request_body = request.body.decode('utf-8', errors='ignore')[:5000]
|
||||
|
||||
AbnormalUserLog.objects.create(
|
||||
AbnormalUserLog.query.create(
|
||||
account_id=account_id,
|
||||
ip_address=real_ip,
|
||||
real_ip=real_ip,
|
||||
@@ -96,9 +98,9 @@ def verify_kefu_permission(request, username_from_frontend=None):
|
||||
|
||||
# ---------- 4. 获取用户的所有权限(通过角色) ----------
|
||||
# 步骤1:获取用户的所有角色ID
|
||||
role_ids = UserRole.objects.filter(account_id=current_user.phone).values_list('role_id', flat=True)
|
||||
role_ids = UserRole.query.filter(account_id=current_user.phone).values_list('role_id', flat=True)
|
||||
# 步骤2:通过角色ID获取权限编码
|
||||
permissions = list(Permission.objects.filter(
|
||||
permissions = list(Permission.query.filter(
|
||||
rolepermission__role_id__in=role_ids
|
||||
).values_list('perm_code', flat=True).distinct())
|
||||
|
||||
@@ -156,7 +158,7 @@ def update_dashou_daily_by_action(yonghuid, amount, action):
|
||||
return # 无效行为
|
||||
|
||||
if update_fields:
|
||||
DashouRiTongji.objects.filter(id=stat.id).update(**update_fields)
|
||||
DashouRiTongji.query.filter(id=stat.id).update(**update_fields)
|
||||
|
||||
|
||||
def update_shangjia_daily(yonghuid, amount, action):
|
||||
@@ -212,7 +214,7 @@ def update_shangjia_daily(yonghuid, amount, action):
|
||||
return
|
||||
|
||||
# 执行原子更新
|
||||
ShangjiaRiTongji.objects.filter(id=stat.id).update(**update_fields)
|
||||
ShangjiaRiTongji.query.filter(id=stat.id).update(**update_fields)
|
||||
|
||||
|
||||
|
||||
@@ -242,7 +244,7 @@ def update_guanshi_daily_by_action(yonghuid, action, amount=Decimal('0.00')):
|
||||
stat.yaoqing_dashou_shu = 1
|
||||
stat.save()
|
||||
else:
|
||||
GuanshiRiTongji.objects.filter(id=stat.id).update(
|
||||
GuanshiRiTongji.query.filter(id=stat.id).update(
|
||||
yaoqing_dashou_shu=F('yaoqing_dashou_shu') + 1
|
||||
)
|
||||
|
||||
@@ -255,7 +257,7 @@ def update_guanshi_daily_by_action(yonghuid, action, amount=Decimal('0.00')):
|
||||
stat.shouru_zonge = amount
|
||||
stat.save()
|
||||
else:
|
||||
GuanshiRiTongji.objects.filter(id=stat.id).update(
|
||||
GuanshiRiTongji.query.filter(id=stat.id).update(
|
||||
chongzhi_dashou_shu=F('chongzhi_dashou_shu') + 1,
|
||||
shouru_zonge=F('shouru_zonge') + amount
|
||||
)
|
||||
@@ -268,7 +270,7 @@ def update_guanshi_daily_by_action(yonghuid, action, amount=Decimal('0.00')):
|
||||
stat.shouru_zonge = amount
|
||||
stat.save()
|
||||
else:
|
||||
GuanshiRiTongji.objects.filter(id=stat.id).update(
|
||||
GuanshiRiTongji.query.filter(id=stat.id).update(
|
||||
shouru_zonge=F('shouru_zonge') + amount
|
||||
)
|
||||
|
||||
@@ -328,7 +330,7 @@ def update_guanshi_daily_by_action(yonghuid, action, amount=Decimal('0.00')):
|
||||
if action == 2:
|
||||
update_fields['shouru_zonge'] = F('shouru_zonge') + amount
|
||||
|
||||
GuanshiRiTongji.objects.filter(id=stat.id).update(**update_fields)'''
|
||||
GuanshiRiTongji.query.filter(id=stat.id).update(**update_fields)'''
|
||||
|
||||
def update_guanshi_xufei_daily(yonghuid, xufei_jine=Decimal('0.00')):
|
||||
"""
|
||||
@@ -348,7 +350,7 @@ def update_guanshi_xufei_daily(yonghuid, xufei_jine=Decimal('0.00')):
|
||||
}
|
||||
)
|
||||
if not created:
|
||||
GuanshiXufeiRiTongji.objects.filter(id=stat.id).update(
|
||||
GuanshiXufeiRiTongji.query.filter(id=stat.id).update(
|
||||
xufei_zongshu=F('xufei_zongshu') + 1,
|
||||
xufei_shouyi=F('xufei_shouyi') + xufei_jine
|
||||
)
|
||||
@@ -392,13 +394,13 @@ def update_zuzhang_daily_by_action(yonghuid, action, amount=Decimal('0.00')):
|
||||
else:
|
||||
# 已存在记录,使用 F 表达式原子累加
|
||||
if action == 1:
|
||||
ZuzhangRiTongji.objects.filter(id=stat.id).update(
|
||||
ZuzhangRiTongji.query.filter(id=stat.id).update(
|
||||
yaoqing_guanshi_shu=F('yaoqing_guanshi_shu') + 1
|
||||
)
|
||||
elif action == 2:
|
||||
amount = Decimal(str(amount)) if amount else Decimal('0.00')
|
||||
if amount > 0:
|
||||
ZuzhangRiTongji.objects.filter(id=stat.id).update(
|
||||
ZuzhangRiTongji.query.filter(id=stat.id).update(
|
||||
shouru_zonge=F('shouru_zonge') + amount,
|
||||
fenyong_jine=F('fenyong_jine') + amount
|
||||
)
|
||||
@@ -419,7 +421,7 @@ def update_tixian_daily_stat(leixing, amount):
|
||||
defaults={'total_amount': amount}
|
||||
)
|
||||
if not created:
|
||||
TixianRiTongji.objects.filter(id=stat.id).update(
|
||||
TixianRiTongji.query.filter(id=stat.id).update(
|
||||
total_amount=F('total_amount') + amount
|
||||
)
|
||||
|
||||
@@ -461,7 +463,7 @@ def _get_fadan_permission_config():
|
||||
perm_map = dict(_DEFAULT_FADAN_PERM_TO_SHENFEN)
|
||||
generic_codes = list(_FADAN_GENERIC_PERMS)
|
||||
try:
|
||||
rows = Permission.objects.filter(
|
||||
rows = Permission.query.filter(
|
||||
Q(perm_name__icontains='罚款') | Q(perm_name__icontains='罚单')
|
||||
).values('perm_code', 'perm_name')
|
||||
for row in rows:
|
||||
|
||||
750
backend/view.py
750
backend/view.py
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user