feat: 订单列表/详情返回自动结算倒计时字段,并加小程序结算率接口

仅 eligible 结算中订单下发预计时间;支持 auto_settle_pending 筛选;新增 /dingdan/wo-de-deal-stat。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-27 02:08:32 +08:00
parent 9ac0a3a5ad
commit 1b733d21cc
8 changed files with 192 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ from rank.models import DingdanBiaoqian, YonghuChenghao
from users.business_models import User
from users.models import UserShangjia
from backend.utils import fmt_datetime
from jituan.services.order_deal import order_auto_settle_payload
logger = logging.getLogger(__name__)
@@ -126,7 +127,7 @@ def enrich_merchant_order_list_items(ext_list, club_id=None):
zid = o.AssignedID or ''
zinfo = zhiding_info.get(zid, {})
result.append({
item = {
'dingdan_id': oid,
'zhuangtai': o.Status,
'jine': float(o.Amount) if o.Amount else 0.0,
@@ -149,6 +150,8 @@ def enrich_merchant_order_list_items(ext_list, club_id=None):
'zhiding_uid': zid,
'zhiding_avatar': zinfo.get('avatar', ''),
'zhiding_nicheng': zinfo.get('nicheng', ''),
})
}
item.update(order_auto_settle_payload(o))
result.append(item)
return result

View File

@@ -47,6 +47,38 @@ def parse_order_list_bound(value, is_end=False):
return _db_dt(dt)
def wants_auto_settle_pending(data) -> bool:
"""前端筛「待自动结算」auto_settle_pending = 1/true。"""
if not data:
return False
v = data.get('auto_settle_pending')
if v is True or v == 1:
return True
if isinstance(v, str) and v.strip().lower() in ('1', 'true', 'yes'):
return True
return False
def apply_auto_settle_pending_filter(qs, data, *, through_order=True):
"""
仅 Status=8 且 AutoSettleEligible 且有到期时间。
through_order=TrueMerchantOrderExtOrder__*FalseOrder 本表。
"""
if not wants_auto_settle_pending(data):
return qs
if through_order:
return qs.filter(
Order__Status=8,
Order__AutoSettleEligible=True,
Order__AutoExpireAt__isnull=False,
)
return qs.filter(
Status=8,
AutoSettleEligible=True,
AutoExpireAt__isnull=False,
)
def apply_merchant_order_list_filters(qs, data):
"""在 MerchantOrderExt 查询集上应用类型/关键字/时间段筛选。"""
leixing_id = pick_leixing_id(data)
@@ -95,4 +127,5 @@ def apply_merchant_order_list_filters(qs, data):
return qs.none()
qs = qs.filter(Order__OrderID__in=order_ids)
qs = apply_auto_settle_pending_filter(qs, data, through_order=True)
return qs

View File

@@ -13,6 +13,7 @@ from .views import CreateOrderView, WechatPayNotifyView, AlipayPayNotifyView, al
LianTongPeiDuiDingDanLieBiaoView, LianTongDingDanZhuangTaiView, LianTongDingDanZhuangTaiPiLiangView, \
ZhiDingChaxunView, ZhiDingHuiFuView
from jituan.services.fubei_notify import FubeiPayNotifyView
from jituan.views_order_deal import MiniappMyDealStatView
urlpatterns = [
@@ -39,6 +40,7 @@ urlpatterns = [
path('sjchufa', ShangjiaChufaShenqingView.as_view(), name='商家处罚打手申请'),
path('ddlxhq', ShangpinLeixingHuoquView.as_view(), name='打手抢单页商品类型获取'),
path('dshqdingdan', DashouDingdanHuoquView1.as_view(), name='打手订单列表页面获取'),
path('wo-de-deal-stat', MiniappMyDealStatView.as_view(), name='小程序我的结算率罚款率'),
# 获取订单列表
path('ddhq', DashouDingdanHuoquView.as_view(), name='打手抢单页获取订单'),

View File

@@ -679,6 +679,11 @@ class DashouDingdanHuoquView1(APIView):
keyword_query = Q(OrderID__icontains=keyword) | Q(Description__icontains=keyword)
query &= keyword_query
from orders.services.merchant_order_list_filters import wants_auto_settle_pending
# 待自动结算筛:强制落在结算中且 eligible
if wants_auto_settle_pending(data):
query &= Q(Status=8, AutoSettleEligible=True, AutoExpireAt__isnull=False)
# 5. 执行查询,按创建时间倒序
dingdan_query = Order.query.filter(query).order_by('-CreateTime')
@@ -690,7 +695,9 @@ class DashouDingdanHuoquView1(APIView):
'Description',
'ImageURL',
'Nickname',
'CreateTime'
'CreateTime',
'AutoSettleEligible',
'AutoExpireAt',
)
total_count = dingdan_query.count()
@@ -702,6 +709,7 @@ class DashouDingdanHuoquView1(APIView):
current_page_count = len(current_page_orders)
# 7. 构建返回数据列表
from jituan.services.order_deal import order_auto_settle_payload
order_list = []
for order in current_page_orders:
order_data = {
@@ -713,6 +721,7 @@ class DashouDingdanHuoquView1(APIView):
'nicheng': order.Nickname or '',
**datetime_aliases(order.CreateTime),
}
order_data.update(order_auto_settle_payload(order))
order_list.append(order_data)
# 8. 判断是否还有更多数据
@@ -1278,6 +1287,11 @@ class DashouDingdanXiangqingView(APIView):
'fuwudashou_id': dingdan.PlayerID or '',
'fadanpingtai': dingdan.Platform or ''
}
try:
from jituan.services.order_deal import order_auto_settle_payload
dingdan_data.update(order_auto_settle_payload(dingdan))
except Exception:
pass
# 6. 查询打手提交的图片
dashou_tupian_list = PlayerDeliveryImage.query.filter(

View File

@@ -754,6 +754,12 @@ class ShangjiaDingdanXiangqingView(APIView):
'laoban_shouji': getattr(shangjia_kuozhan, 'BossPhone', '') or '',
}
try:
from jituan.services.order_deal import order_auto_settle_payload
response_data.update(order_auto_settle_payload(order))
except Exception as e:
logger.warning('自动结算展示字段附加失败: %s', e)
try:
from merchant_ops.services.order_enrich import enrich_order_detail_data
enrich_order_detail_data(response_data, dingdan_id)