getRow(); // 只有正常状态的收益记录才允许重新计算 return $row->status === UrsProfit::STATUS_NORMAL; } /** * 处理请求 * * @param Request $request * @return mixed */ public function handle(Request $request) { $id = $this->getKey(); $profit = UrsProfit::find($id); if (!$profit) { return $this->response()->error('收益记录不存在'); } if ($profit->status !== UrsProfit::STATUS_NORMAL) { return $this->response()->error('只能重新计算正常状态的收益记录'); } try { // 保存原始数据 $originalAmount = $profit->profit_amount; $originalRate = $profit->profit_rate; // 重新计算收益 $result = UrsProfitService::recalculateProfit($profit); if ($result) { // 重新获取更新后的记录 $profit->refresh(); $message = "收益重新计算成功!"; if ($originalAmount != $profit->profit_amount) { $message .= " 分成金额从 {$originalAmount} 调整为 {$profit->profit_amount}"; if ($originalRate != $profit->profit_rate) { $message .= ",分成比例从 " . ($originalRate * 100) . "% 调整为 " . ($profit->profit_rate * 100) . "%"; } } else { $message .= " 金额无变化"; } return $this->response() ->success($message) ->refresh(); } else { return $this->response()->error('收益重新计算失败'); } } catch (\Exception $e) { return $this->response()->error('重新计算失败:' . $e->getMessage()); } } /** * 确认对话框 * * @return string */ public function confirm() { return '确定要重新计算此收益记录吗?这将根据当前的达人等级和分成配置重新计算分成金额。'; } }