fix: 罚单/积分处罚归属申请人俱乐部;申请锁定分红缴纳按锁定值入账
This commit is contained in:
@@ -6648,7 +6648,9 @@ class FaKuanChuangJianView(APIView):
|
|||||||
AffectsGrabbing=AffectsGrabbing,
|
AffectsGrabbing=AffectsGrabbing,
|
||||||
Status=1, # 待缴纳
|
Status=1, # 待缴纳
|
||||||
ClubID=resolve_penalty_club_id(
|
ClubID=resolve_penalty_club_id(
|
||||||
penalized_user_id=PenalizedUserID, request=request,
|
penalized_user_id=PenalizedUserID,
|
||||||
|
request=request,
|
||||||
|
user=request.user,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
for relative_url in uploaded_urls:
|
for relative_url in uploaded_urls:
|
||||||
@@ -6753,7 +6755,12 @@ class FineApplyView(APIView):
|
|||||||
Status=1, # 待缴纳
|
Status=1, # 待缴纳
|
||||||
AffectsGrabbing=AffectsGrabbing,
|
AffectsGrabbing=AffectsGrabbing,
|
||||||
ApplicantIdentity=1, # 申请人身份:1 客服
|
ApplicantIdentity=1, # 申请人身份:1 客服
|
||||||
ClubID=resolve_penalty_club_id(order=order, request=request),
|
ClubID=resolve_penalty_club_id(
|
||||||
|
order=order,
|
||||||
|
request=request,
|
||||||
|
user=request.user,
|
||||||
|
applicant_id=getattr(request.user, 'UserUID', None),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
for relative_url in uploaded_urls:
|
for relative_url in uploaded_urls:
|
||||||
PenaltyAppealImage.query.create(
|
PenaltyAppealImage.query.create(
|
||||||
@@ -6834,7 +6841,13 @@ class PunishDashouView(APIView):
|
|||||||
ApplyStatus=0,
|
ApplyStatus=0,
|
||||||
DeductedPoints=jifen,
|
DeductedPoints=jifen,
|
||||||
OrderID=OrderID,
|
OrderID=OrderID,
|
||||||
ClubID=resolve_penalty_record_club_id(order_id=OrderID, player_id=dashou_id),
|
ClubID=resolve_penalty_record_club_id(
|
||||||
|
order_id=OrderID,
|
||||||
|
player_id=dashou_id,
|
||||||
|
request=request,
|
||||||
|
user=request.user,
|
||||||
|
applicant_id=getattr(request.user, 'UserUID', None) or username,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
# 扣除打手积分
|
# 扣除打手积分
|
||||||
dashou.jifen = F('jifen') - jifen
|
dashou.jifen = F('jifen') - jifen
|
||||||
|
|||||||
@@ -10,19 +10,82 @@ from jituan.services.club_context import (
|
|||||||
from jituan.services.club_user import get_user_club_id
|
from jituan.services.club_user import get_user_club_id
|
||||||
|
|
||||||
|
|
||||||
def resolve_penalty_club_id(order=None, penalized_user_id=None, request=None):
|
def _club_id_from_user_uid(uid):
|
||||||
"""创建罚单时写入 club_id。"""
|
if not uid:
|
||||||
|
return None
|
||||||
|
from users.business_models import User
|
||||||
|
u = User.query.filter(UserUID=str(uid)).first()
|
||||||
|
if u:
|
||||||
|
return get_user_club_id(u)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_penalty_club_id(
|
||||||
|
order=None,
|
||||||
|
penalized_user_id=None,
|
||||||
|
request=None,
|
||||||
|
applicant_id=None,
|
||||||
|
user=None,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
创建金额罚单时写入 club_id。
|
||||||
|
归属:申请人俱乐部 > 当前操作人/请求俱乐部 > 订单俱乐部 > 被罚人俱乐部 > xq。
|
||||||
|
"""
|
||||||
|
cid = _club_id_from_user_uid(applicant_id)
|
||||||
|
if cid:
|
||||||
|
return cid
|
||||||
|
|
||||||
|
if request is not None or user is not None:
|
||||||
|
from jituan.services.club_write import resolve_club_id_for_write
|
||||||
|
u = user or getattr(request, 'user', None)
|
||||||
|
cid = resolve_club_id_for_write(request, u)
|
||||||
|
if cid:
|
||||||
|
return cid
|
||||||
|
|
||||||
if order is not None:
|
if order is not None:
|
||||||
cid = getattr(order, 'ClubID', None)
|
cid = getattr(order, 'ClubID', None)
|
||||||
if cid:
|
if cid:
|
||||||
return cid
|
return cid
|
||||||
if penalized_user_id:
|
|
||||||
from users.business_models import User
|
cid = _club_id_from_user_uid(penalized_user_id)
|
||||||
u = User.query.filter(UserUID=penalized_user_id).first()
|
if cid:
|
||||||
if u:
|
return cid
|
||||||
return get_user_club_id(u)
|
|
||||||
if request is not None:
|
return CLUB_ID_DEFAULT
|
||||||
return resolve_club_id_from_request(request)
|
|
||||||
|
|
||||||
|
def resolve_penalty_record_club_id(
|
||||||
|
order_id=None,
|
||||||
|
player_id=None,
|
||||||
|
request=None,
|
||||||
|
applicant_id=None,
|
||||||
|
user=None,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
创建积分处罚(chufajilu)时写入 club_id。
|
||||||
|
归属规则与金额罚单一致:申请人俱乐部优先。
|
||||||
|
"""
|
||||||
|
cid = _club_id_from_user_uid(applicant_id)
|
||||||
|
if cid:
|
||||||
|
return cid
|
||||||
|
|
||||||
|
if request is not None or user is not None:
|
||||||
|
from jituan.services.club_write import resolve_club_id_for_write
|
||||||
|
u = user or getattr(request, 'user', None)
|
||||||
|
cid = resolve_club_id_for_write(request, u)
|
||||||
|
if cid:
|
||||||
|
return cid
|
||||||
|
|
||||||
|
if order_id:
|
||||||
|
from orders.models import Order
|
||||||
|
o = Order.query.filter(OrderID=order_id).first()
|
||||||
|
if o and getattr(o, 'ClubID', None):
|
||||||
|
return o.ClubID
|
||||||
|
|
||||||
|
cid = _club_id_from_user_uid(player_id)
|
||||||
|
if cid:
|
||||||
|
return cid
|
||||||
|
|
||||||
return CLUB_ID_DEFAULT
|
return CLUB_ID_DEFAULT
|
||||||
|
|
||||||
|
|
||||||
@@ -44,10 +107,9 @@ def resolve_gsfenhong_club_id(dingdan_id=None, dashouid=None, order=None, czjilu
|
|||||||
if o and getattr(o, 'ClubID', None):
|
if o and getattr(o, 'ClubID', None):
|
||||||
return o.ClubID
|
return o.ClubID
|
||||||
if dashouid:
|
if dashouid:
|
||||||
from users.business_models import User
|
cid = _club_id_from_user_uid(dashouid)
|
||||||
u = User.query.filter(UserUID=dashouid).first()
|
if cid:
|
||||||
if u:
|
return cid
|
||||||
return get_user_club_id(u)
|
|
||||||
return CLUB_ID_DEFAULT
|
return CLUB_ID_DEFAULT
|
||||||
|
|
||||||
|
|
||||||
@@ -91,7 +153,7 @@ def _filter_club_penalty_like_qs(qs, request, user_id_field, order_id_field):
|
|||||||
if not parts:
|
if not parts:
|
||||||
return qs.none()
|
return qs.none()
|
||||||
combined = parts[0]
|
combined = parts[0]
|
||||||
for p in parts[1:]:
|
for p in parts[1]:
|
||||||
combined |= p
|
combined |= p
|
||||||
return qs.filter(combined)
|
return qs.filter(combined)
|
||||||
|
|
||||||
@@ -119,20 +181,6 @@ def forbid_penalty_out_of_scope(request, penalty):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def resolve_penalty_record_club_id(order_id=None, player_id=None):
|
|
||||||
if order_id:
|
|
||||||
from orders.models import Order
|
|
||||||
o = Order.query.filter(OrderID=order_id).first()
|
|
||||||
if o and getattr(o, 'ClubID', None):
|
|
||||||
return o.ClubID
|
|
||||||
if player_id:
|
|
||||||
from users.business_models import User
|
|
||||||
u = User.query.filter(UserUID=player_id).first()
|
|
||||||
if u:
|
|
||||||
return get_user_club_id(u)
|
|
||||||
return CLUB_ID_DEFAULT
|
|
||||||
|
|
||||||
|
|
||||||
def filter_penalty_record_qs(qs, request):
|
def filter_penalty_record_qs(qs, request):
|
||||||
"""积分处罚记录(chufajilu)按俱乐部过滤。"""
|
"""积分处罚记录(chufajilu)按俱乐部过滤。"""
|
||||||
return _filter_club_penalty_like_qs(
|
return _filter_club_penalty_like_qs(
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ from .models import (
|
|||||||
from jituan.services.club_config import get_commission_rate, get_commission_rate_object
|
from jituan.services.club_config import get_commission_rate, get_commission_rate_object
|
||||||
from jituan.services.club_context import resolve_club_id_from_request
|
from jituan.services.club_context import resolve_club_id_from_request
|
||||||
from jituan.services.club_user import get_payment_openid
|
from jituan.services.club_user import get_payment_openid
|
||||||
from jituan.services.club_penalty import resolve_penalty_club_id
|
from jituan.services.club_penalty import resolve_penalty_club_id, resolve_penalty_record_club_id
|
||||||
from users.fadan_fenhong_utils import lock_penalty_bonus
|
from users.fadan_fenhong_utils import lock_penalty_bonus
|
||||||
from users.fadan_fenhong_utils import lock_penalty_bonus
|
from users.fadan_fenhong_utils import lock_penalty_bonus
|
||||||
from products.models import Shangpin, ShangpinLeixing, Huiyuangoumai
|
from products.models import Shangpin, ShangpinLeixing, Huiyuangoumai
|
||||||
@@ -2304,12 +2304,16 @@ class ShangjiaDingdanXiangqingView(APIView):
|
|||||||
'update_time': ut,
|
'update_time': ut,
|
||||||
}
|
}
|
||||||
|
|
||||||
# 7. 商家分红利率(申请页预览):与缴纳后分红同一套规则
|
# 7. 商家分红利率:已有罚单用锁定值;否则按商家所在俱乐部预览
|
||||||
fenhong_lilv = 0.0
|
fenhong_lilv = 0.0
|
||||||
try:
|
try:
|
||||||
|
if fadan_obj and fadan_obj.ApplicantBonusRate:
|
||||||
|
fenhong_lilv = float(fadan_obj.ApplicantBonusRate)
|
||||||
|
else:
|
||||||
from users.fadan_fenhong_utils import get_merchant_fenhong_lilv
|
from users.fadan_fenhong_utils import get_merchant_fenhong_lilv
|
||||||
order_club_id = getattr(order, 'ClubID', None) or 'xq'
|
from jituan.services.club_write import resolve_club_id_for_write
|
||||||
fenhong_lilv = get_merchant_fenhong_lilv(yonghuid, club_id=order_club_id)
|
merchant_club_id = resolve_club_id_for_write(request, current_user)
|
||||||
|
fenhong_lilv = get_merchant_fenhong_lilv(yonghuid, club_id=merchant_club_id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f'获取分红利率失败: {e}')
|
logger.warning(f'获取分红利率失败: {e}')
|
||||||
|
|
||||||
@@ -2976,6 +2980,13 @@ class ShangjiaChufaShenqingView(APIView):
|
|||||||
ApplyStatus=0, # 待处理
|
ApplyStatus=0, # 待处理
|
||||||
DeductedPoints=5, # 扣除5积分
|
DeductedPoints=5, # 扣除5积分
|
||||||
OrderID=dingdan_id,
|
OrderID=dingdan_id,
|
||||||
|
ClubID=resolve_penalty_record_club_id(
|
||||||
|
order_id=dingdan_id,
|
||||||
|
player_id=dashou_id,
|
||||||
|
request=request,
|
||||||
|
applicant_id=current_user.UserUID,
|
||||||
|
user=current_user,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
# 🔴【新增】在创建处罚记录后立即扣除打手积分
|
# 🔴【新增】在创建处罚记录后立即扣除打手积分
|
||||||
# 注意:这里使用前面已经获取的dashou对象(打手扩展表)
|
# 注意:这里使用前面已经获取的dashou对象(打手扩展表)
|
||||||
@@ -6539,7 +6550,13 @@ class ShangjiaFakuanApplyView(APIView):
|
|||||||
Status=1, # 待缴纳
|
Status=1, # 待缴纳
|
||||||
AffectsGrabbing=yingxiang_qiangdan,
|
AffectsGrabbing=yingxiang_qiangdan,
|
||||||
ApplicantIdentity=5, # 申请人是商家
|
ApplicantIdentity=5, # 申请人是商家
|
||||||
ClubID=resolve_penalty_club_id(order=order, penalized_user_id=dashou_id),
|
ClubID=resolve_penalty_club_id(
|
||||||
|
order=order,
|
||||||
|
penalized_user_id=dashou_id,
|
||||||
|
request=request,
|
||||||
|
applicant_id=shangjia_id,
|
||||||
|
user=current_user,
|
||||||
|
),
|
||||||
ShopStaffUserID=staff_kefu_id,
|
ShopStaffUserID=staff_kefu_id,
|
||||||
)
|
)
|
||||||
lock_penalty_bonus(fadan)
|
lock_penalty_bonus(fadan)
|
||||||
|
|||||||
@@ -3095,6 +3095,7 @@ class ShopFineApplyView(APIView):
|
|||||||
return Response({'code': 400, 'msg': '该打手已被罚款过'})
|
return Response({'code': 400, 'msg': '该打手已被罚款过'})
|
||||||
|
|
||||||
# ---------- 6. 创建罚单 ----------
|
# ---------- 6. 创建罚单 ----------
|
||||||
|
from jituan.services.club_penalty import resolve_penalty_club_id
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
penalty = Penalty.query.create(
|
penalty = Penalty.query.create(
|
||||||
PenalizedUserID=dashou_id,
|
PenalizedUserID=dashou_id,
|
||||||
@@ -3106,6 +3107,12 @@ class ShopFineApplyView(APIView):
|
|||||||
Status=1, # 待缴纳
|
Status=1, # 待缴纳
|
||||||
AffectsGrabbing=yingxiang_qiangdan,
|
AffectsGrabbing=yingxiang_qiangdan,
|
||||||
ApplicantIdentity=4, # 申请人身份:4 店铺管理员
|
ApplicantIdentity=4, # 申请人身份:4 店铺管理员
|
||||||
|
ClubID=resolve_penalty_club_id(
|
||||||
|
order=order,
|
||||||
|
request=request,
|
||||||
|
user=request.user,
|
||||||
|
applicant_id=str(shop_id),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
from users.fadan_fenhong_utils import lock_penalty_bonus
|
from users.fadan_fenhong_utils import lock_penalty_bonus
|
||||||
lock_penalty_bonus(penalty)
|
lock_penalty_bonus(penalty)
|
||||||
|
|||||||
@@ -12,12 +12,15 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
# 身份映射字典
|
# 身份映射字典
|
||||||
|
# 罚单 ApplicantIdentity(shenqingren_shenfen)→ fadan_fenhong 表 Identity + fadan_fenhong_lilv 表 shenfen
|
||||||
|
# 罚单侧:1=客服 2=售后 3=管理员 4=店铺 5=商家
|
||||||
|
# fadan_fenhong 表:1=商家 2=客服 3=平台管理者 4=店铺 5=售后
|
||||||
IDENTITY_MAP = {
|
IDENTITY_MAP = {
|
||||||
1: {'fenhong': 2, 'lilv': 1}, # 客服
|
1: {'fenhong': 2, 'lilv': 1}, # 客服 → 分红记录身份2,利率表 shenfen=1
|
||||||
2: {'fenhong': 5, 'lilv': 2}, # 售后
|
2: {'fenhong': 5, 'lilv': 2}, # 售后 → 分红记录身份5,利率表 shenfen=2
|
||||||
3: {'fenhong': 3, 'lilv': 3}, # 管理员
|
3: {'fenhong': 3, 'lilv': 3}, # 管理员
|
||||||
4: {'fenhong': 4, 'lilv': 4}, # 店铺
|
4: {'fenhong': 4, 'lilv': 4}, # 店铺
|
||||||
5: {'fenhong': 1, 'lilv': 5}, # 商家
|
5: {'fenhong': 1, 'lilv': 5}, # 商家 → 分红记录身份1,利率表 shenfen=5;钱进 user_shangjia.yue
|
||||||
}
|
}
|
||||||
|
|
||||||
MERCHANT_LILV_SHENFEN = 5
|
MERCHANT_LILV_SHENFEN = 5
|
||||||
@@ -151,7 +154,10 @@ def process_fadan_fenhong(fadan_id):
|
|||||||
locked_amount = Decimal(str(fadan.ApplicantBonusAmount or 0))
|
locked_amount = Decimal(str(fadan.ApplicantBonusAmount or 0))
|
||||||
locked_rate = fadan.ApplicantBonusRate
|
locked_rate = fadan.ApplicantBonusRate
|
||||||
|
|
||||||
if locked_amount > 0:
|
# 申请时已锁定:缴纳只按锁定值入账,不因全局利率后续变更而重算
|
||||||
|
if locked_amount > 0 or (
|
||||||
|
locked_rate is not None and Decimal(str(locked_rate)) > 0
|
||||||
|
):
|
||||||
fenhong_jine = locked_amount
|
fenhong_jine = locked_amount
|
||||||
rate = locked_rate
|
rate = locked_rate
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -10441,6 +10441,7 @@ class KefuPunishView(APIView):
|
|||||||
return Response({'code': 400, 'msg': '该用户不是打手'}, status=status.HTTP_400_BAD_REQUEST)
|
return Response({'code': 400, 'msg': '该用户不是打手'}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
# 6. 使用事务
|
# 6. 使用事务
|
||||||
|
from jituan.services.club_penalty import resolve_penalty_record_club_id
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
# 创建处罚记录(积分扣除5分)
|
# 创建处罚记录(积分扣除5分)
|
||||||
jifen = 5
|
jifen = 5
|
||||||
@@ -10451,6 +10452,12 @@ class KefuPunishView(APIView):
|
|||||||
ApplyStatus=0, # 待处理
|
ApplyStatus=0, # 待处理
|
||||||
DeductedPoints=jifen,
|
DeductedPoints=jifen,
|
||||||
OrderID=dingdan_id,
|
OrderID=dingdan_id,
|
||||||
|
ClubID=resolve_penalty_record_club_id(
|
||||||
|
order_id=dingdan_id,
|
||||||
|
player_id=dashou_id,
|
||||||
|
request=request,
|
||||||
|
user=request.user,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# 扣除打手积分
|
# 扣除打手积分
|
||||||
|
|||||||
Reference in New Issue
Block a user