feat: 公告按页、身份标签、拼多多订单号、派单与抢单改造
This commit is contained in:
@@ -45,6 +45,8 @@ MENU_ROWS = [
|
||||
'perm_codes': ['1100a', '1100b']},
|
||||
{'page_id': 'user.zuzhang', 'name': '组长管理', 'path': '/user/zuzhang', 'parent_id': 'user', 'sort_order': 54,
|
||||
'perm_codes': ['6600a', '6600b', '6600c', '6600d', '6600e']},
|
||||
{'page_id': 'user.identity-tag', 'name': '身份装饰标签', 'path': '/user/identity-tag', 'parent_id': 'user', 'sort_order': 55,
|
||||
'perm_codes': ['sfbq666']},
|
||||
# 提现
|
||||
{'page_id': 'withdraw', 'name': '提现管理', 'path': '', 'parent_id': '', 'sort_order': 60},
|
||||
{'page_id': 'withdraw.audit', 'name': '提现审核', 'path': '/withdraw/audit', 'parent_id': 'withdraw', 'sort_order': 61,
|
||||
|
||||
56
jituan/migrations/0005_identity_tag.py
Normal file
56
jituan/migrations/0005_identity_tag.py
Normal file
@@ -0,0 +1,56 @@
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('jituan', '0004_kefu_menu_page'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='IdentityTag',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('club_id', models.CharField(db_index=True, max_length=16)),
|
||||
('name', models.CharField(max_length=64, verbose_name='标签名')),
|
||||
('color', models.CharField(default='#000000', max_length=32, verbose_name='主色')),
|
||||
('flash_enabled', models.BooleanField(default=False, verbose_name='闪光特效')),
|
||||
('texiao_json', models.TextField(blank=True, default='', verbose_name='特效JSON')),
|
||||
('sort_order', models.IntegerField(default=0)),
|
||||
('status', models.IntegerField(default=1, verbose_name='1启用0停用')),
|
||||
('CreateTime', models.DateTimeField(auto_now_add=True)),
|
||||
('UpdateTime', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'identity_tag',
|
||||
'ordering': ['sort_order', 'id'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='IdentityTagBind',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('club_id', models.CharField(db_index=True, max_length=16)),
|
||||
('yonghuid', models.CharField(db_index=True, max_length=7)),
|
||||
('shenfen', models.IntegerField(verbose_name='1打手2管事3商家4组长')),
|
||||
('CreateTime', models.DateTimeField(auto_now_add=True)),
|
||||
('tag', models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name='binds', to='jituan.identitytag',
|
||||
)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'identity_tag_bind',
|
||||
},
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='identitytagbind',
|
||||
index=models.Index(fields=['club_id', 'yonghuid', 'shenfen'], name='identity_tag_bind_lookup'),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='identitytagbind',
|
||||
unique_together={('club_id', 'yonghuid', 'shenfen', 'tag')},
|
||||
),
|
||||
]
|
||||
@@ -157,6 +157,39 @@ class ClubFadanFenhongLilv(QModel):
|
||||
unique_together = [['club_id', 'shenfen']]
|
||||
|
||||
|
||||
class IdentityTag(QModel):
|
||||
"""身份装饰标签定义(与考核称号、订单需求标签分离)。"""
|
||||
club_id = models.CharField(max_length=16, db_index=True)
|
||||
name = models.CharField(max_length=64, verbose_name='标签名')
|
||||
color = models.CharField(max_length=32, default='#000000', verbose_name='主色')
|
||||
flash_enabled = models.BooleanField(default=False, verbose_name='闪光特效')
|
||||
texiao_json = models.TextField(blank=True, default='', verbose_name='特效JSON')
|
||||
sort_order = models.IntegerField(default=0)
|
||||
status = models.IntegerField(default=1, verbose_name='1启用0停用')
|
||||
CreateTime = models.DateTimeField(auto_now_add=True)
|
||||
UpdateTime = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
db_table = 'identity_tag'
|
||||
ordering = ['sort_order', 'id']
|
||||
|
||||
|
||||
class IdentityTagBind(QModel):
|
||||
"""用户身份与装饰标签绑定。"""
|
||||
club_id = models.CharField(max_length=16, db_index=True)
|
||||
yonghuid = models.CharField(max_length=7, db_index=True)
|
||||
shenfen = models.IntegerField(verbose_name='1打手2管事3商家4组长')
|
||||
tag = models.ForeignKey(IdentityTag, on_delete=models.CASCADE, related_name='binds')
|
||||
CreateTime = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
db_table = 'identity_tag_bind'
|
||||
unique_together = [['club_id', 'yonghuid', 'shenfen', 'tag']]
|
||||
indexes = [
|
||||
models.Index(fields=['club_id', 'yonghuid', 'shenfen']),
|
||||
]
|
||||
|
||||
|
||||
class KefuMenuPage(QModel):
|
||||
"""客服后台左侧菜单页(固定 page_id,与前端路由对应)。"""
|
||||
page_id = models.CharField(max_length=64, primary_key=True, verbose_name='页面ID')
|
||||
|
||||
@@ -58,10 +58,13 @@ def _display_club_id(request):
|
||||
return resolve_effective_club_id(request, None)
|
||||
|
||||
|
||||
def get_gonggao_content(request, notice_type=1):
|
||||
def get_gonggao_content(request, notice_type=1, page_key=None):
|
||||
from config.models import Gonggao
|
||||
club_id = _display_club_id(request)
|
||||
obj = Gonggao.query.filter(club_id=club_id, NoticeType=notice_type).first()
|
||||
pk = normalize_page_key(page_key, image_type=1) if page_key else LUNBO_PAGE_ORDER_POOL
|
||||
obj = Gonggao.query.filter(club_id=club_id, page_key=pk).first()
|
||||
if not obj and notice_type:
|
||||
obj = Gonggao.query.filter(club_id=club_id, NoticeType=notice_type).first()
|
||||
return obj.Content if obj and obj.Content else ''
|
||||
|
||||
|
||||
@@ -131,6 +134,7 @@ def copy_display_config(template_club_id, new_club_id):
|
||||
for row in Gonggao.query.filter(club_id=template_club_id):
|
||||
Gonggao.query.create(
|
||||
club_id=new_club_id,
|
||||
page_key=getattr(row, 'page_key', None) or 'order_pool',
|
||||
NoticeType=row.NoticeType,
|
||||
Content=row.Content,
|
||||
)
|
||||
|
||||
110
jituan/services/identity_tag.py
Normal file
110
jituan/services/identity_tag.py
Normal file
@@ -0,0 +1,110 @@
|
||||
"""身份装饰标签查询与组装(与考核称号、订单需求标签分离)。"""
|
||||
import json
|
||||
|
||||
from jituan.models import IdentityTag, IdentityTagBind
|
||||
|
||||
SHENFEN_DASHOU = 1
|
||||
SHENFEN_GUANSHI = 2
|
||||
SHENFEN_SHANGJIA = 3
|
||||
SHENFEN_ZUZHANG = 4
|
||||
|
||||
|
||||
def _tag_texiao(tag):
|
||||
if tag.texiao_json:
|
||||
try:
|
||||
return json.loads(tag.texiao_json)
|
||||
except (TypeError, ValueError, json.JSONDecodeError):
|
||||
pass
|
||||
return {
|
||||
'color': tag.color or '#000000',
|
||||
'flash': bool(tag.flash_enabled),
|
||||
}
|
||||
|
||||
|
||||
def format_tag_item(tag):
|
||||
return {
|
||||
'id': tag.id,
|
||||
'mingcheng': tag.name,
|
||||
'texiao_json': _tag_texiao(tag),
|
||||
}
|
||||
|
||||
|
||||
def get_identity_tags_for_user(club_id, yonghuid, shenfen):
|
||||
"""单用户单身份装饰标签列表。"""
|
||||
binds = (
|
||||
IdentityTagBind.query.filter(
|
||||
club_id=club_id, yonghuid=yonghuid, shenfen=shenfen,
|
||||
)
|
||||
.select_related('tag')
|
||||
.order_by('tag__sort_order', 'tag__id')
|
||||
)
|
||||
result = []
|
||||
for b in binds:
|
||||
tag = b.tag
|
||||
if tag.status != 1:
|
||||
continue
|
||||
result.append(format_tag_item(tag))
|
||||
return result
|
||||
|
||||
|
||||
def batch_identity_tags(club_id, yonghuid_shenfen_pairs):
|
||||
"""
|
||||
批量查询:[(yonghuid, shenfen), ...] -> {(yonghuid, shenfen): [tags]}
|
||||
"""
|
||||
if not yonghuid_shenfen_pairs:
|
||||
return {}
|
||||
yonghuids = {p[0] for p in yonghuid_shenfen_pairs}
|
||||
shenfens = {p[1] for p in yonghuid_shenfen_pairs}
|
||||
binds = (
|
||||
IdentityTagBind.query.filter(
|
||||
club_id=club_id, yonghuid__in=yonghuids, shenfen__in=shenfens,
|
||||
)
|
||||
.select_related('tag')
|
||||
.order_by('tag__sort_order', 'tag__id')
|
||||
)
|
||||
out = {}
|
||||
pair_set = set(yonghuid_shenfen_pairs)
|
||||
for b in binds:
|
||||
key = (b.yonghuid, b.shenfen)
|
||||
if key not in pair_set:
|
||||
continue
|
||||
if b.tag.status != 1:
|
||||
continue
|
||||
out.setdefault(key, []).append(format_tag_item(b.tag))
|
||||
return out
|
||||
|
||||
|
||||
def get_my_identity_tags(user, club_id):
|
||||
"""当前用户各已激活身份的装饰标签。"""
|
||||
uid = user.UserUID
|
||||
data = {'dashou': [], 'guanshi': [], 'zuzhang': [], 'shangjia': []}
|
||||
|
||||
try:
|
||||
dp = user.DashouProfile
|
||||
if dp.zhanghaozhuangtai == 1:
|
||||
data['dashou'] = get_identity_tags_for_user(club_id, uid, SHENFEN_DASHOU)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
gp = user.GuanshiProfile
|
||||
if gp.zhuangtai == 1:
|
||||
data['guanshi'] = get_identity_tags_for_user(club_id, uid, SHENFEN_GUANSHI)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
zp = user.ZuzhangProfile
|
||||
if zp.zhuangtai == 1:
|
||||
data['zuzhang'] = get_identity_tags_for_user(club_id, uid, SHENFEN_ZUZHANG)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
sp = user.ShopProfile
|
||||
if sp.zhuangtai == 1:
|
||||
data['shangjia'] = get_identity_tags_for_user(club_id, uid, SHENFEN_SHANGJIA)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return data
|
||||
@@ -43,6 +43,14 @@ from jituan.views import (
|
||||
ClubWechatLoginView,
|
||||
)
|
||||
|
||||
from jituan.views_identity_tag import (
|
||||
IdentityTagBindListView,
|
||||
IdentityTagBindView,
|
||||
IdentityTagListView,
|
||||
IdentityTagManageView,
|
||||
IdentityTagMyTagsView,
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
path('auth/wechat-login', ClubWechatLoginView.as_view(), name='jituan_wechat_login'),
|
||||
path('auth/kefu-login', ClubKefuLoginView.as_view(), name='jituan_kefu_login'),
|
||||
@@ -71,6 +79,11 @@ urlpatterns = [
|
||||
path('houtai/lunbo-list', ClubLunboListView.as_view(), name='jituan_lunbo_list'),
|
||||
path('houtai/lunbo-manage', ClubLunboManageView.as_view(), name='jituan_lunbo_manage'),
|
||||
path('houtai/gonggao', ClubGonggaoView.as_view(), name='jituan_gonggao'),
|
||||
path('identity-tag/my-tags', IdentityTagMyTagsView.as_view(), name='jituan_identity_my_tags'),
|
||||
path('houtai/identity-tag/list', IdentityTagListView.as_view(), name='jituan_identity_tag_list'),
|
||||
path('houtai/identity-tag/manage', IdentityTagManageView.as_view(), name='jituan_identity_tag_manage'),
|
||||
path('houtai/identity-tag/bind-list', IdentityTagBindListView.as_view(), name='jituan_identity_tag_bind_list'),
|
||||
path('houtai/identity-tag/bind', IdentityTagBindView.as_view(), name='jituan_identity_tag_bind'),
|
||||
path('houtai/tupian-list', ClubTupianListView.as_view(), name='jituan_tupian_list'),
|
||||
path('houtai/tupian-manage', ClubTupianManageView.as_view(), name='jituan_tupian_manage'),
|
||||
path('houtai/hthqtcxx', PopupNoticeListAPIView.as_view(), name='jituan_popup_list'),
|
||||
|
||||
@@ -133,6 +133,7 @@ class ClubGonggaoView(APIView):
|
||||
return Response({'code': 403, 'msg': '无权限管理公告'})
|
||||
|
||||
notice_type = int(request.data.get('notice_type', 1) or 1)
|
||||
page_key = normalize_page_key(request.data.get('page_key'), image_type=1)
|
||||
club_id = resolve_effective_club_id(request, request.user)
|
||||
|
||||
content = request.data.get('content')
|
||||
@@ -140,8 +141,9 @@ class ClubGonggaoView(APIView):
|
||||
return Response({
|
||||
'code': 0,
|
||||
'data': {
|
||||
'content': get_gonggao_content(request, notice_type=notice_type),
|
||||
'content': get_gonggao_content(request, notice_type=notice_type, page_key=page_key),
|
||||
'notice_type': notice_type,
|
||||
'page_key': page_key,
|
||||
**list_response_meta(request),
|
||||
},
|
||||
})
|
||||
@@ -152,12 +154,13 @@ class ClubGonggaoView(APIView):
|
||||
|
||||
row, _ = Gonggao.query.get_or_create(
|
||||
club_id=club_id,
|
||||
NoticeType=notice_type,
|
||||
defaults={'Content': content},
|
||||
page_key=page_key,
|
||||
defaults={'NoticeType': notice_type, 'Content': content},
|
||||
)
|
||||
row.Content = content
|
||||
row.save(update_fields=['Content', 'UpdateTime'])
|
||||
return Response({'code': 0, 'msg': '保存成功'})
|
||||
row.NoticeType = notice_type
|
||||
row.save(update_fields=['Content', 'NoticeType', 'UpdateTime'])
|
||||
return Response({'code': 0, 'msg': '保存成功', 'data': {'page_key': page_key}})
|
||||
|
||||
|
||||
class ClubTupianListView(APIView):
|
||||
|
||||
241
jituan/views_identity_tag.py
Normal file
241
jituan/views_identity_tag.py
Normal file
@@ -0,0 +1,241 @@
|
||||
"""身份装饰标签:后台管理 + 小程序 my-tags。"""
|
||||
import json
|
||||
|
||||
from rest_framework.parsers import JSONParser
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from backend.utils import verify_kefu_permission
|
||||
from jituan.models import IdentityTag, IdentityTagBind
|
||||
from jituan.services.club_context import resolve_effective_club_id
|
||||
from jituan.services.display_config import list_response_meta
|
||||
from jituan.services.identity_tag import (
|
||||
SHENFEN_DASHOU,
|
||||
SHENFEN_GUANSHI,
|
||||
SHENFEN_SHANGJIA,
|
||||
SHENFEN_ZUZHANG,
|
||||
format_tag_item,
|
||||
get_my_identity_tags,
|
||||
)
|
||||
from users.business_models import User
|
||||
|
||||
IDENTITY_TAG_PERM = 'sfbq666'
|
||||
|
||||
SHENFEN_LABELS = {
|
||||
SHENFEN_DASHOU: '打手',
|
||||
SHENFEN_GUANSHI: '管事',
|
||||
SHENFEN_SHANGJIA: '商家',
|
||||
SHENFEN_ZUZHANG: '组长',
|
||||
}
|
||||
|
||||
|
||||
def _build_texiao_json(color, flash_enabled):
|
||||
return json.dumps({
|
||||
'color': color or '#000000',
|
||||
'flash': bool(flash_enabled),
|
||||
}, ensure_ascii=False)
|
||||
|
||||
|
||||
class IdentityTagMyTagsView(APIView):
|
||||
"""小程序:当前用户各身份装饰标签 POST /jituan/identity-tag/my-tags"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
def post(self, request):
|
||||
user = request.user
|
||||
club_id = resolve_effective_club_id(request, user)
|
||||
data = get_my_identity_tags(user, club_id)
|
||||
return Response({'code': 200, 'msg': '成功', 'data': data})
|
||||
|
||||
|
||||
class IdentityTagListView(APIView):
|
||||
"""后台:标签定义列表 POST /jituan/houtai/identity-tag/list"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
def post(self, request):
|
||||
phone = (request.data.get('phone') or request.data.get('username') or '').strip()
|
||||
if not phone:
|
||||
return Response({'code': 401, 'msg': '缺少客服账号'})
|
||||
kefu, permissions = verify_kefu_permission(request, phone)
|
||||
if kefu is None:
|
||||
return permissions
|
||||
if IDENTITY_TAG_PERM not in permissions:
|
||||
return Response({'code': 403, 'msg': '无权限管理身份装饰标签'})
|
||||
|
||||
club_id = resolve_effective_club_id(request, request.user)
|
||||
rows = IdentityTag.query.filter(club_id=club_id).order_by('sort_order', 'id')
|
||||
return Response({
|
||||
'code': 0,
|
||||
'data': {
|
||||
'list': [
|
||||
{
|
||||
'id': r.id,
|
||||
'name': r.name,
|
||||
'color': r.color,
|
||||
'flash_enabled': r.flash_enabled,
|
||||
'sort_order': r.sort_order,
|
||||
'status': r.status,
|
||||
}
|
||||
for r in rows
|
||||
],
|
||||
**list_response_meta(request),
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
class IdentityTagManageView(APIView):
|
||||
"""后台:新增/编辑/删除标签 POST /jituan/houtai/identity-tag/manage"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
def post(self, request):
|
||||
phone = (request.data.get('phone') or request.data.get('username') or '').strip()
|
||||
if not phone:
|
||||
return Response({'code': 401, 'msg': '缺少客服账号'})
|
||||
kefu, permissions = verify_kefu_permission(request, phone)
|
||||
if kefu is None:
|
||||
return permissions
|
||||
if IDENTITY_TAG_PERM not in permissions:
|
||||
return Response({'code': 403, 'msg': '无权限管理身份装饰标签'})
|
||||
|
||||
club_id = resolve_effective_club_id(request, request.user)
|
||||
action = (request.data.get('action') or '').strip()
|
||||
|
||||
if action == 'delete':
|
||||
tag_id = request.data.get('id')
|
||||
if not tag_id:
|
||||
return Response({'code': 400, 'msg': '缺少标签ID'})
|
||||
IdentityTag.query.filter(id=tag_id, club_id=club_id).delete()
|
||||
return Response({'code': 0, 'msg': '删除成功'})
|
||||
|
||||
name = (request.data.get('name') or '').strip()
|
||||
if not name:
|
||||
return Response({'code': 400, 'msg': '标签名不能为空'})
|
||||
color = (request.data.get('color') or '#000000').strip()
|
||||
flash_enabled = bool(request.data.get('flash_enabled', False))
|
||||
sort_order = int(request.data.get('sort_order', 0) or 0)
|
||||
status = int(request.data.get('status', 1) or 1)
|
||||
texiao_json = _build_texiao_json(color, flash_enabled)
|
||||
|
||||
tag_id = request.data.get('id')
|
||||
if tag_id:
|
||||
row = IdentityTag.query.filter(id=tag_id, club_id=club_id).first()
|
||||
if not row:
|
||||
return Response({'code': 404, 'msg': '标签不存在'})
|
||||
row.name = name
|
||||
row.color = color
|
||||
row.flash_enabled = flash_enabled
|
||||
row.sort_order = sort_order
|
||||
row.status = status
|
||||
row.texiao_json = texiao_json
|
||||
row.save()
|
||||
return Response({'code': 0, 'msg': '更新成功', 'data': {'id': row.id}})
|
||||
|
||||
row = IdentityTag.query.create(
|
||||
club_id=club_id,
|
||||
name=name,
|
||||
color=color,
|
||||
flash_enabled=flash_enabled,
|
||||
sort_order=sort_order,
|
||||
status=status,
|
||||
texiao_json=texiao_json,
|
||||
)
|
||||
return Response({'code': 0, 'msg': '创建成功', 'data': {'id': row.id}})
|
||||
|
||||
|
||||
class IdentityTagBindListView(APIView):
|
||||
"""后台:绑定列表 POST /jituan/houtai/identity-tag/bind-list"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
def post(self, request):
|
||||
phone = (request.data.get('phone') or request.data.get('username') or '').strip()
|
||||
if not phone:
|
||||
return Response({'code': 401, 'msg': '缺少客服账号'})
|
||||
kefu, permissions = verify_kefu_permission(request, phone)
|
||||
if kefu is None:
|
||||
return permissions
|
||||
if IDENTITY_TAG_PERM not in permissions:
|
||||
return Response({'code': 403, 'msg': '无权限管理身份装饰标签'})
|
||||
|
||||
club_id = resolve_effective_club_id(request, request.user)
|
||||
keyword = (request.data.get('keyword') or '').strip()
|
||||
shenfen = request.data.get('shenfen')
|
||||
page = max(1, int(request.data.get('page', 1) or 1))
|
||||
page_size = min(50, max(1, int(request.data.get('page_size', 20) or 20)))
|
||||
|
||||
qs = IdentityTagBind.query.filter(club_id=club_id).select_related('tag')
|
||||
if shenfen is not None and str(shenfen) != '':
|
||||
qs = qs.filter(shenfen=int(shenfen))
|
||||
if keyword:
|
||||
qs = qs.filter(yonghuid__icontains=keyword)
|
||||
|
||||
total = qs.count()
|
||||
rows = qs.order_by('-id')[(page - 1) * page_size:page * page_size]
|
||||
items = []
|
||||
for b in rows:
|
||||
items.append({
|
||||
'id': b.id,
|
||||
'yonghuid': b.yonghuid,
|
||||
'shenfen': b.shenfen,
|
||||
'shenfen_label': SHENFEN_LABELS.get(b.shenfen, str(b.shenfen)),
|
||||
'tag_id': b.tag_id,
|
||||
'tag_name': b.tag.name if b.tag else '',
|
||||
})
|
||||
return Response({
|
||||
'code': 0,
|
||||
'data': {
|
||||
'list': items,
|
||||
'total': total,
|
||||
'page': page,
|
||||
'page_size': page_size,
|
||||
**list_response_meta(request),
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
class IdentityTagBindView(APIView):
|
||||
"""后台:绑定/解绑 POST /jituan/houtai/identity-tag/bind"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
def post(self, request):
|
||||
phone = (request.data.get('phone') or request.data.get('username') or '').strip()
|
||||
if not phone:
|
||||
return Response({'code': 401, 'msg': '缺少客服账号'})
|
||||
kefu, permissions = verify_kefu_permission(request, phone)
|
||||
if kefu is None:
|
||||
return permissions
|
||||
if IDENTITY_TAG_PERM not in permissions:
|
||||
return Response({'code': 403, 'msg': '无权限管理身份装饰标签'})
|
||||
|
||||
club_id = resolve_effective_club_id(request, request.user)
|
||||
action = (request.data.get('action') or 'bind').strip()
|
||||
|
||||
if action == 'unbind':
|
||||
bind_id = request.data.get('id')
|
||||
if not bind_id:
|
||||
return Response({'code': 400, 'msg': '缺少绑定ID'})
|
||||
IdentityTagBind.query.filter(id=bind_id, club_id=club_id).delete()
|
||||
return Response({'code': 0, 'msg': '解绑成功'})
|
||||
|
||||
yonghuid = (request.data.get('yonghuid') or '').strip()
|
||||
tag_id = request.data.get('tag_id')
|
||||
shenfen = request.data.get('shenfen')
|
||||
if not yonghuid or not tag_id or shenfen is None:
|
||||
return Response({'code': 400, 'msg': '参数不完整'})
|
||||
if not User.query.filter(UserUID=yonghuid).exists():
|
||||
return Response({'code': 404, 'msg': '用户不存在'})
|
||||
tag = IdentityTag.query.filter(id=tag_id, club_id=club_id, status=1).first()
|
||||
if not tag:
|
||||
return Response({'code': 404, 'msg': '标签不存在'})
|
||||
|
||||
IdentityTagBind.query.get_or_create(
|
||||
club_id=club_id,
|
||||
yonghuid=yonghuid,
|
||||
shenfen=int(shenfen),
|
||||
tag=tag,
|
||||
)
|
||||
return Response({'code': 0, 'msg': '绑定成功'})
|
||||
Reference in New Issue
Block a user