修复了一些可能影响生产的问题

This commit is contained in:
2026-06-14 23:08:44 +08:00
parent 21bb129c5d
commit a155dc9f33
43 changed files with 66 additions and 210 deletions

View File

@@ -1,16 +1,6 @@
"""
ASGI config for a_long_dianjing project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
application = get_asgi_application()

View File

@@ -12,27 +12,24 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
# 创建Celery应用实例
app = Celery('a_long_dianjing')
# 从Django settings中加载Celery配置CELERY_前缀
app.config_from_object('django.conf:settings', namespace='CELERY')
# 自动发现所有已注册app中的tasks.py文件
#app.autodiscover_tasks()
app.autodiscover_tasks(['yonghu.tasks', 'yonghu.ranking_tasks', 'dingdan.tasks', 'peizhi.tasks'])
app.autodiscover_tasks(['users.tasks', 'users.ranking_tasks', 'orders.tasks', 'config.tasks'])
# 配置周期性任务Celery Beat Schedule
app.conf.beat_schedule = {
# 月榜数据转移每月最后一天23:50执行
'yuebang_zhuanyi': {
'task': 'yonghu.ranking_tasks.zhuanyi_yuebang',
'task': 'users.ranking_tasks.zhuanyi_yuebang',
'schedule': crontab(hour=23, minute=50, day_of_month='28-31'), # ✅ 修改这里
'options': {'queue': 'periodic_tasks', 'priority': 7},
},
# 日榜数据转移每天23:55执行在清零前
'ribang_zhuanyi': {
'task': 'yonghu.ranking_tasks.zhuanyi_ribang',
'task': 'users.ranking_tasks.zhuanyi_ribang',
#'schedule': crontab(minute='*/1'), # 每分钟执行一次,测试用
'schedule': crontab(hour=23, minute=55), # 每天23:55
'options': {'queue': 'periodic_tasks', 'priority': 7}, # 优先级高于清零任务
@@ -40,21 +37,21 @@ app.conf.beat_schedule = {
# 清理旧历史数据每月1号凌晨1点执行
'qingli_jiulishuju': {
'task': 'yonghu.ranking_tasks.qingli_jiulishuju',
'task': 'users.ranking_tasks.qingli_jiulishuju',
'schedule': crontab(hour=1, minute=0, day_of_month=1), # 每月1号凌晨1点
'options': {'queue': 'periodic_tasks', 'priority': 4},
},
# 补偿检查任务每5分钟运行
'check_order_expire_task': {
'task': 'dingdan.tasks.check_order_expire_task',
'task': 'orders.tasks.check_order_expire_task',
'schedule': crontab(minute='*/5000'),
'options': {'queue': 'order_tasks', 'priority': 3},
},
# 1. 每日凌晨0点执行 - 清零任务
'daily_reset_task': {
'task': 'yonghu.tasks.daily_reset_task',
'task': 'users.tasks.daily_reset_task',
'schedule': crontab(hour=0, minute=0), # 每天0点
'options': {
'queue': 'periodic_tasks',
@@ -66,7 +63,7 @@ app.conf.beat_schedule = {
# 2. 每月1日凌晨0点执行 - 月度清零任务
'monthly_reset_task': {
'task': 'yonghu.tasks.monthly_reset_task',
'task': 'users.tasks.monthly_reset_task',
'schedule': crontab(hour=0, minute=0, day_of_month=1), # 每月1日0点
'options': {
'queue': 'periodic_tasks',
@@ -78,7 +75,7 @@ app.conf.beat_schedule = {
# 4. 每天凌晨0点5分清理收支记录
'daily_sz_reset_task': {
'task': 'peizhi.tasks.daily_sz_reset_task',
'task': 'config.tasks.daily_sz_reset_task',
'schedule': crontab(hour=0, minute=5), # 每天0点5分
'options': {
'queue': 'periodic_tasks',
@@ -90,66 +87,15 @@ app.conf.beat_schedule = {
}
# 配置周期性任务Celery Beat Schedule
'''app.conf.beat_schedule = {
# 1. 每日凌晨0点执行 - 清零任务
'daily_reset_task': {
'task': 'yonghu.tasks.daily_reset_task',
'schedule': crontab(hour=0, minute=0), # 每天0点
'options': {
'queue': 'periodic_tasks',
'priority': 5
},
'args': (),
'kwargs': {}
},
# 2. 每月1日凌晨0点执行 - 月度清零任务
'monthly_reset_task': {
'task': 'yonghu.tasks.monthly_reset_task',
'schedule': crontab(hour=0, minute=0, day_of_month=1), # 每月1日0点
'options': {
'queue': 'periodic_tasks',
'priority': 5
},
'args': (),
'kwargs': {}
},
# 3. 每5分钟检查一次待处理订单 - 作为补偿机制
'check_order_expire_task': {
'task': 'dingdan.tasks.check_order_expire_task',
'schedule': crontab(minute='*/5'), # 每5分钟
'options': {
'queue': 'order_tasks',
'priority': 3
},
'args': (),
'kwargs': {}
},
# 4. 每天凌晨0点5分清理收支记录
'daily_sz_reset_task': {
'task': 'peizhi.tasks.daily_sz_reset_task',
'schedule': crontab(hour=0, minute=5), # 每天0点5分
'options': {
'queue': 'periodic_tasks',
'priority': 4
},
'args': (),
'kwargs': {}
}
}'''
# 时区设置
app.conf.timezone = 'Asia/Shanghai'
app.conf.enable_utc = True
# 队列路由配置
app.conf.task_routes = {
'dingdan.tasks.*': {'queue': 'order_tasks'},
'yonghu.tasks.*': {'queue': 'periodic_tasks'},
'peizhi.tasks.*': {'queue': 'periodic_tasks'},
'orders.tasks.*': {'queue': 'order_tasks'},
'users.tasks.*': {'queue': 'periodic_tasks'},
'config.tasks.*': {'queue': 'periodic_tasks'},
}
# 任务序列化

View File

@@ -1,10 +1,10 @@
# celery_app.py
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
app = Celery('a_long_dianjing')
app.config_from_object('django.conf:settings', namespace='CELERY')
# 手动导入任务模块,避免与已有 tasks.py 冲突
app.autodiscover_tasks(['dingdan.notice_tasks'])
app.autodiscover_tasks(['orders.notice_tasks'])

View File

@@ -3,14 +3,13 @@ Django settings for a_long_dianjing project.
"""
from pathlib import Path
from datetime import timedelta
import os
# 从密钥配置文件导入敏感信息
try:
import app_secrets
except ImportError:
raise ImportError("缺少 appapp_secrets.py 密钥配置文件,请参照项目说明创建")
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = app_secrets.SECRET_KEY

