buy torrent add lock for update + improve disabled func check

This commit is contained in:
xiaomlove
2023-06-02 02:45:15 +08:00
parent ff325ad687
commit 65eaf09a6d
4 changed files with 11 additions and 18 deletions
+6 -2
View File
@@ -254,10 +254,14 @@ class BonusRepository extends BaseRepository
public function consumeToBuyTorrent($uid, $torrentId, $channel = 'Web'): bool
{
$user = User::query()->findOrFail($uid);
$torrent = Torrent::query()->findOrFail($torrentId, Torrent::$commentFields);
$requireBonus = $torrent->price;
NexusDB::transaction(function () use ($user, $requireBonus, $torrent, $channel) {
NexusDB::transaction(function () use ($requireBonus, $torrent, $channel, $uid) {
$userQuery = User::query();
if ($requireBonus > 0) {
$userQuery = $userQuery->lockForUpdate();
}
$user = $userQuery->findOrFail($uid);
$comment = nexus_trans('bonus.comment_buy_torrent', [
'bonus' => $requireBonus,
'torrent_id' => $torrent->id,