diff --git a/peizhi/migrations/0019_xcx_sys_peizhi_shangpin_mode.py b/peizhi/migrations/0019_xcx_sys_peizhi_shangpin_mode.py new file mode 100644 index 0000000..734e5ae --- /dev/null +++ b/peizhi/migrations/0019_xcx_sys_peizhi_shangpin_mode.py @@ -0,0 +1,20 @@ +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('peizhi', '0018_xcx_xieyi_must_sign'), + ] + + operations = [ + migrations.AddField( + model_name='xcxsyspeizhi', + name='shangpin_shenhe_mode', + field=models.PositiveSmallIntegerField( + default=2, + help_text='1=正常运营(shenhezhuangtai=1),2=审核专用(shenhezhuangtai=2)', + verbose_name='点单商品展示模式', + ), + ), + ] diff --git a/peizhi/models.py b/peizhi/models.py index 8a8f16e..0b5ef19 100644 --- a/peizhi/models.py +++ b/peizhi/models.py @@ -696,6 +696,12 @@ class XcxSysPeizhi(models.Model): notify_base_url = models.CharField( max_length=300, blank=True, default='https://wenhe.nmslb.com/hqhd', verbose_name='业务回调根URL' ) + # 点单页 /shangpin/shangpinhuoqu 按此值筛选类型/专区/商品的 shenhezhuangtai + shangpin_shenhe_mode = models.PositiveSmallIntegerField( + default=2, + verbose_name='点单商品展示模式', + help_text='1=正常运营(shenhezhuangtai=1),2=审核专用(shenhezhuangtai=2)', + ) update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间') class Meta: diff --git a/peizhi/xcx_config_views.py b/peizhi/xcx_config_views.py index 5f6e1f9..db12d07 100644 --- a/peizhi/xcx_config_views.py +++ b/peizhi/xcx_config_views.py @@ -113,6 +113,7 @@ class XcxSysPeizhiQueryView(APIView): 'weixin_cert_path': row.weixin_cert_path if row else wx_cfg.WEIXIN_CERT_PATH, 'weixin_key_path': row.weixin_key_path if row else wx_cfg.WEIXIN_KEY_PATH, 'notify_base_url': row.notify_base_url if row else wx_cfg.NOTIFY_BASE_URL, + 'shangpin_shenhe_mode': row.shangpin_shenhe_mode if row else wx_cfg.SHANGPIN_SHENHE_MODE, 'from_database': bool(row), } return Response({'code': 0, 'msg': 'success', 'data': data}) @@ -129,7 +130,7 @@ class XcxSysPeizhiUpdateView(APIView): 'weixin_official_token', 'weixin_official_encoding_aes_key', 'weixin_template_id', 'weixin_template_max_per_minute', 'weixin_template_batch_size', 'weixin_broadcast_enabled', 'weixin_broadcast_workers', 'weixin_mchid', 'weixin_shanghu_miyao', 'weixin_notify_url', - 'weixin_cert_path', 'weixin_key_path', 'notify_base_url', + 'weixin_cert_path', 'weixin_key_path', 'notify_base_url', 'shangpin_shenhe_mode', }) def post(self, request): @@ -149,6 +150,11 @@ class XcxSysPeizhiUpdateView(APIView): row.weixin_broadcast_enabled = bool(val) elif key in ('weixin_template_max_per_minute', 'weixin_template_batch_size', 'weixin_broadcast_workers'): row.__setattr__(key, int(val)) + elif key == 'shangpin_shenhe_mode': + mode = int(val) + if mode not in (1, 2): + continue + row.shangpin_shenhe_mode = mode else: row.__setattr__(key, str(val).strip()) row.save() diff --git a/shangpin/views.py b/shangpin/views.py index 99bb982..8a2deeb 100644 --- a/shangpin/views.py +++ b/shangpin/views.py @@ -5,6 +5,7 @@ from rest_framework import status from rest_framework.throttling import AnonRateThrottle from django.db import models from shangpin.models import ShangpinLeixing, ShangpinZhuanqu, Shangpin +from utils.xcx_sys_config import get_shangpin_shenhe_zhuangtai import logging from rest_framework.permissions import AllowAny # 新增这行 @@ -30,16 +31,12 @@ class ShangpinHuoquView(APIView): try: logger.info("收到商品数据获取请求") - # 1. 查询商品类型(只查询正常状态的类型,并排序) - # 正常运营:只显示 shenhezhuangtai=2 的商品类型 - leixing_queryset = ShangpinLeixing.objects.filter( - shenhezhuangtai=2 # 只取正常状态 - ).order_by('-paixu', 'id') # 先按paixu降序,再按id升序 + shenhe_filter = get_shangpin_shenhe_zhuangtai() + logger.info("点单商品展示模式 shenhezhuangtai=%s", shenhe_filter) - # 注意:审核期间使用下面这行代码(先注释掉) - '''leixing_queryset = ShangpinLeixing.objects.filter( - shenhezhuangtai=2 # 审核期间:只取审核专用状态 - ).order_by('-paixu', 'id')''' + leixing_queryset = ShangpinLeixing.objects.filter( + shenhezhuangtai=shenhe_filter, + ).order_by('-paixu', 'id') shangpinleixing_data = [] for leixing in leixing_queryset: @@ -57,8 +54,8 @@ class ShangpinHuoquView(APIView): if visible_leixing_ids: zhuanqu_queryset = ShangpinZhuanqu.objects.filter( leixing_id__in=visible_leixing_ids, - shenhezhuangtai=2 # 🔴【添加】只筛选审核状态为2的专区 - ).order_by('-paixu', 'id') # 先按paixu降序,再按id升序 + shenhezhuangtai=shenhe_filter, + ).order_by('-paixu', 'id') else: zhuanqu_queryset = ShangpinZhuanqu.objects.none() @@ -79,7 +76,7 @@ class ShangpinHuoquView(APIView): # 注意:这里使用values()只获取指定字段,提高查询效率 shangpin_queryset = Shangpin.objects.filter( zhuanqu_id__in=visible_zhuanqu_ids, - shenhezhuangtai=2 # 🔴【添加】只筛选审核状态为2的商品 + shenhezhuangtai=shenhe_filter, ).values( 'id', 'biaoqian', 'jiage', 'leixing_id', 'zhuanqu_id', 'tupian_url', 'duiwai_xiaoliang', 'paixu' diff --git a/utils/xcx_sys_config.py b/utils/xcx_sys_config.py index e82f029..afac95d 100644 --- a/utils/xcx_sys_config.py +++ b/utils/xcx_sys_config.py @@ -119,5 +119,17 @@ class WxConfig: def NOTIFY_BASE_URL(self): return _val('notify_base_url', None, 'https://wenhe.nmslb.com/hqhd').rstrip('/') + @property + def SHANGPIN_SHENHE_MODE(self): + row = _load_row() + if row is not None and row.shangpin_shenhe_mode in (1, 2): + return int(row.shangpin_shenhe_mode) + return 2 + wx_cfg = WxConfig() + + +def get_shangpin_shenhe_zhuangtai(): + """点单页商品接口筛选 shenhezhuangtai:1=正常,2=审核专用""" + return wx_cfg.SHANGPIN_SHENHE_MODE