订单修改金额

This commit is contained in:
2026-05-08 16:07:39 +08:00
parent f20a45a1ad
commit 14735af0b3
7 changed files with 252 additions and 3 deletions
@@ -2432,6 +2432,52 @@ class PrescriptionOrderLogic
];
}
/**
* 修改订单金额
*/
public static function updateAmount(array $params, int $adminId, array $adminInfo): bool
{
$id = (int) $params['id'];
$newAmount = round((float) $params['amount_update'], 2);
// 查询订单
$order = PrescriptionOrder::find($id);
if (!$order) {
self::setError('订单不存在');
return false;
}
// 数据权限检查
if (!self::checkDataScope($order->toArray(), $adminId, $adminInfo)) {
self::setError('无权限操作此订单');
return false;
}
// 状态检查:已完成(3)和已取消(4)不允许修改
if (in_array((int) $order->fulfillment_status, [3, 4], true)) {
self::setError('已完成或已取消的订单不允许修改金额');
return false;
}
$oldAmount = round((float) $order->amount, 2);
// 金额未变化
if (abs($newAmount - $oldAmount) < 0.01) {
self::setError('金额未发生变化');
return false;
}
// 更新金额
$order->amount = $newAmount;
$order->save();
// 记录日志
$summary = sprintf('将订单金额从 ¥%.2f 修改为 ¥%.2f', $oldAmount, $newAmount);
self::writeLog($id, $adminId, $adminInfo, 'update_amount', $summary);
return true;
}
private static function writeLog(int $orderId, int $adminId, array $adminInfo, string $action, string $summary): void
{
$adminName = $adminInfo['name'] ?? '';