update
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('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改关联处方的患者姓名与手机号(订单详情场景)
|
||||
*/
|
||||
@@ -246,21 +257,6 @@ 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('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 为「已发货」订单新增一条关联支付单,并重置支付单审核状态为待审核
|
||||
*/
|
||||
|
||||
@@ -2437,18 +2437,19 @@ class PrescriptionOrderLogic
|
||||
*/
|
||||
public static function updateAmount(array $params, int $adminId, array $adminInfo): bool
|
||||
{
|
||||
self::$error = '';
|
||||
$id = (int) $params['id'];
|
||||
$newAmount = round((float) $params['amount_update'], 2);
|
||||
$newAmount = round((float) $params['amount'], 2);
|
||||
|
||||
// 查询订单
|
||||
$order = PrescriptionOrder::find($id);
|
||||
$order = PrescriptionOrder::where('id', $id)->whereNull('delete_time')->find();
|
||||
if (!$order) {
|
||||
self::setError('订单不存在');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 数据权限检查
|
||||
if (!self::checkDataScope($order->toArray(), $adminId, $adminInfo)) {
|
||||
if (!self::canAccessOrder($order, $adminId, $adminInfo)) {
|
||||
self::setError('无权限操作此订单');
|
||||
return false;
|
||||
}
|
||||
@@ -2460,16 +2461,23 @@ class PrescriptionOrderLogic
|
||||
}
|
||||
|
||||
$oldAmount = round((float) $order->amount, 2);
|
||||
$oldAmountCents = (int) round($oldAmount * 100);
|
||||
$newAmountCents = (int) round($newAmount * 100);
|
||||
|
||||
// 金额未变化
|
||||
if (abs($newAmount - $oldAmount) < 0.01) {
|
||||
if ($newAmountCents === $oldAmountCents) {
|
||||
self::setError('金额未发生变化');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 更新金额
|
||||
$order->amount = $newAmount;
|
||||
$order->save();
|
||||
try {
|
||||
$order->save();
|
||||
} catch (\Throwable $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
$summary = sprintf('将订单金额从 ¥%.2f 修改为 ¥%.2f', $oldAmount, $newAmount);
|
||||
|
||||
@@ -36,7 +36,6 @@ 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 = [
|
||||
@@ -51,8 +50,6 @@ class PrescriptionOrderValidate extends BaseValidate
|
||||
'patient_name.require' => '请输入患者姓名',
|
||||
'phone.require' => '请输入手机号',
|
||||
'phone_tail.regex' => '手机后四位仅支持数字',
|
||||
'amount_update.require' => '请输入订单金额',
|
||||
'amount_update.gt' => '订单金额必须大于0',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
@@ -80,6 +77,13 @@ class PrescriptionOrderValidate extends BaseValidate
|
||||
'submitGancaoRecipel' => ['id'],
|
||||
'previewGancaoRecipel' => ['id'],
|
||||
'patchPrescriptionPatient' => ['id', 'patient_name', 'phone'],
|
||||
'updateAmount' => ['id', 'amount_update'],
|
||||
'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