state === TechnicianStatus::BLACKLIST->value, 422, '技师已经被拉黑'); // 更新技师状态为拉黑 $coach->state = TechnicianStatus::BLACKLIST->value; $coach->block_reason = $data['reason']; $coach->block_time = now(); $coach->block_operator_id = Auth::user()->id; $coach->save(); DB::commit(); return [ 'code' => 200, 'message' => '拉黑成功', 'data' => null, ]; } catch (\Exception $e) { DB::rollBack(); Log::error('拉黑技师失败', [ 'coach_id' => $data['coach_id'], 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString(), ]); throw $e; } } /** * 冻结技师余额 * * @param array $data 包含 coach_id, amount 和 reason */ public function freezeCoachBalance(array $data): array { try { DB::beginTransaction(); // 获取技师及其钱包信息 $coach = CoachUser::findOrFail($data['coach_id']); $wallet = $coach->wallet()->lockForUpdate()->firstOrFail(); // 验证可用余额是否足够 abort_if($wallet->available_amount < $data['amount'], 422, '技师可用余额不足'); // 更新钱包余额 $wallet->available_amount -= $data['amount']; $wallet->frozen_amount += $data['amount']; $wallet->save(); // 记录冻结流水 WalletTransRecord::create([ 'user_id' => $data['coach_id'], 'type' => TransactionType::FREEZE->value, 'amount' => $data['amount'], 'before_amount' => $wallet->available_amount + $data['amount'], 'after_amount' => $wallet->available_amount, 'operator_id' => Auth::user()->id, 'operator_type' => 'admin', 'remark' => $data['reason'], 'state' => TransactionStatus::SUCCESS->value, ]); DB::commit(); return [ 'code' => 200, 'message' => '冻结成功', 'data' => null, ]; } catch (\Exception $e) { DB::rollBack(); Log::error('冻结技师余额失败', [ 'coach_id' => $data['coach_id'], 'amount' => $data['amount'], 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString(), ]); throw $e; } } }