feat: 管事自助更换组长(配额、记录、小程序与后台接口)
This commit is contained in:
@@ -6,7 +6,7 @@ from .view import (GetRolePermissionView,
|
||||
ModifyAdminUserView, KefuGetDashouListView, KefuGetDashouDetailView, KefuUpdateDashouView, KefuGetShangjiaListView,
|
||||
KefuGetShangjiaDetailView, KefuUpdateShangjiaView, KefuAddShangjiaView, GetProductBaseDataView, GetProductListView, SaveProductOrderView,
|
||||
AddProductView, DeleteProductView, GetProductDetailView, UpdateProductView, UpdateZhiKanShenheView, UpdateMemberView, GetMemberListView,
|
||||
AddMemberView, GetGuanliListView, GetGuanliDetailView, PromoteGuanshiToZuzhangView, ChangeInviterView, UpdateGuanliView, GetWithdrawSettingsView,
|
||||
AddMemberView, GetGuanliListView, GetGuanliDetailView, PromoteGuanshiToZuzhangView, ChangeInviterView, UpdateGuanliView, GuanshiChangeLeaderQuotaView, GuanshiChangeLeaderLogView, GetWithdrawSettingsView,
|
||||
UpdateWithdrawSettingsView, GetZuzhangListView, GetZuzhangDetailView, UpdateZuzhangView, GetOperationLogListView, GetProductTypeZoneView,
|
||||
ModifyProductTypeZoneView, GetRateView, ModifyRateView, PopupNoticeListAPIView, PopupNoticeModifyAPIView,ShopListView,
|
||||
ShopModifyView, ShopPublicTypeAndAuditView, ShopListForProductView, ShopProductModifyView,
|
||||
@@ -56,6 +56,8 @@ urlpatterns = [
|
||||
path('hthqgsxq', GetGuanliDetailView.as_view(), name='后台获取管事详情信息'),
|
||||
path('htgssjzz', PromoteGuanshiToZuzhangView.as_view(), name='后台管事升级组长'),
|
||||
path('htghyqr', ChangeInviterView.as_view(), name='后台更换邀请人'),
|
||||
path('htgs_huan_zz_quota', GuanshiChangeLeaderQuotaView.as_view(), name='后台管事换组长次数'),
|
||||
path('htgs_huan_zz_logs', GuanshiChangeLeaderLogView.as_view(), name='后台管事换组长记录'),
|
||||
path('htxggsxx', UpdateGuanliView.as_view(), name='后台更新管事数据'),
|
||||
path('hqczrz', GetOperationLogListView.as_view(), name='后台操作日志列表'),
|
||||
path('hthqtxpz', GetWithdrawSettingsView.as_view(), name='后台获取提现配置'),
|
||||
|
||||
@@ -51,7 +51,7 @@ from .views.members import (
|
||||
)
|
||||
from .views.guanli import (
|
||||
GetGuanliListView, GetGuanliDetailView, PromoteGuanshiToZuzhangView,
|
||||
UpdateGuanliView,
|
||||
UpdateGuanliView, GuanshiChangeLeaderQuotaView, GuanshiChangeLeaderLogView,
|
||||
)
|
||||
from .views.withdraw_settings import (
|
||||
GetWithdrawSettingsView, UpdateWithdrawSettingsView,
|
||||
@@ -113,7 +113,7 @@ __all__ = [
|
||||
'MemberCardImageUploadView', 'MemberRechargeRecordsView', 'MemberBundleCreateView',
|
||||
# guanli
|
||||
'GetGuanliListView', 'GetGuanliDetailView', 'PromoteGuanshiToZuzhangView',
|
||||
'UpdateGuanliView',
|
||||
'UpdateGuanliView', 'GuanshiChangeLeaderQuotaView', 'GuanshiChangeLeaderLogView',
|
||||
# withdraw_settings
|
||||
'GetWithdrawSettingsView', 'UpdateWithdrawSettingsView',
|
||||
# zuzhang
|
||||
|
||||
@@ -387,6 +387,19 @@ class GetGuanliDetailView(APIView):
|
||||
# 注意:首次分红定制只存储有定制记录的会员,没有定制的会员使用默认值(前端通过会员表展示)
|
||||
# 额外次数分红按次数返回
|
||||
|
||||
from jituan.services.club_context import resolve_club_id_from_request, resolve_club_scope
|
||||
from jituan.constants import DATA_SCOPE_ALL
|
||||
from jituan.services.club_user import get_user_club_id
|
||||
from users.services.change_leader import get_or_create_quota, quota_payload, list_change_logs
|
||||
|
||||
if resolve_club_scope(request) == DATA_SCOPE_ALL:
|
||||
quota_club = get_user_club_id(user)
|
||||
else:
|
||||
quota_club = resolve_club_id_from_request(request)
|
||||
quota = get_or_create_quota(quota_club, yonghuid)
|
||||
change_leader_quota = quota_payload(quota)
|
||||
change_leader_logs = list_change_logs(quota_club, yonghuid, page=1, page_size=20)
|
||||
|
||||
return Response({
|
||||
'code': 0,
|
||||
'data': {
|
||||
@@ -398,6 +411,8 @@ class GetGuanliDetailView(APIView):
|
||||
'extra_dividend_map': extra_map,
|
||||
'all_members': all_members,
|
||||
'is_zuzhang': is_zuzhang,
|
||||
'change_leader_quota': change_leader_quota,
|
||||
'change_leader_logs': change_leader_logs,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -855,7 +870,117 @@ class UpdateGuanliView(APIView):
|
||||
return Response({'code': 0, 'msg': '修改成功'})
|
||||
|
||||
|
||||
|
||||
def _admin_quota_club_id(request, user):
|
||||
from jituan.services.club_context import resolve_club_id_from_request, resolve_club_scope
|
||||
from jituan.constants import DATA_SCOPE_ALL
|
||||
from jituan.services.club_user import get_user_club_id
|
||||
if resolve_club_scope(request) == DATA_SCOPE_ALL:
|
||||
return get_user_club_id(user)
|
||||
return resolve_club_id_from_request(request)
|
||||
|
||||
|
||||
class GuanshiChangeLeaderQuotaView(APIView):
|
||||
"""
|
||||
后台设置/追加管事换组长次数
|
||||
POST /houtai/htgs_huan_zz_quota
|
||||
参数:username, yonghuid,
|
||||
action=set|add,
|
||||
total_quota(set)或 add_count(add)
|
||||
权限:4400a
|
||||
"""
|
||||
permission_classes = []
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
def post(self, request):
|
||||
username = request.data.get('username', '').strip()
|
||||
yonghuid = request.data.get('yonghuid', '').strip()
|
||||
action = (request.data.get('action') or 'add').strip().lower()
|
||||
|
||||
if not username:
|
||||
return Response({'code': 401, 'msg': '缺少username'})
|
||||
if not yonghuid:
|
||||
return Response({'code': 400, 'msg': '缺少用户ID'})
|
||||
|
||||
kefu, permissions = verify_kefu_permission(request, username)
|
||||
if kefu is None:
|
||||
return permissions
|
||||
if '4400a' not in permissions and '000001' not in permissions:
|
||||
return Response({'code': 403, 'msg': '无权限修改换组长次数(需要4400a)'})
|
||||
|
||||
try:
|
||||
user = User.query.select_related('GuanshiProfile').get(UserUID=yonghuid)
|
||||
_ = user.GuanshiProfile
|
||||
except User.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '管事不存在'})
|
||||
except UserGuanshi.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '用户不是管事'})
|
||||
|
||||
denied = forbid_if_user_out_of_scope(request, user)
|
||||
if denied:
|
||||
return denied
|
||||
|
||||
from users.services.change_leader import set_total_quota, add_quota
|
||||
club_id = _admin_quota_club_id(request, user)
|
||||
if action == 'set':
|
||||
result = set_total_quota(club_id, yonghuid, request.data.get('total_quota'))
|
||||
else:
|
||||
result = add_quota(
|
||||
club_id,
|
||||
yonghuid,
|
||||
request.data.get('add_count') or request.data.get('add'),
|
||||
)
|
||||
if not result.get('ok'):
|
||||
return Response({'code': result.get('code', 400), 'msg': result.get('msg', '失败')})
|
||||
return Response({'code': 0, 'msg': result.get('msg', 'ok'), 'data': result.get('data')})
|
||||
|
||||
|
||||
class GuanshiChangeLeaderLogView(APIView):
|
||||
"""
|
||||
后台查询管事换组长记录
|
||||
POST /houtai/htgs_huan_zz_logs
|
||||
参数:username, yonghuid, page, page_size
|
||||
权限:4400a-f 任一
|
||||
"""
|
||||
permission_classes = []
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
def post(self, request):
|
||||
username = request.data.get('username', '').strip()
|
||||
yonghuid = request.data.get('yonghuid', '').strip()
|
||||
|
||||
if not username:
|
||||
return Response({'code': 401, 'msg': '缺少username'})
|
||||
if not yonghuid:
|
||||
return Response({'code': 400, 'msg': '缺少用户ID'})
|
||||
|
||||
kefu, permissions = verify_kefu_permission(request, username)
|
||||
if kefu is None:
|
||||
return permissions
|
||||
required_perms = {'4400a', '4400b', '4400c', '4400d', '4400e', '4400f', '000001'}
|
||||
if not any(p in permissions for p in required_perms):
|
||||
return Response({'code': 403, 'msg': '您没有权限查看换组长记录'})
|
||||
|
||||
try:
|
||||
user = User.query.select_related('GuanshiProfile').get(UserUID=yonghuid)
|
||||
_ = user.GuanshiProfile
|
||||
except User.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '管事不存在'})
|
||||
except UserGuanshi.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '用户不是管事'})
|
||||
|
||||
denied = forbid_if_user_out_of_scope(request, user)
|
||||
if denied:
|
||||
return denied
|
||||
|
||||
from users.services.change_leader import list_change_logs
|
||||
club_id = _admin_quota_club_id(request, user)
|
||||
data = list_change_logs(
|
||||
club_id,
|
||||
yonghuid,
|
||||
page=request.data.get('page', 1),
|
||||
page_size=request.data.get('page_size', 20),
|
||||
)
|
||||
return Response({'code': 0, 'data': data})
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user