can('dcat.admin.orders.reduce'); } /** * Handle the form request. * * @param array $input * * @return mixed */ public function handle(array $input) { $orderId = $this->payload['id'] ?? 0; $order = Order::findOrFail($orderId); $reduceAmount = $input['reduce_amount']??0; //获取调整价格; if ($reduceAmount > $order->total_amount) { throw new BizException('订单价格无法上浮'); } if ($reduceAmount == $order->total_amount) { throw new BizException('调整价格和订单原价格一致,无需调整'); } $orderService = new OrderService(); $reduced = $order->total_amount-$reduceAmount; //判断是否在当前操作人调价权限范围内 $adminUser = Admin::user(); if (! $adminUser->isAdministrator() && ! $adminUser->inReduceRange($reduced)) { throw new BizException('当前调整价格超出权限范围,请重新确认价格。'); } try { DB::beginTransaction(); $orderService->adminReduceOrder($order, $reduceAmount); DB::commit(); } catch (Throwable $th) { DB::rollBack(); report($th); throw new BizException('操作失败:'.$th->getMessage()); } return $this->response() ->success(__('admin.update_succeeded')) ->refresh(); } /** * Build a form here. */ public function form() { $orderId = $this->payload['id'] ?? 0; $order = Order::findOrFail($orderId); $this->currency('reduce_amount', '调整价格')->symbol('¥')->default(0)->customFormat(function ($V) use ($order) { return bcdiv($order->total_amount, 100, 2); })->saving(function ($reduceAmount) { return bcmul($reduceAmount, 100); }); $this->confirm('是否确认调价?', '该操作不可逆,确认后将更改订单支付价格。'); $this->disableResetButton(); } }