修复了一些

This commit is contained in:
2026-06-18 18:02:45 +08:00
parent e67bc17fa2
commit 53049d1588
20 changed files with 3671 additions and 2541 deletions

View File

@@ -5,7 +5,7 @@ import logging
from decimal import Decimal
from django.db import transaction
from orders.models import Fadan, FadanFenhong, FadanFenhongLilv
from orders.models import Penalty, PenaltyBonus, PenaltyBonusRate
from users.models import UserShangjia
logger = logging.getLogger(__name__)
@@ -32,14 +32,14 @@ def process_fadan_fenhong(fadan_id):
try:
# 1. 获取罚单对象(必须是已缴纳状态)
try:
fadan = Fadan.objects.get(id=fadan_id, zhuangtai=2)
except Fadan.DoesNotExist:
fadan = Penalty.objects.get(id=fadan_id, Status=2)
except Penalty.DoesNotExist:
logger.error(f"罚单 {fadan_id} 不存在或状态不是已缴纳")
return False, "罚单不存在或状态异常"
# 2. 获取申请处罚者ID和身份源身份数字
shenqing_chufa = fadan.shenqing_chufa
src_shenfen = fadan.shenqingren_shenfen
shenqing_chufa = fadan.ApplicantID
src_shenfen = fadan.ApplicantIdentity
if not shenqing_chufa:
logger.info(f"罚单 {fadan_id} 无申请处罚者,不进行分红")
@@ -56,27 +56,27 @@ def process_fadan_fenhong(fadan_id):
lilv_shenfen = mapped['lilv'] # 用于 FadanFenhongLilv.shenfen
# 4. 获取罚款金额
fakuan_jine = fadan.fakuanjine
fakuan_jine = fadan.FineAmount
if fakuan_jine <= 0:
logger.info(f"罚单 {fadan_id} 罚款金额为0不产生分红")
fadan.shenqingren_fenhong_jine = Decimal('0.00')
fadan.save(update_fields=['shenqingren_fenhong_jine'])
fadan.ApplicantBonusAmount = Decimal('0.00')
fadan.save(update_fields=['ApplicantBonusAmount'])
return True, "罚款金额为0无分红"
# 5. 确定分红利率
rate = _get_fenhong_rate(shenqing_chufa, fenhong_shenfen, lilv_shenfen)
if rate is None:
logger.warning(f"未找到身份 {src_shenfen} (映射后 fenhong_shenfen={fenhong_shenfen}, lilv_shenfen={lilv_shenfen}) 的分红利率,罚单 {fadan_id} 不进行分红")
fadan.shenqingren_fenhong_jine = Decimal('0.00')
fadan.save(update_fields=['shenqingren_fenhong_jine'])
fadan.ApplicantBonusAmount = Decimal('0.00')
fadan.save(update_fields=['ApplicantBonusAmount'])
return True, "未配置分红利率,无分红"
# 6. 计算分红金额
fenhong_jine = (Decimal(str(fakuan_jine)) * Decimal(str(rate))).quantize(Decimal('0.01'))
if fenhong_jine <= 0:
logger.info(f"罚单 {fadan_id} 计算分红金额为0无需处理")
fadan.shenqingren_fenhong_jine = Decimal('0.00')
fadan.save(update_fields=['shenqingren_fenhong_jine'])
fadan.ApplicantBonusAmount = Decimal('0.00')
fadan.save(update_fields=['ApplicantBonusAmount'])
return True, "分红金额为0"
# 7. 根据申请处罚者身份执行不同的分红逻辑
@@ -84,20 +84,20 @@ def process_fadan_fenhong(fadan_id):
if src_shenfen == 5:
# 商家特殊处理只记录总额可提现分红永远为0直接加到商家余额
with transaction.atomic():
fenhong_record, created = FadanFenhong.objects.get_or_create(
fenhongzhe_id=shenqing_chufa,
shenfen=fenhong_shenfen,
fenhong_record, created = PenaltyBonus.objects.get_or_create(
BeneficiaryID=shenqing_chufa,
Identity=fenhong_shenfen,
defaults={
'zonge': Decimal('0.00'),
'ketixian_fenhong': Decimal('0.00'),
'fenhong_cishu': 0,
'yingde_lilv': rate,
'TotalAmount': Decimal('0.00'),
'WithdrawableAmount': Decimal('0.00'),
'BonusCount': 0,
'IndividualRate': rate,
'is_individual_rate': False
}
)
fenhong_record.zonge += fenhong_jine
fenhong_record.TotalAmount += fenhong_jine
# 可提现分红不累加保持0
fenhong_record.fenhong_cishu += 1
fenhong_record.BonusCount += 1
fenhong_record.save()
# 直接增加商家余额UserShangjia.yue
@@ -111,31 +111,31 @@ def process_fadan_fenhong(fadan_id):
raise Exception(f"商家 {shenqing_chufa} 扩展表不存在,无法增加余额")
# 更新罚单中的申请人分红金额
fadan.shenqingren_fenhong_jine = fenhong_jine
fadan.save(update_fields=['shenqingren_fenhong_jine'])
fadan.ApplicantBonusAmount = fenhong_jine
fadan.save(update_fields=['ApplicantBonusAmount'])
else:
# 其他身份(客服、售后、管理员、店铺):同时增加总额和可提现分红
with transaction.atomic():
fenhong_record, created = FadanFenhong.objects.get_or_create(
fenhongzhe_id=shenqing_chufa,
shenfen=fenhong_shenfen,
fenhong_record, created = PenaltyBonus.objects.get_or_create(
BeneficiaryID=shenqing_chufa,
Identity=fenhong_shenfen,
defaults={
'zonge': Decimal('0.00'),
'ketixian_fenhong': Decimal('0.00'),
'fenhong_cishu': 0,
'yingde_lilv': rate,
'TotalAmount': Decimal('0.00'),
'WithdrawableAmount': Decimal('0.00'),
'BonusCount': 0,
'IndividualRate': rate,
'is_individual_rate': False
}
)
fenhong_record.zonge += fenhong_jine
fenhong_record.ketixian_fenhong += fenhong_jine
fenhong_record.fenhong_cishu += 1
fenhong_record.TotalAmount += fenhong_jine
fenhong_record.WithdrawableAmount += fenhong_jine
fenhong_record.BonusCount += 1
fenhong_record.save()
# 更新罚单中的申请人分红金额
fadan.shenqingren_fenhong_jine = fenhong_jine
fadan.save(update_fields=['shenqingren_fenhong_jine'])
fadan.ApplicantBonusAmount = fenhong_jine
fadan.save(update_fields=['ApplicantBonusAmount'])
logger.info(f"罚单 {fadan_id} 分红处理成功: 申请者 {shenqing_chufa}, 分红金额 {fenhong_jine} 元, 源身份 {src_shenfen}, 映射后分红身份 {fenhong_shenfen}")
return True, "分红处理成功"
@@ -150,17 +150,17 @@ def _get_fenhong_rate(fenhongzhe_id, fenhong_shenfen, lilv_shenfen):
获取分红利率(优先使用个人单独配置,否则使用全局身份配置)
"""
try:
individual = FadanFenhong.objects.get(
fenhongzhe_id=fenhongzhe_id,
shenfen=fenhong_shenfen,
individual = PenaltyBonus.objects.get(
BeneficiaryID=fenhongzhe_id,
Identity=fenhong_shenfen,
is_individual_rate=True
)
return individual.yingde_lilv
except FadanFenhong.DoesNotExist:
return individual.IndividualRate
except PenaltyBonus.DoesNotExist:
pass
try:
global_rate = FadanFenhongLilv.objects.get(shenfen=lilv_shenfen)
return global_rate.lilv
except FadanFenhongLilv.DoesNotExist:
global_rate = PenaltyBonusRate.objects.get(Identity=lilv_shenfen)
return global_rate.Rate
except PenaltyBonusRate.DoesNotExist:
return None

View File

@@ -25,7 +25,7 @@ from django.conf import settings
from django.db import transaction
from django.utils import timezone
from orders.models import Dingdan, DingdanShangjia, Fadan, Lilubiao
from orders.models import Order, MerchantOrderExt, Penalty, CommissionRate
from config.models import Szjilu, TixianQuotaDefault
from utils.fadan_utils import check_fadan_qiangdan_eligible
@@ -153,10 +153,10 @@ def get_tixian_feilv(leixing):
rate_key = LEIXING_RATE_KEY.get(leixing)
if not rate_key:
raise ValueError('无效的提现类型')
rate_obj = Lilubiao.query.filter(fadanpingtai=rate_key).first()
rate_obj = CommissionRate.query.filter(Platform=rate_key).first()
if not rate_obj:
raise ValueError(f'提现费率未配置(类型{leixing}')
return decimal.Decimal(str(rate_obj.lilu))
return decimal.Decimal(str(rate_obj.Rate))
def calc_fee_amounts(jine, feilv):
@@ -261,12 +261,12 @@ def validate_withdraw_eligibility(user_main, leixing, jine):
return False, huiyuan_msg, {}
if dashou.yajin < jine:
return False, f'押金余额不足,当前押金: {dashou.yajin}', {}
unfinished = Dingdan.query.filter(
jiedan_dashou_id=yonghuid,
).exclude(zhuangtai__in=[ORDER_STATUS_COMPLETED, ORDER_STATUS_REFUNDED]).exists()
unfinished = Order.query.filter(
PlayerID=yonghuid,
).exclude(Status__in=[ORDER_STATUS_COMPLETED, ORDER_STATUS_REFUNDED]).exists()
if unfinished:
return False, '您还有未完成或未退款的订单,请先处理完毕再提取押金', {}
self_fadan = Fadan.query.filter(beichufa_id=yonghuid).exclude(zhuangtai__in=[2, 4]).exists()
self_fadan = Penalty.query.filter(PenalizedUserID=yonghuid).exclude(Status__in=[2, 4]).exists()
if self_fadan:
return False, '您有未处理完毕的自身罚单(待缴纳/申诉中),请先处理', {}
return True, '', {'nicheng': dashou.nicheng or ''}
@@ -280,15 +280,15 @@ def validate_withdraw_eligibility(user_main, leixing, jine):
return False, '商家账号已被禁用,无法提现', {}
if shangjia.yue < jine:
return False, f'商家余额不足,当前余额: {shangjia.yue}', {}
unfinished_orders = DingdanShangjia.query.filter(
shangjia_id=yonghuid,
).exclude(dingdan__zhuangtai__in=[ORDER_STATUS_COMPLETED, ORDER_STATUS_REFUNDED]).exists()
unfinished_orders = MerchantOrderExt.query.filter(
MerchantID=yonghuid,
).exclude(Order__Status__in=[ORDER_STATUS_COMPLETED, ORDER_STATUS_REFUNDED]).exists()
if unfinished_orders:
return False, '您还有未完成或未退款的订单,请先处理完毕再提现余额', {}
self_fadan = Fadan.query.filter(beichufa_id=yonghuid).exclude(zhuangtai__in=[2, 4]).exists()
self_fadan = Penalty.query.filter(PenalizedUserID=yonghuid).exclude(Status__in=[2, 4]).exists()
if self_fadan:
return False, '您有未处理完毕的自身罚单(待缴纳/申诉中),请先处理', {}
applied_fadan = Fadan.query.filter(shenqing_chufa=yonghuid).exclude(zhuangtai__in=[2, 4]).exists()
applied_fadan = Penalty.query.filter(ApplicantID=yonghuid).exclude(Status__in=[2, 4]).exists()
if applied_fadan:
return False, '您发起的对其他用户的处罚尚未处理完毕,请等待完结', {}
return True, '', {'nicheng': shangjia.nicheng or ''}
@@ -350,12 +350,12 @@ def validate_collect_eligibility(user_main, leixing):
huiyuan_ok, huiyuan_msg = check_dashou_has_valid_huiyuan(yonghuid)
if not huiyuan_ok:
return False, huiyuan_msg
unfinished = Dingdan.query.filter(
jiedan_dashou_id=yonghuid,
).exclude(zhuangtai__in=[ORDER_STATUS_COMPLETED, ORDER_STATUS_REFUNDED]).exists()
unfinished = Order.query.filter(
PlayerID=yonghuid,
).exclude(Status__in=[ORDER_STATUS_COMPLETED, ORDER_STATUS_REFUNDED]).exists()
if unfinished:
return False, '您还有未完成或未退款的订单,无法收款'
self_fadan = Fadan.query.filter(beichufa_id=yonghuid).exclude(zhuangtai__in=[2, 4]).exists()
self_fadan = Penalty.query.filter(PenalizedUserID=yonghuid).exclude(Status__in=[2, 4]).exists()
if self_fadan:
return False, '您有未处理完毕的自身罚单,无法收款'
return True, ''
@@ -376,15 +376,15 @@ def validate_collect_eligibility(user_main, leixing):
return False, '您不是商家身份,无法收款'
if shangjia.zhuangtai != 1:
return False, '商家账号已被禁用,无法收款'
unfinished_orders = DingdanShangjia.query.filter(
shangjia_id=yonghuid,
).exclude(dingdan__zhuangtai__in=[ORDER_STATUS_COMPLETED, ORDER_STATUS_REFUNDED]).exists()
unfinished_orders = MerchantOrderExt.query.filter(
MerchantID=yonghuid,
).exclude(Order__Status__in=[ORDER_STATUS_COMPLETED, ORDER_STATUS_REFUNDED]).exists()
if unfinished_orders:
return False, '您还有未完成或未退款的订单,无法收款'
self_fadan = Fadan.query.filter(beichufa_id=yonghuid).exclude(zhuangtai__in=[2, 4]).exists()
self_fadan = Penalty.query.filter(PenalizedUserID=yonghuid).exclude(Status__in=[2, 4]).exists()
if self_fadan:
return False, '您有未处理完毕的自身罚单,无法收款'
applied_fadan = Fadan.query.filter(shenqing_chufa=yonghuid).exclude(zhuangtai__in=[2, 4]).exists()
applied_fadan = Penalty.query.filter(ApplicantID=yonghuid).exclude(Status__in=[2, 4]).exists()
if applied_fadan:
return False, '您发起的处罚尚未处理完毕,无法收款'
return True, ''

View File

@@ -3,7 +3,7 @@ from django.views.decorators.csrf import csrf_exempt
from .views import WechatMiniProgramLoginView, UserInfoUpdateView, DashouXinxiAPIView, \
ZaixianZhuangtaiAPIView, GuanshiXinxiView, ShangJiaXinXiView, BossBiaoshiView, YaoqingmaView, \
DashouZhuceView, GuanshiYaoqingDashouListView, TixianXinxiHuoquView, ShoukuanXinxiShangchuanView, \
TixianShenqingView, TixianJiluHuoquViewV2, AdminLoginView, AdminFinancialDataView, AdGetDingdanList, \
TixianShenqingView, TixianJiluHuoquViewV2, AdminLoginView, AdminFinancialDataView, AdGetOrderList, \
AdGetOrderTypes, AdGuanLiYongHu, AdYaoQingDaShou, CfGuanLi, AdTongYiChuFa, AdckyhxqView, AdcjxgView, AddtxshView, \
AdtixianqkView, DashouZiliaoHuoquView, DashouGengxinView,ShangjiaZhuceView,\
PaihangbangGuanliQueryView,PaihangbangRiqiliebiaoView, WechatLoginAndDashouRegisterView, \
@@ -43,7 +43,7 @@ urlpatterns = [
path('adgetordertypes', AdGetOrderTypes.as_view(), name='管理员获取订单类型'),
# 订单列表获取接口
path('adddhq', AdGetDingdanList.as_view(), name='管理员获取订单列表'),
path('adddhq', AdGetOrderList.as_view(), name='管理员获取订单列表'),
path('adyqds', AdYaoQingDaShou.as_view(), name='管理员获取邀请码'),
# 用户管理列表接口

File diff suppressed because it is too large Load Diff