订单修改金额
This commit is contained in:
@@ -246,6 +246,21 @@ 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('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 为「已发货」订单新增一条关联支付单,并重置支付单审核状态为待审核
|
||||
*/
|
||||
|
||||
@@ -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'] ?? '';
|
||||
|
||||
@@ -36,6 +36,7 @@ class PrescriptionOrderValidate extends BaseValidate
|
||||
'patient_name' => 'require|max:50',
|
||||
'phone' => 'require|max:20',
|
||||
'phone_tail' => 'max:20|regex:/^\\d*$/',
|
||||
'amount_update' => 'require|float|gt:0',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
@@ -50,6 +51,8 @@ class PrescriptionOrderValidate extends BaseValidate
|
||||
'patient_name.require' => '请输入患者姓名',
|
||||
'phone.require' => '请输入手机号',
|
||||
'phone_tail.regex' => '手机后四位仅支持数字',
|
||||
'amount_update.require' => '请输入订单金额',
|
||||
'amount_update.gt' => '订单金额必须大于0',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
@@ -77,5 +80,6 @@ class PrescriptionOrderValidate extends BaseValidate
|
||||
'submitGancaoRecipel' => ['id'],
|
||||
'previewGancaoRecipel' => ['id'],
|
||||
'patchPrescriptionPatient' => ['id', 'patient_name', 'phone'],
|
||||
'updateAmount' => ['id', 'amount_update'],
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user