View File

@@ -1,32 +1,7 @@
"""
URL configuration for a_long_dianjing project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/6.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
'''from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]'''
# a_long_dianjing/urls.py
"""
项目根路由配置 - 按照生产环境格式连接所有APP路由
注意本项目使用MinIO模拟OSS文件上传不经过Django MEDIA_URL所以不需要static(settings.MEDIA_URL)配置
"""
from django.contrib import admin
from django.urls import path, include

View File

@@ -1,16 +1,6 @@
"""
WSGI config for a_long_dianjing project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
application = get_wsgi_application()

View File

@@ -1,5 +1,6 @@
from django.apps import AppConfig
class HoutaiConfig(AppConfig):
class BackendConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'houtai'
name = 'backend'

View File

@@ -1,5 +1,6 @@
from django.db import models
# ==================== 1. 角色表 ====================
class Role(models.Model):
"""角色表"""
@@ -17,7 +18,6 @@ class Role(models.Model):
verbose_name_plural = '角色'
indexes = [
models.Index(fields=['role_code']),
]
def __str__(self):

View File

@@ -1,9 +1,8 @@
# serializers.py
#小程序弹窗序列化器
from rest_framework import serializers
from config.models import PopupPage, PopupConfig, PopupImage
class PopupImageSerializer(serializers.ModelSerializer):
"""图片序列化器(输出用)"""
class Meta:

View File

