feat: 只看审核按俱乐部隔离,商品管理支持俱乐部视图

未绑店出货开关按 club_id 配置;后台商品列表可在具体小程序下管理并切换审核展示。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-21 03:20:03 +08:00
parent ed627fa6f7
commit 6515568ec0
9 changed files with 249 additions and 42 deletions

View File

@@ -0,0 +1,44 @@
from django.db import migrations, models
def forwards_fill_club_id(apps, schema_editor):
Model = apps.get_model('shop', 'DianpuShangpinShenheShezhi')
# 历史全局单例 → 归到星阙 xq若已有多行则只保留一条
rows = list(Model.objects.all().order_by('id'))
if not rows:
return
keep = rows[0]
keep.club_id = keep.club_id or 'xq'
keep.save(update_fields=['club_id'])
for extra in rows[1:]:
extra.delete()
def noop_reverse(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('shop', '0003_zhi_kan_shenhe'),
]
operations = [
migrations.AddField(
model_name='dianpushangpinshenheshezhi',
name='club_id',
field=models.CharField(
db_index=True, default='xq', max_length=16, verbose_name='所属俱乐部',
),
),
migrations.RunPython(forwards_fill_club_id, noop_reverse),
migrations.AlterField(
model_name='dianpushangpinshenheshezhi',
name='club_id',
field=models.CharField(
db_index=True, default='xq', max_length=16, unique=True,
verbose_name='所属俱乐部',
),
),
]

View File

@@ -211,11 +211,14 @@ class ShangpinLeixingDianpu(QModel):
# shangdian/models.py 或独立应用 models.py
class DianpuShangpinShenheShezhi(QModel):
"""店铺商品审核模式全局配置(仅一条记录)"""
"""点单展示 / 店铺商品审核:按俱乐部各一条。"""
club_id = models.CharField(
max_length=16, unique=True, default='xq', db_index=True,
verbose_name='所属俱乐部',
)
kaiqi_shenhe = models.BooleanField(default=False, verbose_name='是否开启商品审核模式')
# True=未注册打手等特殊身份只看审核专用商品False=未绑店一律看正常公共商品
# True=未绑店且无打手等身份只看审核专用False=未绑店一律看正常公共商品
zhi_kan_shenhe = models.BooleanField(default=True, verbose_name='是否只看审核商品')
CreateTime = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
UpdateTime = models.DateTimeField(auto_now=True, verbose_name='更新时间')
@@ -224,7 +227,3 @@ class DianpuShangpinShenheShezhi(QModel):
db_table = 'dianpu_shangpin_shenhe_shezhi'
verbose_name = '商品审核模式配置'
verbose_name_plural = verbose_name
def save(self, *args, **kwargs):
self.pk = 1 # 强制使用 ID=1 保证唯一
super().save(*args, **kwargs)

View File

@@ -0,0 +1,43 @@
"""点单端商品展示 / 店铺审核模式:按俱乐部隔离。"""
from jituan.constants import CLUB_ID_DEFAULT
from shop.models import DianpuShangpinShenheShezhi
def _norm_club_id(club_id):
return (club_id or CLUB_ID_DEFAULT).strip() or CLUB_ID_DEFAULT
def get_or_create_shenhe_config(club_id):
"""获取或创建某俱乐部的审核展示配置。"""
cid = _norm_club_id(club_id)
config, _ = DianpuShangpinShenheShezhi.objects.get_or_create(
club_id=cid,
defaults={
'kaiqi_shenhe': False,
'zhi_kan_shenhe': True,
},
)
return config
def is_zhi_kan_shenhe_enabled(club_id):
"""
未绑店用户是否只看审核专用商品。
无配置时默认 True保持历史行为。
"""
config = DianpuShangpinShenheShezhi.query.filter(
club_id=_norm_club_id(club_id)
).first()
if not config:
return True
return bool(getattr(config, 'zhi_kan_shenhe', True))
def is_kaiqi_shenhe_enabled(club_id):
"""店铺发布商品是否需平台审核。无配置默认 False。"""
config = DianpuShangpinShenheShezhi.query.filter(
club_id=_norm_club_id(club_id)
).first()
if not config:
return False
return bool(config.kaiqi_shenhe)

