提交
This commit is contained in:
1 parent
771f010a39
commit
ee4abd361e
102 files changed
+8021
-4094
No files matched your search
+1
-1
@@ -1 +1 @@
|
||||
89592
|
||||
21868
|
||||
@@ -1619,6 +1619,7 @@ class TxnRechargeBody(BaseModel):
|
||||
|
||||
amount: float = Field(..., gt=0, alias="amount")
|
||||
remark: Optional[str] = Field(None, alias="remark")
|
||||
finance_submit_attachments: Optional[str] = Field(None, alias="financeSubmitAttachments")
|
||||
|
||||
|
||||
class TxnRefundBody(BaseModel):
|
||||
@@ -1654,6 +1655,14 @@ class TxnUnsubscribeBody(BaseModel):
|
||||
remark: Optional[str] = Field(None, alias="remark")
|
||||
|
||||
|
||||
class TxnUpdateBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
amount: Optional[float] = Field(None, gt=0, alias="amount")
|
||||
remark: Optional[str] = Field(None, alias="remark")
|
||||
finance_submit_attachments: Optional[str] = Field(None, alias="financeSubmitAttachments")
|
||||
|
||||
|
||||
class TxnFinanceSubmitBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
@@ -1933,6 +1942,7 @@ async def list_service_order_txns(
|
||||
keyword: Optional[str] = None,
|
||||
createTimeStart: Optional[str] = Query(None, alias="createTimeStart"),
|
||||
createTimeEnd: Optional[str] = Query(None, alias="createTimeEnd"),
|
||||
financeDoneOnly: Optional[bool] = Query(False, alias="financeDoneOnly"),
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
@@ -1945,6 +1955,7 @@ async def list_service_order_txns(
|
||||
keyword=keyword,
|
||||
create_time_start=createTimeStart,
|
||||
create_time_end=createTimeEnd,
|
||||
finance_done_only=bool(financeDoneOnly),
|
||||
page=page,
|
||||
page_size=pageSize,
|
||||
tenant_no=tenant_no,
|
||||
@@ -1966,17 +1977,7 @@ async def get_service_order_txn_detail(
|
||||
txn = ps_svc.get_service_order_txn(db, txn_id, tenant_no=tenant_no)
|
||||
if not txn:
|
||||
return error_response(404, "流水不存在")
|
||||
txn_dict = ps_svc._row_to_dict_service_order_txn(txn, db, tenant_no)
|
||||
order = ps_svc.get_service_order(db, txn.service_order_id, tenant_no=tenant_no)
|
||||
if order:
|
||||
txn_dict["channelName"] = order.channel_name or ""
|
||||
txn_dict["orderType"] = order.order_type or ""
|
||||
user_ids = [x for x in (txn.create_by, txn.finance_submit_by) if x]
|
||||
name_map = ps_svc._user_nick_name_map(db, user_ids)
|
||||
txn_dict["createByName"] = name_map.get(txn.create_by or "", "") or (txn.create_by or "")
|
||||
txn_dict["financeSubmitByName"] = name_map.get(txn.finance_submit_by or "", "") or (
|
||||
txn.finance_submit_by or ""
|
||||
)
|
||||
txn_dict = ps_svc._service_order_txn_to_response_dict(db, txn, tenant_no)
|
||||
return success_response(txn_dict)
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
@@ -1996,6 +1997,7 @@ async def create_recharge_txn(
|
||||
order_id,
|
||||
amount=body.amount,
|
||||
remark=body.remark,
|
||||
finance_submit_attachments=body.finance_submit_attachments,
|
||||
tenant_no=tenant_no,
|
||||
user_id=user.get("user_id"),
|
||||
)
|
||||
@@ -2080,6 +2082,31 @@ async def create_unsubscribe_txn(
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.put("/channel-service-order-txns/{txn_id}")
|
||||
async def update_service_order_txn(
|
||||
txn_id: str,
|
||||
body: TxnUpdateBody,
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
txn = ps_svc.update_service_order_txn(
|
||||
db,
|
||||
txn_id,
|
||||
amount=body.amount,
|
||||
remark=body.remark,
|
||||
finance_submit_attachments=body.finance_submit_attachments,
|
||||
tenant_no=tenant_no,
|
||||
user_id=user.get("user_id"),
|
||||
)
|
||||
return success_response(
|
||||
ps_svc._row_to_dict_service_order_txn(txn, db, tenant_no), message="更新成功"
|
||||
)
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
|
||||
@router.post("/channel-service-order-txns/{txn_id}/submit-finance")
|
||||
async def submit_txn_finance(
|
||||
txn_id: str,
|
||||
@@ -2122,7 +2149,8 @@ async def confirm_txn(
|
||||
user_id=user.get("user_id"),
|
||||
)
|
||||
return success_response(
|
||||
ps_svc._row_to_dict_service_order_txn(txn, db, tenant_no), message="财务确认成功"
|
||||
ps_svc._service_order_txn_to_response_dict(db, txn, tenant_no),
|
||||
message="财务确认成功",
|
||||
)
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
@@ -2143,7 +2171,8 @@ async def void_txn(
|
||||
user_id=user.get("user_id"),
|
||||
)
|
||||
return success_response(
|
||||
ps_svc._row_to_dict_service_order_txn(txn, db, tenant_no), message="作废成功"
|
||||
ps_svc._service_order_txn_to_response_dict(db, txn, tenant_no),
|
||||
message="作废成功",
|
||||
)
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
|
||||
@@ -2598,9 +2598,12 @@ def _row_to_dict_service_order_txn(row, db=None, tenant_no=None) -> Dict[str, An
|
||||
"financeSubmitAttachments": row.finance_submit_attachments or "",
|
||||
"financeSubmitAttachmentFiles": urls_to_attachment_list(row.finance_submit_attachments, db, tn) if db and row.finance_submit_attachments else [],
|
||||
"financeConfirmTime": row.finance_confirm_time.strftime("%Y-%m-%d %H:%M:%S") if row.finance_confirm_time else "",
|
||||
"financeConfirmBy": row.finance_confirm_by or "",
|
||||
"financeConfirmAttachments": row.finance_confirm_attachments or "",
|
||||
"financeConfirmAttachmentFiles": urls_to_attachment_list(row.finance_confirm_attachments, db, tn) if db and row.finance_confirm_attachments else [],
|
||||
"financeRemark": row.finance_remark or "",
|
||||
"voidBy": row.void_by or "",
|
||||
"voidTime": row.void_time.strftime("%Y-%m-%d %H:%M:%S") if row.void_time else "",
|
||||
"balanceBefore": float(row.balance_before) if row.balance_before else 0,
|
||||
"balanceAfter": float(row.balance_after) if row.balance_after else 0,
|
||||
"tenantNo": row.tenant_no or "",
|
||||
@@ -2618,6 +2621,71 @@ def _row_to_dict_service_order_txn(row, db=None, tenant_no=None) -> Dict[str, An
|
||||
return d
|
||||
|
||||
|
||||
def _service_order_txn_to_response_dict(
|
||||
db,
|
||||
txn,
|
||||
tenant_no=None,
|
||||
*,
|
||||
order=None,
|
||||
name_map=None,
|
||||
) -> Dict[str, Any]:
|
||||
"""流水响应字典:含订单渠道信息与提交人/创建人昵称。"""
|
||||
d = _row_to_dict_service_order_txn(txn, db, tenant_no)
|
||||
if order is None and txn.service_order_id:
|
||||
order = get_service_order(db, txn.service_order_id, tenant_no)
|
||||
if order:
|
||||
d["channelName"] = order.channel_name or ""
|
||||
d["deptName"] = order.dept_name or ""
|
||||
d["orderType"] = order.order_type or ""
|
||||
confirm_uid = txn.finance_confirm_by or (
|
||||
txn.update_by
|
||||
if (txn.txn_status or "") == "yqr" and txn.finance_confirm_time and not txn.finance_confirm_by
|
||||
else None
|
||||
)
|
||||
void_uid = txn.void_by or (
|
||||
txn.update_by
|
||||
if (txn.txn_status or "") == "yzf"
|
||||
and txn.finance_submit_time
|
||||
and not txn.void_by
|
||||
else None
|
||||
)
|
||||
if name_map is None:
|
||||
user_ids = [x for x in (txn.create_by, txn.finance_submit_by, confirm_uid, void_uid) if x]
|
||||
name_map = _user_nick_name_map(db, user_ids) if db and user_ids else {}
|
||||
d["createByName"] = name_map.get(txn.create_by or "", "") or (txn.create_by or "")
|
||||
d["financeSubmitByName"] = name_map.get(txn.finance_submit_by or "", "") or (
|
||||
txn.finance_submit_by or ""
|
||||
)
|
||||
d["financeConfirmByName"] = name_map.get(confirm_uid or "", "") or (confirm_uid or "")
|
||||
if not d.get("voidTime") and (txn.txn_status or "") == "yzf" and txn.update_time:
|
||||
d["voidTime"] = txn.update_time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
d["voidByName"] = name_map.get(void_uid or "", "") or (void_uid or "")
|
||||
if not (d.get("financeSubmitRemark") or "").strip() and (d.get("remark") or "").strip():
|
||||
d["financeSubmitRemark"] = (d.get("remark") or "").strip()
|
||||
_enrich_finance_operate_fields(d, txn)
|
||||
return d
|
||||
|
||||
|
||||
def _enrich_finance_operate_fields(d: Dict[str, Any], txn) -> None:
|
||||
"""财务页「已处理」展示:操作类型、操作人、操作时间。"""
|
||||
status = txn.txn_status or ""
|
||||
if status == "yqr" and txn.finance_confirm_time:
|
||||
d["financeOperateType"] = "confirm"
|
||||
d["financeOperateTypeLabel"] = "财务确认"
|
||||
d["financeOperateByName"] = d.get("financeConfirmByName") or d.get("financeConfirmBy") or ""
|
||||
d["financeOperateTime"] = d.get("financeConfirmTime") or ""
|
||||
elif status == "yzf" and txn.finance_submit_time:
|
||||
d["financeOperateType"] = "void"
|
||||
d["financeOperateTypeLabel"] = "财务作废"
|
||||
d["financeOperateByName"] = d.get("voidByName") or d.get("voidBy") or ""
|
||||
d["financeOperateTime"] = d.get("voidTime") or ""
|
||||
else:
|
||||
d["financeOperateType"] = ""
|
||||
d["financeOperateTypeLabel"] = ""
|
||||
d["financeOperateByName"] = ""
|
||||
d["financeOperateTime"] = ""
|
||||
|
||||
|
||||
def list_channel_service_orders(
|
||||
db,
|
||||
*,
|
||||
@@ -2879,11 +2947,10 @@ def create_channel_service_order(
|
||||
order_status = "dsx"
|
||||
|
||||
if order_type == "yfk":
|
||||
# 预存款订单:创建后为待生效,市场发起财务确认后进入待确认
|
||||
if not prepay_amount or float(prepay_amount) <= 0:
|
||||
raise ValueError("预存金额必须大于0")
|
||||
# 预存款订单:创建后为待生效,充值金额通过「发起充值」流水录入
|
||||
_get_valid_channel_agreement(db, channel_agreement_id, channel_id, tenant_no)
|
||||
order_status = "dsx"
|
||||
prepay_amount = None
|
||||
|
||||
elif order_type == "gmcp":
|
||||
# 购买产品订单:创建后为待生效,走财务确认后生效
|
||||
@@ -2903,7 +2970,7 @@ def create_channel_service_order(
|
||||
channel_name=channel_name or channel.channel_name or "",
|
||||
dept_name=dept_name or "",
|
||||
order_type=order_type,
|
||||
prepay_amount=prepay_amount if order_type == "yfk" else None,
|
||||
prepay_amount=None,
|
||||
purchase_total_amount=purchase_total_amount,
|
||||
order_status=order_status,
|
||||
channel_agreement_id=channel_agreement_id,
|
||||
@@ -2932,7 +2999,7 @@ def create_channel_service_order(
|
||||
|
||||
|
||||
def update_channel_service_order(db, order_id, *, tenant_no=None, user_id=None, products=None, **kwargs):
|
||||
"""待生效状态下可更新;预存款可改协议与充值金额,购买订单可改协议与产品明细"""
|
||||
"""待生效状态下可更新;预存款可改协议,购买订单可改协议与产品明细"""
|
||||
order = get_service_order(db, order_id, tenant_no)
|
||||
if not order:
|
||||
raise ValueError("订单不存在")
|
||||
@@ -2943,11 +3010,6 @@ def update_channel_service_order(db, order_id, *, tenant_no=None, user_id=None,
|
||||
if "remark" in kwargs and kwargs["remark"] is not None:
|
||||
order.remark = kwargs["remark"]
|
||||
if order.order_type == "yfk":
|
||||
if "prepay_amount" in kwargs and kwargs["prepay_amount"] is not None:
|
||||
amt = float(kwargs["prepay_amount"])
|
||||
if amt <= 0:
|
||||
raise ValueError("预存金额必须大于0")
|
||||
order.prepay_amount = amt
|
||||
if "channel_agreement_id" in kwargs and kwargs["channel_agreement_id"] is not None:
|
||||
_get_valid_channel_agreement(
|
||||
db, kwargs["channel_agreement_id"], order.channel_id, tenant_no
|
||||
@@ -3185,21 +3247,33 @@ def list_service_order_txns(
|
||||
keyword=None,
|
||||
create_time_start=None,
|
||||
create_time_end=None,
|
||||
finance_done_only=False,
|
||||
page=1,
|
||||
page_size=20,
|
||||
tenant_no=None,
|
||||
):
|
||||
"""查询操作流水列表"""
|
||||
"""查询操作流水列表。finance_done_only:财务已处理(已确认或财务侧作废)。"""
|
||||
q = db.query(BizChannelServiceOrderTxn).filter(BizChannelServiceOrderTxn.del_flag == 0)
|
||||
if tenant_no:
|
||||
q = q.filter(BizChannelServiceOrderTxn.tenant_no == tenant_no)
|
||||
if service_order_id:
|
||||
q = q.filter(BizChannelServiceOrderTxn.service_order_id == service_order_id)
|
||||
ss = (txn_status or "").strip()
|
||||
if ss:
|
||||
statuses = [s.strip() for s in ss.split(",") if s.strip()]
|
||||
if statuses:
|
||||
q = q.filter(BizChannelServiceOrderTxn.txn_status.in_(statuses))
|
||||
if finance_done_only:
|
||||
q = q.filter(
|
||||
or_(
|
||||
BizChannelServiceOrderTxn.txn_status == "yqr",
|
||||
and_(
|
||||
BizChannelServiceOrderTxn.txn_status == "yzf",
|
||||
BizChannelServiceOrderTxn.finance_submit_time.isnot(None),
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
ss = (txn_status or "").strip()
|
||||
if ss:
|
||||
statuses = [s.strip() for s in ss.split(",") if s.strip()]
|
||||
if statuses:
|
||||
q = q.filter(BizChannelServiceOrderTxn.txn_status.in_(statuses))
|
||||
tt = (txn_type or "").strip()
|
||||
if tt:
|
||||
types = [t.strip() for t in tt.split(",") if t.strip()]
|
||||
@@ -3234,8 +3308,66 @@ def list_service_order_txns(
|
||||
total = q.order_by(None).with_entities(func.count(BizChannelServiceOrderTxn.id)).scalar() or 0
|
||||
page = max(1, page)
|
||||
page_size = min(max(1, page_size), 100)
|
||||
rows = q.order_by(BizChannelServiceOrderTxn.create_time.desc()).offset((page - 1) * page_size).limit(page_size).all()
|
||||
return [_row_to_dict_service_order_txn(r, db, tenant_no) for r in rows], int(total)
|
||||
if finance_done_only:
|
||||
operate_time = func.coalesce(
|
||||
BizChannelServiceOrderTxn.finance_confirm_time,
|
||||
BizChannelServiceOrderTxn.void_time,
|
||||
)
|
||||
rows = (
|
||||
q.order_by(operate_time.desc(), BizChannelServiceOrderTxn.create_time.desc())
|
||||
.offset((page - 1) * page_size)
|
||||
.limit(page_size)
|
||||
.all()
|
||||
)
|
||||
else:
|
||||
rows = (
|
||||
q.order_by(BizChannelServiceOrderTxn.create_time.desc())
|
||||
.offset((page - 1) * page_size)
|
||||
.limit(page_size)
|
||||
.all()
|
||||
)
|
||||
if not rows:
|
||||
return [], int(total)
|
||||
|
||||
order_ids = list({r.service_order_id for r in rows if r.service_order_id})
|
||||
orders: Dict[str, Any] = {}
|
||||
if order_ids:
|
||||
oq = db.query(BizChannelServiceOrder).filter(
|
||||
BizChannelServiceOrder.id.in_(order_ids),
|
||||
BizChannelServiceOrder.del_flag == 0,
|
||||
)
|
||||
if tenant_no:
|
||||
oq = oq.filter(BizChannelServiceOrder.tenant_no == tenant_no)
|
||||
for o in oq.all():
|
||||
orders[o.id] = o
|
||||
|
||||
user_ids: List[str] = []
|
||||
for r in rows:
|
||||
if r.create_by:
|
||||
user_ids.append(r.create_by)
|
||||
if r.finance_submit_by:
|
||||
user_ids.append(r.finance_submit_by)
|
||||
if r.finance_confirm_by:
|
||||
user_ids.append(r.finance_confirm_by)
|
||||
elif (r.txn_status or "") == "yqr" and r.update_by:
|
||||
user_ids.append(r.update_by)
|
||||
if r.void_by:
|
||||
user_ids.append(r.void_by)
|
||||
elif (r.txn_status or "") == "yzf" and r.finance_submit_time and r.update_by:
|
||||
user_ids.append(r.update_by)
|
||||
name_map = _user_nick_name_map(db, user_ids) if db and user_ids else {}
|
||||
|
||||
items = [
|
||||
_service_order_txn_to_response_dict(
|
||||
db,
|
||||
r,
|
||||
tenant_no,
|
||||
order=orders.get(r.service_order_id),
|
||||
name_map=name_map,
|
||||
)
|
||||
for r in rows
|
||||
]
|
||||
return items, int(total)
|
||||
|
||||
|
||||
def get_service_order_txn(db, txn_id, *, tenant_no=None):
|
||||
@@ -3248,8 +3380,17 @@ def get_service_order_txn(db, txn_id, *, tenant_no=None):
|
||||
return q.first()
|
||||
|
||||
|
||||
def create_recharge_txn(db, order_id, *, amount, remark=None, tenant_no=None, user_id=None):
|
||||
"""创建充值流水(yfk订单),状态 dsx"""
|
||||
def create_recharge_txn(
|
||||
db,
|
||||
order_id,
|
||||
*,
|
||||
amount,
|
||||
remark=None,
|
||||
finance_submit_attachments=None,
|
||||
tenant_no=None,
|
||||
user_id=None,
|
||||
):
|
||||
"""创建充值流水(yfk订单),状态 dsx;附件预存于 finance_submit_attachments 供后续财务确认"""
|
||||
order = get_service_order(db, order_id, tenant_no)
|
||||
if not order:
|
||||
raise ValueError("订单不存在")
|
||||
@@ -3270,6 +3411,7 @@ def create_recharge_txn(db, order_id, *, amount, remark=None, tenant_no=None, us
|
||||
amount=amount,
|
||||
txn_status="dsx",
|
||||
remark=remark or "",
|
||||
finance_submit_attachments=(finance_submit_attachments or "").strip() or None,
|
||||
tenant_no=tenant_no or order.tenant_no,
|
||||
order_num=0,
|
||||
create_by=user_id,
|
||||
@@ -3497,6 +3639,56 @@ def create_unsubscribe_txn(db, order_id, *, products, remark=None, tenant_no=Non
|
||||
return txn
|
||||
|
||||
|
||||
def update_service_order_txn(
|
||||
db,
|
||||
txn_id,
|
||||
*,
|
||||
amount=None,
|
||||
remark=None,
|
||||
finance_submit_attachments=None,
|
||||
tenant_no=None,
|
||||
user_id=None,
|
||||
):
|
||||
"""更新待生效流水:仅 dsx;充值/退款可改金额,购买/退订仅可改备注与凭证"""
|
||||
txn = get_service_order_txn(db, txn_id, tenant_no=tenant_no)
|
||||
if not txn:
|
||||
raise ValueError("流水不存在")
|
||||
if txn.txn_status != "dsx":
|
||||
raise ValueError("仅待生效流水可编辑")
|
||||
|
||||
now = datetime.now()
|
||||
txn_type = (txn.txn_type or "").strip()
|
||||
|
||||
if amount is not None:
|
||||
amt = float(amount)
|
||||
if amt <= 0:
|
||||
raise ValueError("金额必须大于0")
|
||||
if txn_type in ("recharge", "refund"):
|
||||
if txn_type == "refund":
|
||||
order = get_service_order(db, txn.service_order_id, tenant_no)
|
||||
if not order:
|
||||
raise ValueError("关联订单不存在")
|
||||
current_balance = float(order.current_balance) if order.current_balance else 0
|
||||
if amt > current_balance:
|
||||
raise ValueError(f"退款金额不能大于当前余额 {current_balance}")
|
||||
txn.amount = amt
|
||||
else:
|
||||
raise ValueError("购买/退订流水不可修改金额,请作废后重新发起")
|
||||
|
||||
if remark is not None:
|
||||
txn.remark = remark or ""
|
||||
|
||||
if finance_submit_attachments is not None:
|
||||
txn.finance_submit_attachments = (finance_submit_attachments or "").strip() or None
|
||||
|
||||
txn.update_by = user_id
|
||||
txn.update_time = now
|
||||
db.add(txn)
|
||||
db.commit()
|
||||
db.refresh(txn)
|
||||
return txn
|
||||
|
||||
|
||||
def submit_txn_finance(db, txn_id, *, finance_submit_remark=None, finance_submit_attachments=None, tenant_no=None, user_id=None):
|
||||
"""发起流水财务确认:dsx → dqr"""
|
||||
txn = get_service_order_txn(db, txn_id, tenant_no=tenant_no)
|
||||
@@ -3509,8 +3701,14 @@ def submit_txn_finance(db, txn_id, *, finance_submit_remark=None, finance_submit
|
||||
txn.txn_status = "dqr"
|
||||
txn.finance_submit_by = user_id
|
||||
txn.finance_submit_time = now
|
||||
txn.finance_submit_remark = finance_submit_remark or ""
|
||||
txn.finance_submit_attachments = finance_submit_attachments or ""
|
||||
submit_remark = (finance_submit_remark or "").strip()
|
||||
if not submit_remark:
|
||||
submit_remark = (txn.remark or "").strip()
|
||||
txn.finance_submit_remark = submit_remark
|
||||
if finance_submit_attachments:
|
||||
txn.finance_submit_attachments = finance_submit_attachments
|
||||
elif not (txn.finance_submit_attachments or "").strip():
|
||||
txn.finance_submit_attachments = ""
|
||||
txn.update_by = user_id
|
||||
txn.update_time = now
|
||||
db.add(txn)
|
||||
@@ -3615,6 +3813,7 @@ def confirm_txn(db, txn_id, *, finance_remark=None, finance_confirm_attachments=
|
||||
# Update txn status
|
||||
txn.txn_status = "yqr"
|
||||
txn.finance_confirm_time = now
|
||||
txn.finance_confirm_by = user_id
|
||||
txn.finance_confirm_attachments = finance_confirm_attachments or ""
|
||||
txn.finance_remark = finance_remark or ""
|
||||
txn.update_by = user_id
|
||||
@@ -3634,12 +3833,12 @@ def confirm_txn(db, txn_id, *, finance_remark=None, finance_confirm_attachments=
|
||||
|
||||
|
||||
def void_txn(db, txn_id, *, tenant_no=None, user_id=None):
|
||||
"""作废流水:dsx → yzf。如果是 purchase/unsubscribe 还需要回滚产品持仓"""
|
||||
"""作废流水:dsx/dqr → yzf。如果是 purchase/unsubscribe 还需要回滚产品持仓"""
|
||||
txn = get_service_order_txn(db, txn_id, tenant_no=tenant_no)
|
||||
if not txn:
|
||||
raise ValueError("流水不存在")
|
||||
if txn.txn_status != "dsx":
|
||||
raise ValueError("仅待生效流水可作废")
|
||||
if txn.txn_status not in ("dsx", "dqr"):
|
||||
raise ValueError("仅待生效或待财务确认流水可作废")
|
||||
|
||||
now = datetime.now()
|
||||
order = get_service_order(db, txn.service_order_id, tenant_no)
|
||||
@@ -3692,6 +3891,8 @@ def void_txn(db, txn_id, *, tenant_no=None, user_id=None):
|
||||
db.add(existing)
|
||||
|
||||
txn.txn_status = "yzf"
|
||||
txn.void_by = user_id
|
||||
txn.void_time = now
|
||||
txn.update_by = user_id
|
||||
txn.update_time = now
|
||||
db.add(txn)
|
||||
|
||||
+41
-3
@@ -1,9 +1,12 @@
|
||||
"""FastAPI 应用入口(骨架工程)"""
|
||||
from contextlib import asynccontextmanager
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import JSONResponse
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.database import SessionLocal
|
||||
@@ -58,6 +61,43 @@ app.add_middleware(CORSMiddleware, **_cors_kw)
|
||||
app.add_middleware(ApiRequestLogMiddleware)
|
||||
app.add_middleware(ApiCryptoMiddleware)
|
||||
|
||||
logger = logging.getLogger("sqxp")
|
||||
|
||||
|
||||
def _error_json(status_code: int, code: int, message: str) -> JSONResponse:
|
||||
return JSONResponse(
|
||||
status_code=status_code,
|
||||
content={
|
||||
"code": code,
|
||||
"message": message,
|
||||
"data": None,
|
||||
"timestamp": int(datetime.now().timestamp() * 1000),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@app.exception_handler(SQLAlchemyError)
|
||||
async def sqlalchemy_exception_handler(request: Request, exc: SQLAlchemyError):
|
||||
"""数据库异常:返回 JSON 并保留 CORS 头,避免浏览器只报跨域错误"""
|
||||
logger.exception("Database error on %s %s", request.method, request.url.path)
|
||||
if settings.DEBUG:
|
||||
message = f"数据库不可用:{exc.orig if getattr(exc, 'orig', None) else exc}"
|
||||
else:
|
||||
message = "数据库不可用,请确认 MySQL 已启动且连接配置正确"
|
||||
return _error_json(503, 503, message)
|
||||
|
||||
|
||||
@app.exception_handler(Exception)
|
||||
async def unhandled_exception_handler(request: Request, exc: Exception):
|
||||
"""未捕获异常:统一 JSON 500,确保跨域场景下仍有 Access-Control-Allow-Origin"""
|
||||
logger.exception("Unhandled error on %s %s", request.method, request.url.path)
|
||||
if settings.DEBUG:
|
||||
message = str(exc) or "服务器内部错误"
|
||||
else:
|
||||
message = "服务器内部错误,请稍后重试"
|
||||
return _error_json(500, 500, message)
|
||||
|
||||
|
||||
app.include_router(public_router, prefix=settings.API_V1_PREFIX)
|
||||
app.include_router(menu_router, prefix=settings.API_V1_PREFIX)
|
||||
app.include_router(admin_router, prefix=settings.API_V1_PREFIX)
|
||||
@@ -83,8 +123,6 @@ app.include_router(pilot_delivery_router, prefix=settings.API_V1_PREFIX)
|
||||
app.include_router(pilot_infusion_confirm_router, prefix=settings.API_V1_PREFIX)
|
||||
app.include_router(outbound_release_review_router, prefix=settings.API_V1_PREFIX)
|
||||
|
||||
logger = logging.getLogger("sqxp")
|
||||
|
||||
|
||||
def _mask_secret(value: str) -> str:
|
||||
if not value:
|
||||
|
||||
@@ -1850,8 +1850,11 @@ class BizChannelServiceOrderTxn(Base):
|
||||
finance_submit_remark = Column(String(512), nullable=True, comment="发起确认备注")
|
||||
finance_submit_attachments = Column(Text, nullable=True, comment="发起确认附件")
|
||||
finance_confirm_time = Column(DateTime, nullable=True, comment="财务确认时间")
|
||||
finance_confirm_by = Column(String(64), nullable=True, comment="财务确认人ID")
|
||||
finance_confirm_attachments = Column(Text, nullable=True, comment="财务确认附件")
|
||||
finance_remark = Column(String(512), nullable=True, comment="财务确认备注")
|
||||
void_by = Column(String(64), nullable=True, comment="作废人ID")
|
||||
void_time = Column(DateTime, nullable=True, comment="作废时间")
|
||||
balance_before = Column(Numeric(18, 2), nullable=True, comment="操作前余额")
|
||||
balance_after = Column(Numeric(18, 2), nullable=True, comment="操作后余额")
|
||||
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
|
||||
|
||||
Reference in new issue
Block a user