100) { throw new \InvalidArgumentException('收款地址备注不能超过 100 个字符'); } $wallets[$address] = $label; } if (count($wallets) > 100) { throw new \InvalidArgumentException('收款地址池最多配置 100 个地址'); } return $wallets; } public static function sync(array $wallets) { $now = time(); $connection = (new UsdtWallet())->getConnection(); $connection->transaction(function () use ($wallets, $now) { if ($wallets === []) { UsdtWallet::query()->update(['enabled' => 0, 'updated_at' => $now]); return; } UsdtWallet::whereNotIn('address', array_keys($wallets))->update([ 'enabled' => 0, 'updated_at' => $now, ]); $sort = 0; foreach ($wallets as $address => $label) { $wallet = UsdtWallet::where('address', $address)->lockForUpdate()->first(); if ($wallet === null) { $wallet = new UsdtWallet(); $wallet->address = $address; $wallet->allocation_cursor = 0; $wallet->last_assigned_at = 0; $wallet->last_scanned_at = 0; $wallet->last_error = ''; $wallet->created_at = $now; } $wallet->label = $label; $wallet->enabled = 1; $wallet->sort = $sort++; $wallet->updated_at = $now; $wallet->save(); } }, 3); } public static function text() { return UsdtWallet::where('enabled', 1) ->orderBy('sort', 'asc') ->orderBy('id', 'asc') ->get() ->map(function (UsdtWallet $wallet) { return (string) $wallet->address . ((string) $wallet->label !== '' ? ' | ' . (string) $wallet->label : ''); }) ->implode("\n"); } }