View File

@@ -139,22 +139,20 @@ class ShopGoodsView(APIView):
# 店铺封禁或不属于当前俱乐部 → 公共正常商品
data = self._get_public_goods(True)
else:
# 未绑店:受「是否只看审核」开关控制
# 未绑店:受本俱乐部「是否只看审核」开关控制
# 开启 → 有特殊身份看正常(=1),否则看审核专用(=2)
# 关闭 → 一律看正常公共商品(与身份无关)
use_normal = True
if self._is_zhi_kan_shenhe_enabled():
if self._is_zhi_kan_shenhe_enabled(club_id):
use_normal = has_special
data = self._get_public_goods(use_normal)
return Response({'code': 200, 'data': data})
def _is_zhi_kan_shenhe_enabled(self):
"""全局开关:未绑店用户是否按身份只看审核专用商品。默认开启以保持历史行为"""
config = DianpuShangpinShenheShezhi.query.filter(id=1).first()
if not config:
return True
return bool(getattr(config, 'zhi_kan_shenhe', True))
def _is_zhi_kan_shenhe_enabled(self, club_id):
"""本俱乐部开关:未绑店用户是否按身份只看审核专用商品。默认开启。"""
from shop.services.shenhe_config import is_zhi_kan_shenhe_enabled
return is_zhi_kan_shenhe_enabled(club_id)
def _has_special_identity(self, user_main):
"""判断用户是否拥有打手/商家/管事/组长任一身份"""

View File

@@ -237,9 +237,10 @@ class ShopProductModifyView(APIView):
# 提取相对路径
tupian_url = full_url.replace(settings.COS_DOMAIN.rstrip('/') + '/', '', 1)
# 审核状态
audit_config = DianpuShangpinShenheShezhi.query.filter(id=1).first()
shenhe_status = not (audit_config and audit_config.kaiqi_shenhe)
# 审核状态(按店铺所属俱乐部)
from shop.services.shenhe_config import is_kaiqi_shenhe_enabled
shop_club = getattr(dianpu, 'club_id', None) or 'xq'
shenhe_status = not is_kaiqi_shenhe_enabled(shop_club)
ShangpinLeixingDianpu.query.create(
dianpu_id=dianpu.id,
@@ -320,8 +321,9 @@ class ShopProductModifyView(APIView):
# 审核重置
if content_changed:
audit_config = DianpuShangpinShenheShezhi.query.filter(id=1).first()
if audit_config and audit_config.kaiqi_shenhe:
from shop.services.shenhe_config import is_kaiqi_shenhe_enabled
shop_club = getattr(dianpu, 'club_id', None) or 'xq'
if is_kaiqi_shenhe_enabled(shop_club):
obj.shenhe_zhuangtai = False
update_fields.append('shenhe_zhuangtai')
@@ -872,8 +874,9 @@ class ShopProductModifyView1(APIView):
content_changed = True
if content_changed:
audit_config = DianpuShangpinShenheShezhi.query.filter(id=1).first()
if audit_config and audit_config.kaiqi_shenhe:
from shop.services.shenhe_config import is_kaiqi_shenhe_enabled
shop_club = getattr(dianpu, 'club_id', None) or 'xq'
if is_kaiqi_shenhe_enabled(shop_club):
product.shenhe_zhuangtai = False
update_fields.append('shenhe_zhuangtai')
@@ -962,8 +965,9 @@ class ShopProductModifyView1(APIView):
return Response({'code': 400, 'msg': '分成金额不能超过商品价格'})'''
shenhe_status = True
audit_config = DianpuShangpinShenheShezhi.query.filter(id=1).first()
if audit_config and audit_config.kaiqi_shenhe:
from shop.services.shenhe_config import is_kaiqi_shenhe_enabled
shop_club = getattr(dianpu, 'club_id', None) or 'xq'
if is_kaiqi_shenhe_enabled(shop_club):
shenhe_status = False
product = Shangpin.query.create(