Merge branch 'long-0507'
This commit is contained in:
@@ -105,6 +105,17 @@ class PrescriptionOrderController extends BaseAdminController
|
||||
return $this->success('保存成功', $result);
|
||||
}
|
||||
|
||||
public function updateAmount()
|
||||
{
|
||||
$params = (new PrescriptionOrderValidate())->post()->goCheck('updateAmount');
|
||||
$result = PrescriptionOrderLogic::updateAmount($params, $this->adminId, $this->adminInfo);
|
||||
if ($result === false) {
|
||||
return $this->fail(PrescriptionOrderLogic::getError());
|
||||
}
|
||||
|
||||
return $this->success('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改关联处方的患者姓名与手机号(订单详情场景)
|
||||
*/
|
||||
|
||||
@@ -2642,6 +2642,60 @@ class PrescriptionOrderLogic
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改订单金额
|
||||
*/
|
||||
public static function updateAmount(array $params, int $adminId, array $adminInfo): bool
|
||||
{
|
||||
self::$error = '';
|
||||
$id = (int) $params['id'];
|
||||
$newAmount = round((float) $params['amount'], 2);
|
||||
|
||||
// 查询订单
|
||||
$order = PrescriptionOrder::where('id', $id)->whereNull('delete_time')->find();
|
||||
if (!$order) {
|
||||
self::setError('订单不存在');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 数据权限检查
|
||||
if (!self::canAccessOrder($order, $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);
|
||||
$oldAmountCents = (int) round($oldAmount * 100);
|
||||
$newAmountCents = (int) round($newAmount * 100);
|
||||
|
||||
// 金额未变化
|
||||
if ($newAmountCents === $oldAmountCents) {
|
||||
self::setError('金额未发生变化');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 更新金额
|
||||
$order->amount = $newAmount;
|
||||
try {
|
||||
$order->save();
|
||||
} catch (\Throwable $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
$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'] ?? '';
|
||||
|
||||
@@ -77,5 +77,13 @@ class PrescriptionOrderValidate extends BaseValidate
|
||||
'submitGancaoRecipel' => ['id'],
|
||||
'previewGancaoRecipel' => ['id'],
|
||||
'patchPrescriptionPatient' => ['id', 'patient_name', 'phone'],
|
||||
'updateAmount' => ['id', 'amount'],
|
||||
];
|
||||
|
||||
public function updateAmount(): PrescriptionOrderValidate
|
||||
{
|
||||
return $this->only(['id', 'amount'])
|
||||
->append('id', 'require|integer|gt:0')
|
||||
->append('amount', 'require|float|gt:0');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user