@@ -1,25 +1,25 @@
from django.urls import path
from django.views.decorators.csrf import csrf_exempt
from .view import GetClubConfigView, GetCrossOrderListView, PartnerGetOrderDataView,PartnerRefundNotifyView,\
CrossPlatformRefundView, GetCrossOrderDetailView, CrossPlatformForceCompleteView, CrossPlatformTransferHallView,\
PartnerTransferHallNotifyView, GetSettingsView, UpdateSettingsView, GetMappingsView, UpdateMappingsView,\
PartnerUpdateSelfConfigView, GetPartnerClubsView, GetStatsView, PunishDashouView, PartnerPunishNotifyView,\
GetClubConfigForPreSettlementView, PreSettlementActionView, GetPreSettlementDataView, GetRolePermissionView,\
ModifyRolePermissionView, AddRoleView, GetAdminRolesView, GetAdminUserListView, AddAdminUserView,\
ModifyAdminUserView, KefuGetDashouListView, KefuGetDashouDetailView, KefuUpdateDashouView, KefuGetShangjiaListView,\
KefuGetShangjiaDetailView, KefuUpdateShangjiaView, GetProductBaseDataView, GetProductListView, SaveProductOrderView,\
AddProductView, DeleteProductView, GetProductDetailView, UpdateProductView, UpdateMemberView, GetMemberListView,\
AddMemberView, GetGuanliListView, GetGuanliDetailView, UpdateGuanliView, GetWithdrawSettingsView,\
UpdateWithdrawSettingsView, GetZuzhangListView, GetZuzhangDetailView, UpdateZuzhangView, GetProductTypeZoneView,\
ModifyProductTypeZoneView, GetRateView, ModifyRateView, PopupNoticeListAPIView, PopupNoticeModifyAPIView,ShopListView, ShopModifyView, ShopPublicTypeAndAuditView, ShopListForProductView, ShopProductModifyView,\
ShopProductTypeMappingView, ProductListView, ProductModifyView, KefuChatPermissionsView,\
PartnerFineNotifyView,FineApplyView, FaKuanTongJiView, FaKuanLieBiaoView, FaKuanChuLiView, FaKuanChuangJianView,\
HqbkxxView,BkxgView,CaiwuView,CwhybkhqView, HybkjtsjView, SzxxView, CwddhqlxView, CwhqjtddsjView,\
CwqtczhqView, KhpzhqView, ChzsgcView,KhgglView, ShgxgsjView, ZxkfghdsView, KptxwztjbView
from .view import (GetClubConfigView, GetCrossOrderListView, PartnerGetOrderDataView,PartnerRefundNotifyView,
CrossPlatformRefundView, GetCrossOrderDetailView, CrossPlatformForceCompleteView, CrossPlatformTransferHallView,
PartnerTransferHallNotifyView, GetSettingsView, UpdateSettingsView, GetMappingsView, UpdateMappingsView,
PartnerUpdateSelfConfigView, GetPartnerClubsView, GetStatsView, PunishDashouView, PartnerPunishNotifyView,
GetClubConfigForPreSettlementView, PreSettlementActionView, GetPreSettlementDataView, GetRolePermissionView,
ModifyRolePermissionView, AddRoleView, GetAdminRolesView, GetAdminUserListView, AddAdminUserView,
ModifyAdminUserView, KefuGetDashouListView, KefuGetDashouDetailView, KefuUpdateDashouView, KefuGetShangjiaListView,
KefuGetShangjiaDetailView, KefuUpdateShangjiaView, GetProductBaseDataView, GetProductListView, SaveProductOrderView,
AddProductView, DeleteProductView, GetProductDetailView, UpdateProductView, UpdateMemberView, GetMemberListView,
AddMemberView, GetGuanliListView, GetGuanliDetailView, UpdateGuanliView, GetWithdrawSettingsView,
UpdateWithdrawSettingsView, GetZuzhangListView, GetZuzhangDetailView, UpdateZuzhangView, GetProductTypeZoneView,
ModifyProductTypeZoneView, GetRateView, ModifyRateView, PopupNoticeListAPIView, PopupNoticeModifyAPIView,ShopListView,
ShopModifyView, ShopPublicTypeAndAuditView, ShopListForProductView, ShopProductModifyView,
ShopProductTypeMappingView, ProductListView, ProductModifyView, KefuChatPermissionsView,
PartnerFineNotifyView,FineApplyView, FaKuanTongJiView, FaKuanLieBiaoView, FaKuanChuLiView, FaKuanChuangJianView,
HqbkxxView,BkxgView,CaiwuView,CwhybkhqView, HybkjtsjView, SzxxView, CwddhqlxView, CwhqjtddsjView,
CwqtczhqView, KhpzhqView, ChzsgcView,KhgglView, ShgxgsjView, ZxkfghdsView, KptxwztjbView)
urlpatterns = [
path('kpthq', GetClubConfigView.as_view(), name='跨平台订单页面获取俱乐部数据'),
path('hqddlb', GetCrossOrderListView.as_view(), name='获取跨平台订单'),
path('kpthqtp',csrf_exempt(PartnerGetOrderDataView.as_view()), name='跨平台接受对方服务器获取订单数据'),

View File

@@ -3,7 +3,7 @@ import logging
import json
from django.core.exceptions import ObjectDoesNotExist
from rest_framework.response import Response
from .models import AbnormalUserLog, UserRole, RolePermission, Permission, DashouRiTongji, ShangjiaRiTongji, \
from .models import AbnormalUserLog, UserRole, Permission, DashouRiTongji, ShangjiaRiTongji, \
GuanshiXufeiRiTongji, GuanshiRiTongji, ZuzhangRiTongji, TixianRiTongji
from django.db import transaction

View File

@@ -79,11 +79,11 @@ from config.models import (
## rank
from rank.models import (
KaoheguanBankuai, Bankuai, Chenghao, KaoheCishuFeiyong,
YonghuChenghao, ShenheJilu
YonghuChenghao
)
# 序列化器
from .serializers import PopupPageSerializer, PopupConfigSerializer, PopupImageSerializer
from .serializers import PopupPageSerializer
# 全局常量、日志对象
logger = logging.getLogger('houtai')

View File

@@ -1,3 +1 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,5 +1,5 @@
from django.apps import AppConfig
class PeizhiConfig(AppConfig):
name = "peizhi"
class ConfigConfig(AppConfig):
name = "config"

View File

@@ -1,7 +1,6 @@
from django.db import models
class Lunbo(models.Model):
tupian_url = models.CharField(max_length=500, null=True, blank=True, verbose_name='轮播图片URL')
leixing = models.IntegerField(null=True, blank=True, verbose_name='图片类型:1轮播2个人中心背景')

View File

@@ -1,3 +1 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -7,6 +7,7 @@ from .views import ShangpinGonggaoView, AdminUpdateConfigView, AdminUploadImageV
GetDynamicConfigView, PopupConfigView, GetWithdrawModeView,CheckPhoneAuthView,\
ShangjiaLianjieListView
urlpatterns = [
path('shangpingonggao/', ShangpinGonggaoView.as_view(), name='商品公告轮播获取'),
path('adpzhq', AdminConfigQueryView.as_view(), name='管理员获取配置'),

View File

@@ -1,6 +1,5 @@
import io
import os
import json
import re
import time
import random
@@ -11,7 +10,7 @@ import urllib.parse
from decimal import Decimal, InvalidOperation
from django.conf import settings
from django.db import models, transaction, connection
from django.db import transaction, connection
from django.db.models import Q, F, Max, Prefetch
from django.core.cache import cache
from django.core.paginator import Paginator

View File

@@ -1,3 +1 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,9 +1,9 @@
from django.apps import AppConfig
class DingdanConfig(AppConfig):
class OrdersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dingdan'
name = 'orders'
def ready(self):
# 导入信号处理,确保信号被注册

View File

@@ -22,16 +22,11 @@ logger = logging.getLogger(__name__)
@shared_task(bind=True, max_retries=3, default_retry_delay=60)
def process_expired_order(self, dingdan_id):
"""
处理单个超时订单(订单状态=8超过48小时未处理
"""
try:
# 使用select_for_update锁定记录防止并发修改
with transaction.atomic():

View File

@@ -1,3 +1 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -5,7 +5,6 @@ import json
import time
import random
import string
import uuid
import traceback
import threading
import requests
@@ -14,15 +13,12 @@ import xml.etree.ElementTree as ET
import xmltodict
import logging
from decimal import Decimal
from datetime import datetime
from django.conf import settings
from django.db import models, transaction
from django.db.models import F, Q, Count, OuterRef, Subquery, Prefetch
from django.db.models import F, Q, OuterRef, Subquery
from django.core.cache import cache
from django.core.paginator import Paginator
from django.core.exceptions import ObjectDoesNotExist
from django.shortcuts import render
from django.http import HttpResponse
from django.utils import timezone
@@ -41,7 +37,6 @@ from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentClo
from tencentcloud.sts.v20180813 import sts_client, models
from utils.weixin_broadcast import WeixinBroadcastSender
from utils.goeasy_service import GoEasyService
from utils.chat_utils import _send_group_message, _subscribe_users_to_group, establish_order_chat
from utils.fadan_utils import check_fadan_qiangdan_eligible
@@ -60,7 +55,7 @@ from orders.notice_tasks import dingdan_guangbo
from .models import (
Dingdan, DingdanShangjia, DingdanPingtai, Dashoutupian,
Chufajilu, Chufatupian, Fadan, FadanFenhong, Liaotian
Chufajilu, Chufatupian, Fadan, FadanFenhong
)
from orders.models import (
Lilubiao, Pingfen, PreSettlement, Tuikuanjilu, CrossPlatformOrderData

View File

@@ -1,3 +1 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,5 +1,5 @@
from django.apps import AppConfig
class ShangpinConfig(AppConfig):
name = "shangpin"
class ProductsConfig(AppConfig):
name = "products"

View File

@@ -1,3 +1 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -64,8 +64,6 @@ urlpatterns = [
path('adhyjllxcx',HuiyuanTypeListView.as_view(), name='管理员查询会员记录获取会员类型'),
path('adhyjlcxhq',HuiyuanRecordListView.as_view(), name='管理员查询会员记录'),
path('zuzhangfenhong', ZuzhangFenhongView.as_view(), name='组长分红记录获取'),
path('czhqdy', CzhqdyView.as_view(), name='充值打手抵押查询'),
path('dsqrgmdh', DsqrgmdhView.as_view(), name='充值抵扣'),

View File

@@ -1,5 +1,3 @@
# tongji/utils.py 或 shangpin/utils.py
import logging
from datetime import date
from decimal import Decimal

View File

@@ -15,9 +15,8 @@ import defusedxml.ElementTree as ET
# ==================== Django 内置 ====================
from django.conf import settings
from django.db import models, transaction, connection
from django.db.models import Q, Count, Subquery, OuterRef
from django.core.paginator import Paginator
from django.db import transaction, connection
from django.db.models import Q
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from django.utils import timezone

View File

@@ -1,6 +1,6 @@
from django.apps import AppConfig
class DengjiConfig(AppConfig):
class RankConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'dengji'
name = 'rank'

View File

@@ -4,7 +4,8 @@ from django.db import transaction, IntegrityError
from django.utils import timezone
from .models import DashouBiaoxian
logger = logging.getLogger('dengji')
logger = logging.getLogger(__name__)
def record_dashou_biaoxian(dingdan_id, dashou_id, xingwei, **kwargs):
"""

View File

@@ -1,3 +1 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -3,6 +3,7 @@ from .views import DashouBiaoqianView , BankuaiBiaoqianView, KaoheguanRegisterVi
KaoheguanRefreshView , ShenheDatingModuleView, ShenheDatingDataView, ShenheQiangdanView, ShenheCaozuoView,ShenheXiangqingView, KaoheJinpaiTagsView, KaoheJiluView, KaoheFreeApplyView,\
KaoheJiluListView
urlpatterns = [
path('dsbqhq', DashouBiaoqianView.as_view(), name='打手标签获取'),
# 其他已有路由保持不变

View File

@@ -4,8 +4,7 @@ import random
import logging
from decimal import Decimal
# Django 内置
from django.db import models
from django.db.models import Q, F, Max
from django.db.models import F, Max
# 项目模型
## 当前dengji应用
from .models import (
@@ -70,9 +69,6 @@ def check_dashou_biaoqian_required(order_id, dashou_yonghuid):
def get_tag_fee(chenghao, cishu):
"""
获取标签在指定考核次数下的费用。

View File

@@ -1,8 +1,8 @@
import json
import logging
from decimal import Decimal
from django.db import models, transaction, IntegrityError
from django.db.models import F, Q, OuterRef, Subquery, Count, Max
from django.db import models, transaction
from django.db.models import F
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated

View File

@@ -1,3 +1 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,6 +1,6 @@
from django.apps import AppConfig
class ShangdianConfig(AppConfig):
class ShopConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'shangdian'
name = 'shop'

View File

@@ -1,3 +1 @@
from django.contrib import admin
# Register your models here.

View File

@@ -1,5 +1,5 @@
from django.apps import AppConfig
class YonghuConfig(AppConfig):
name = "yonghu"
class UsersConfig(AppConfig):
name = "users"

View File

@@ -1,11 +1,9 @@
# yonghu/fadan_fenhong_utils.py
# 罚款缴纳分红处理公共方法(支持更新罚单中的申请人分红金额)
import decimal
import logging
from decimal import Decimal
from django.db import transaction
from django.core.exceptions import ObjectDoesNotExist
from orders.models import Fadan, FadanFenhong, FadanFenhongLilv
from users.models import UserShangjia

View File

@@ -1,8 +1,6 @@
# models.py
from django.db import models
import random
import string
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
from django.contrib.auth.models import AbstractBaseUser
# ==================== 用户主表 ====================
class UserMain(AbstractBaseUser):

View File

@@ -1,3 +1 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -1,3 +1 @@
from django.contrib import admin
# Register your models here.