2021-06-21 02:01:26 +08:00
|
|
|
<?php
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
2023-01-05 18:29:31 +08:00
|
|
|
use App\Exceptions\NexusException;
|
2021-06-21 02:01:26 +08:00
|
|
|
use App\Models\BonusLogs;
|
|
|
|
|
use App\Models\HitAndRun;
|
2023-01-05 18:29:31 +08:00
|
|
|
use App\Models\Invite;
|
2022-01-19 23:54:55 +08:00
|
|
|
use App\Models\Medal;
|
2023-01-29 20:00:58 +08:00
|
|
|
use App\Models\Message;
|
2021-06-21 02:01:26 +08:00
|
|
|
use App\Models\Setting;
|
2023-02-11 16:08:48 +08:00
|
|
|
use App\Models\Torrent;
|
|
|
|
|
use App\Models\TorrentBuyLog;
|
2021-06-21 02:01:26 +08:00
|
|
|
use App\Models\User;
|
2022-03-19 14:55:43 +08:00
|
|
|
use App\Models\UserMedal;
|
2023-01-05 18:29:31 +08:00
|
|
|
use App\Models\UserMeta;
|
2021-06-21 02:01:26 +08:00
|
|
|
use Carbon\Carbon;
|
2021-12-14 16:22:03 +08:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2021-06-21 02:01:26 +08:00
|
|
|
use Nexus\Database\NexusDB;
|
|
|
|
|
|
|
|
|
|
class BonusRepository extends BaseRepository
|
|
|
|
|
{
|
2022-01-19 23:54:55 +08:00
|
|
|
public function consumeToCancelHitAndRun($uid, $hitAndRunId): bool
|
2021-06-21 02:01:26 +08:00
|
|
|
{
|
2021-06-22 14:34:45 +08:00
|
|
|
if (!HitAndRun::getIsEnabled()) {
|
2021-06-21 02:01:26 +08:00
|
|
|
throw new \LogicException("H&R not enabled.");
|
|
|
|
|
}
|
|
|
|
|
$user = User::query()->findOrFail($uid);
|
|
|
|
|
$hitAndRun = HitAndRun::query()->findOrFail($hitAndRunId);
|
|
|
|
|
if ($hitAndRun->uid != $uid) {
|
|
|
|
|
throw new \LogicException("H&R: $hitAndRunId not belongs to user: $uid.");
|
|
|
|
|
}
|
2022-06-08 14:15:59 +08:00
|
|
|
if ($hitAndRun->status == HitAndRun::STATUS_PARDONED) {
|
|
|
|
|
throw new \LogicException("H&R: $hitAndRunId already pardoned.");
|
|
|
|
|
}
|
2021-06-21 02:01:26 +08:00
|
|
|
$requireBonus = BonusLogs::getBonusForCancelHitAndRun();
|
2022-01-19 23:54:55 +08:00
|
|
|
NexusDB::transaction(function () use ($user, $hitAndRun, $requireBonus) {
|
2021-06-21 02:01:26 +08:00
|
|
|
$comment = nexus_trans('hr.bonus_cancel_comment', [
|
|
|
|
|
'bonus' => $requireBonus,
|
|
|
|
|
], $user->locale);
|
|
|
|
|
do_log("comment: $comment");
|
2022-01-19 23:54:55 +08:00
|
|
|
|
|
|
|
|
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_CANCEL_HIT_AND_RUN, "$comment(H&R ID: {$hitAndRun->id})");
|
|
|
|
|
|
2021-06-21 02:01:26 +08:00
|
|
|
$hitAndRun->update([
|
|
|
|
|
'status' => HitAndRun::STATUS_PARDONED,
|
2022-08-02 01:58:08 +08:00
|
|
|
'comment' => NexusDB::raw("if(comment = '', '$comment', concat_ws('\n', '$comment', comment))"),
|
2021-06-21 02:01:26 +08:00
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2022-01-19 23:54:55 +08:00
|
|
|
return true;
|
2021-06-21 02:01:26 +08:00
|
|
|
|
|
|
|
|
}
|
2021-12-14 16:22:03 +08:00
|
|
|
|
|
|
|
|
|
2022-01-19 23:54:55 +08:00
|
|
|
public function consumeToBuyMedal($uid, $medalId): bool
|
|
|
|
|
{
|
|
|
|
|
$user = User::query()->findOrFail($uid);
|
|
|
|
|
$medal = Medal::query()->findOrFail($medalId);
|
|
|
|
|
$exists = $user->valid_medals()->where('medal_id', $medalId)->exists();
|
|
|
|
|
do_log(last_query());
|
|
|
|
|
if ($exists) {
|
|
|
|
|
throw new \LogicException("user: $uid already own this medal: $medalId.");
|
|
|
|
|
}
|
2023-01-29 20:00:58 +08:00
|
|
|
$medal->checkCanBeBuy();
|
2022-01-19 23:54:55 +08:00
|
|
|
$requireBonus = $medal->price;
|
|
|
|
|
NexusDB::transaction(function () use ($user, $medal, $requireBonus) {
|
|
|
|
|
$comment = nexus_trans('bonus.comment_buy_medal', [
|
|
|
|
|
'bonus' => $requireBonus,
|
|
|
|
|
'medal_name' => $medal->name,
|
|
|
|
|
], $user->locale);
|
|
|
|
|
do_log("comment: $comment");
|
|
|
|
|
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_BUY_MEDAL, "$comment(medal ID: {$medal->id})");
|
|
|
|
|
$expireAt = null;
|
|
|
|
|
if ($medal->duration > 0) {
|
2025-05-02 21:21:37 +07:00
|
|
|
$expireAt = Carbon::now()->addDays((int)$medal->duration)->toDateTimeString();
|
2022-01-19 23:54:55 +08:00
|
|
|
}
|
2022-03-19 14:55:43 +08:00
|
|
|
$user->medals()->attach([$medal->id => ['expire_at' => $expireAt, 'status' => UserMedal::STATUS_NOT_WEARING]]);
|
2023-01-29 20:00:58 +08:00
|
|
|
if ($medal->inventory !== null) {
|
|
|
|
|
$affectedRows = NexusDB::table('medals')
|
|
|
|
|
->where('id', $medal->id)
|
|
|
|
|
->where('inventory', $medal->inventory)
|
|
|
|
|
->decrement('inventory')
|
|
|
|
|
;
|
|
|
|
|
if ($affectedRows != 1) {
|
|
|
|
|
throw new \RuntimeException("Decrement medal({$medal->id}) inventory affected rows != 1($affectedRows)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function consumeToGiftMedal($uid, $medalId, $toUid): bool
|
|
|
|
|
{
|
|
|
|
|
$user = User::query()->findOrFail($uid);
|
|
|
|
|
$toUser = User::query()->findOrFail($toUid);
|
|
|
|
|
$medal = Medal::query()->findOrFail($medalId);
|
|
|
|
|
$exists = $toUser->valid_medals()->where('medal_id', $medalId)->exists();
|
|
|
|
|
do_log(last_query());
|
|
|
|
|
if ($exists) {
|
|
|
|
|
throw new \LogicException("user: $toUid already own this medal: $medalId.");
|
|
|
|
|
}
|
|
|
|
|
$medal->checkCanBeBuy();
|
|
|
|
|
$giftFee = $medal->price * ($medal->gift_fee_factor ?? 0);
|
|
|
|
|
$requireBonus = $medal->price + $giftFee;
|
|
|
|
|
NexusDB::transaction(function () use ($user, $toUser, $medal, $requireBonus, $giftFee) {
|
|
|
|
|
$comment = nexus_trans('bonus.comment_gift_medal', [
|
|
|
|
|
'bonus' => $requireBonus,
|
|
|
|
|
'medal_name' => $medal->name,
|
|
|
|
|
'to_username' => $toUser->username,
|
|
|
|
|
], $user->locale);
|
|
|
|
|
do_log("comment: $comment");
|
|
|
|
|
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_GIFT_MEDAL, "$comment(medal ID: {$medal->id})");
|
|
|
|
|
|
|
|
|
|
$expireAt = null;
|
|
|
|
|
if ($medal->duration > 0) {
|
2025-05-02 21:21:37 +07:00
|
|
|
$expireAt = Carbon::now()->addDays((int)$medal->duration)->toDateTimeString();
|
2023-01-29 20:00:58 +08:00
|
|
|
}
|
|
|
|
|
$msg = [
|
|
|
|
|
'sender' => 0,
|
|
|
|
|
'receiver' => $toUser->id,
|
|
|
|
|
'subject' => nexus_trans('message.receive_medal.subject', [], $toUser->locale),
|
|
|
|
|
'msg' => nexus_trans('message.receive_medal.body', [
|
|
|
|
|
'username' => $user->username,
|
|
|
|
|
'cost_bonus' => $requireBonus,
|
|
|
|
|
'medal_name' => $medal->name,
|
|
|
|
|
'price' => $medal->price,
|
|
|
|
|
'gift_fee_total' => $giftFee,
|
|
|
|
|
'gift_fee_factor' => $medal->gift_fee_factor ?? 0,
|
|
|
|
|
'expire_at' => $expireAt ?? nexus_trans('label.permanent'),
|
|
|
|
|
'bonus_addition_factor' => $medal->bonus_addition_factor ?? 0,
|
|
|
|
|
], $toUser->locale),
|
|
|
|
|
'added' => now()
|
|
|
|
|
];
|
|
|
|
|
Message::add($msg);
|
|
|
|
|
$toUser->medals()->attach([$medal->id => ['expire_at' => $expireAt, 'status' => UserMedal::STATUS_NOT_WEARING]]);
|
2023-01-25 20:22:32 +08:00
|
|
|
if ($medal->inventory !== null) {
|
|
|
|
|
$affectedRows = NexusDB::table('medals')
|
|
|
|
|
->where('id', $medal->id)
|
|
|
|
|
->where('inventory', $medal->inventory)
|
|
|
|
|
->decrement('inventory')
|
|
|
|
|
;
|
|
|
|
|
if ($affectedRows != 1) {
|
|
|
|
|
throw new \RuntimeException("Decrement medal({$medal->id}) inventory affected rows != 1($affectedRows)");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-19 23:54:55 +08:00
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-04 17:26:26 +08:00
|
|
|
public function consumeToBuyAttendanceCard($uid): bool
|
|
|
|
|
{
|
|
|
|
|
$user = User::query()->findOrFail($uid);
|
|
|
|
|
$requireBonus = BonusLogs::getBonusForBuyAttendanceCard();
|
|
|
|
|
NexusDB::transaction(function () use ($user, $requireBonus) {
|
|
|
|
|
$comment = nexus_trans('bonus.comment_buy_attendance_card', [
|
|
|
|
|
'bonus' => $requireBonus,
|
|
|
|
|
], $user->locale);
|
|
|
|
|
do_log("comment: $comment");
|
2022-05-29 18:22:56 +08:00
|
|
|
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_BUY_ATTENDANCE_CARD, $comment);
|
2022-04-04 17:26:26 +08:00
|
|
|
User::query()->where('id', $user->id)->increment('attendance_card');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-05 18:29:31 +08:00
|
|
|
|
|
|
|
|
public function consumeToBuyTemporaryInvite($uid, $count = 1): bool
|
|
|
|
|
{
|
|
|
|
|
$requireBonus = BonusLogs::getBonusForBuyTemporaryInvite();
|
2023-01-07 16:27:27 +08:00
|
|
|
if ($requireBonus <= 0) {
|
|
|
|
|
throw new \RuntimeException("Temporary invite require bonus <= 0 !");
|
|
|
|
|
}
|
|
|
|
|
$user = User::query()->findOrFail($uid);
|
2023-01-05 18:29:31 +08:00
|
|
|
$toolRep = new ToolRepository();
|
|
|
|
|
$hashArr = $toolRep->generateUniqueInviteHash([], $count, $count);
|
|
|
|
|
NexusDB::transaction(function () use ($user, $requireBonus, $hashArr) {
|
|
|
|
|
$comment = nexus_trans('bonus.comment_buy_temporary_invite', [
|
|
|
|
|
'bonus' => $requireBonus,
|
|
|
|
|
'count' => count($hashArr)
|
|
|
|
|
], $user->locale);
|
|
|
|
|
do_log("comment: $comment");
|
|
|
|
|
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_BUY_TEMPORARY_INVITE, $comment);
|
|
|
|
|
$invites = [];
|
|
|
|
|
foreach ($hashArr as $hash) {
|
|
|
|
|
$invites[] = [
|
|
|
|
|
'inviter' => $user->id,
|
|
|
|
|
'invitee' => '',
|
|
|
|
|
'hash' => $hash,
|
|
|
|
|
'valid' => 0,
|
|
|
|
|
'expired_at' => Carbon::now()->addDays(Invite::TEMPORARY_INVITE_VALID_DAYS),
|
|
|
|
|
'created_at' => Carbon::now(),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
Invite::query()->insert($invites);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function consumeToBuyRainbowId($uid, $duration = 30): bool
|
|
|
|
|
{
|
|
|
|
|
$user = User::query()->findOrFail($uid);
|
|
|
|
|
$requireBonus = BonusLogs::getBonusForBuyRainbowId();
|
|
|
|
|
NexusDB::transaction(function () use ($user, $requireBonus, $duration) {
|
|
|
|
|
$comment = nexus_trans('bonus.comment_buy_rainbow_id', [
|
|
|
|
|
'bonus' => $requireBonus,
|
|
|
|
|
'duration' => $duration,
|
|
|
|
|
], $user->locale);
|
|
|
|
|
do_log("comment: $comment");
|
|
|
|
|
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_BUY_RAINBOW_ID, $comment);
|
|
|
|
|
$metaData = [
|
|
|
|
|
'meta_key' => UserMeta::META_KEY_PERSONALIZED_USERNAME,
|
|
|
|
|
'duration' => $duration,
|
|
|
|
|
];
|
|
|
|
|
$userRep = new UserRepository();
|
|
|
|
|
$userRep->addMeta($user, $metaData, $metaData, false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function consumeToBuyChangeUsernameCard($uid): bool
|
|
|
|
|
{
|
|
|
|
|
$user = User::query()->findOrFail($uid);
|
|
|
|
|
$requireBonus = BonusLogs::getBonusForBuyChangeUsernameCard();
|
|
|
|
|
if (UserMeta::query()->where('uid', $uid)->where('meta_key', UserMeta::META_KEY_CHANGE_USERNAME)->exists()) {
|
|
|
|
|
throw new NexusException("user already has change username card");
|
|
|
|
|
}
|
|
|
|
|
NexusDB::transaction(function () use ($user, $requireBonus) {
|
|
|
|
|
$comment = nexus_trans('bonus.comment_buy_change_username_card', [
|
|
|
|
|
'bonus' => $requireBonus,
|
|
|
|
|
], $user->locale);
|
|
|
|
|
do_log("comment: $comment");
|
|
|
|
|
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_BUY_CHANGE_USERNAME_CARD, $comment);
|
|
|
|
|
$metaData = [
|
|
|
|
|
'meta_key' => UserMeta::META_KEY_CHANGE_USERNAME,
|
|
|
|
|
];
|
|
|
|
|
$userRep = new UserRepository();
|
|
|
|
|
$userRep->addMeta($user, $metaData, $metaData, false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-11 16:08:48 +08:00
|
|
|
public function consumeToBuyTorrent($uid, $torrentId, $channel = 'Web'): bool
|
|
|
|
|
{
|
|
|
|
|
$torrent = Torrent::query()->findOrFail($torrentId, Torrent::$commentFields);
|
|
|
|
|
$requireBonus = $torrent->price;
|
2023-06-02 02:45:15 +08:00
|
|
|
NexusDB::transaction(function () use ($requireBonus, $torrent, $channel, $uid) {
|
|
|
|
|
$userQuery = User::query();
|
|
|
|
|
if ($requireBonus > 0) {
|
|
|
|
|
$userQuery = $userQuery->lockForUpdate();
|
|
|
|
|
}
|
|
|
|
|
$user = $userQuery->findOrFail($uid);
|
2023-06-30 02:55:53 +08:00
|
|
|
$buyerLocale = $user->locale;
|
2023-02-11 16:08:48 +08:00
|
|
|
$comment = nexus_trans('bonus.comment_buy_torrent', [
|
|
|
|
|
'bonus' => $requireBonus,
|
|
|
|
|
'torrent_id' => $torrent->id,
|
2023-06-30 02:55:53 +08:00
|
|
|
], $buyerLocale);
|
2023-02-11 16:08:48 +08:00
|
|
|
do_log("comment: $comment");
|
|
|
|
|
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_BUY_TORRENT, $comment);
|
|
|
|
|
TorrentBuyLog::query()->create([
|
|
|
|
|
'uid' => $user->id,
|
|
|
|
|
'torrent_id' => $torrent->id,
|
|
|
|
|
'price' => $requireBonus,
|
|
|
|
|
'channel' => $channel,
|
|
|
|
|
]);
|
|
|
|
|
//increment owner bonus
|
|
|
|
|
$taxFactor = Setting::get('torrent.tax_factor');
|
|
|
|
|
if (!is_numeric($taxFactor) || $taxFactor < 0 || $taxFactor > 1) {
|
|
|
|
|
throw new \RuntimeException("Invalid tax_factor: $taxFactor");
|
|
|
|
|
}
|
|
|
|
|
$increaseBonus = $requireBonus * (1 - $taxFactor);
|
|
|
|
|
$owner = $torrent->user;
|
|
|
|
|
if ($owner->id) {
|
|
|
|
|
$nowStr = now()->toDateTimeString();
|
|
|
|
|
$businessType = BonusLogs::BUSINESS_TYPE_TORRENT_BE_DOWNLOADED;
|
|
|
|
|
$owner->increment('seedbonus', $increaseBonus);
|
|
|
|
|
$comment = nexus_trans('bonus.comment_torrent_be_downloaded', [
|
|
|
|
|
'username' => $user->username,
|
|
|
|
|
'uid' => $user->id,
|
|
|
|
|
], $owner->locale);
|
|
|
|
|
$bonusLog = [
|
|
|
|
|
'business_type' => $businessType,
|
|
|
|
|
'uid' => $owner->id,
|
|
|
|
|
'old_total_value' => $owner->seedbonus,
|
|
|
|
|
'value' => $increaseBonus,
|
|
|
|
|
'new_total_value' => bcadd($owner->seedbonus, $increaseBonus),
|
|
|
|
|
'comment' => sprintf('[%s] %s', BonusLogs::$businessTypes[$businessType]['text'], $comment),
|
|
|
|
|
'created_at' => $nowStr,
|
|
|
|
|
'updated_at' => $nowStr,
|
|
|
|
|
];
|
|
|
|
|
BonusLogs::query()->insert($bonusLog);
|
|
|
|
|
}
|
2023-06-30 02:55:53 +08:00
|
|
|
$buyTorrentSuccessMessage = [
|
|
|
|
|
'sender' => 0,
|
|
|
|
|
'receiver' => $user->id,
|
|
|
|
|
'added' => now(),
|
|
|
|
|
'subject' => nexus_trans("message.buy_torrent_success.subject", [], $buyerLocale),
|
|
|
|
|
'msg' => nexus_trans("message.buy_torrent_success.body", [
|
|
|
|
|
'torrent_name' => $torrent->name,
|
|
|
|
|
'bonus' => $requireBonus,
|
|
|
|
|
'url' => sprintf('details.php?id=%s&hit=1', $torrent->id)
|
|
|
|
|
], $buyerLocale),
|
|
|
|
|
];
|
|
|
|
|
Message::add($buyTorrentSuccessMessage);
|
2023-02-11 16:08:48 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-25 03:31:19 +08:00
|
|
|
public function consumeUserBonus($user, $requireBonus, $logBusinessType, $logComment = '', array $userUpdates = [])
|
2022-01-19 23:54:55 +08:00
|
|
|
{
|
2022-07-25 03:31:19 +08:00
|
|
|
if (!isset(BonusLogs::$businessTypes[$logBusinessType])) {
|
|
|
|
|
throw new \InvalidArgumentException("Invalid logBusinessType: $logBusinessType");
|
|
|
|
|
}
|
2025-01-19 22:47:39 +08:00
|
|
|
if (isset($userUpdates['seedbonus']) || isset($userUpdates['bonuscomment']) || isset($userUpdates['modcomment'])) {
|
|
|
|
|
throw new \InvalidArgumentException("Not support update seedbonus or bonuscomment or modcomment");
|
2022-07-25 03:31:19 +08:00
|
|
|
}
|
2022-06-08 14:15:59 +08:00
|
|
|
if ($requireBonus <= 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-07-25 03:31:19 +08:00
|
|
|
$user = $this->getUser($user);
|
2022-01-19 23:54:55 +08:00
|
|
|
if ($user->seedbonus < $requireBonus) {
|
|
|
|
|
do_log("user: {$user->id}, bonus: {$user->seedbonus} < requireBonus: $requireBonus", 'error');
|
2022-08-02 01:58:08 +08:00
|
|
|
throw new \LogicException("User bonus not enough.");
|
2022-01-19 23:54:55 +08:00
|
|
|
}
|
2022-07-25 03:31:19 +08:00
|
|
|
NexusDB::transaction(function () use ($user, $requireBonus, $logBusinessType, $logComment, $userUpdates) {
|
2022-01-19 23:54:55 +08:00
|
|
|
$oldUserBonus = $user->seedbonus;
|
|
|
|
|
$newUserBonus = bcsub($oldUserBonus, $requireBonus);
|
|
|
|
|
$log = "user: {$user->id}, requireBonus: $requireBonus, oldUserBonus: $oldUserBonus, newUserBonus: $newUserBonus, logBusinessType: $logBusinessType, logComment: $logComment";
|
|
|
|
|
do_log($log);
|
2022-07-25 03:31:19 +08:00
|
|
|
$userUpdates['seedbonus'] = $newUserBonus;
|
2022-01-19 23:54:55 +08:00
|
|
|
$affectedRows = NexusDB::table($user->getTable())
|
|
|
|
|
->where('id', $user->id)
|
|
|
|
|
->where('seedbonus', $oldUserBonus)
|
2022-07-25 03:31:19 +08:00
|
|
|
->update($userUpdates);
|
2022-01-19 23:54:55 +08:00
|
|
|
if ($affectedRows != 1) {
|
2024-02-23 02:38:42 +08:00
|
|
|
do_log("update user seedbonus affected rows: ".$affectedRows." != 1, query: " . last_query(), 'error');
|
2022-01-19 23:54:55 +08:00
|
|
|
throw new \RuntimeException("Update user seedbonus fail.");
|
|
|
|
|
}
|
2023-02-08 15:08:07 +08:00
|
|
|
$nowStr = now()->toDateTimeString();
|
2022-01-19 23:54:55 +08:00
|
|
|
$bonusLog = [
|
|
|
|
|
'business_type' => $logBusinessType,
|
|
|
|
|
'uid' => $user->id,
|
|
|
|
|
'old_total_value' => $oldUserBonus,
|
|
|
|
|
'value' => $requireBonus,
|
|
|
|
|
'new_total_value' => $newUserBonus,
|
2022-07-25 03:31:19 +08:00
|
|
|
'comment' => sprintf('[%s] %s', BonusLogs::$businessTypes[$logBusinessType]['text'], $logComment),
|
2023-02-08 15:08:07 +08:00
|
|
|
'created_at' => $nowStr,
|
|
|
|
|
'updated_at' => $nowStr,
|
2022-01-19 23:54:55 +08:00
|
|
|
];
|
|
|
|
|
BonusLogs::query()->insert($bonusLog);
|
|
|
|
|
do_log("bonusLog: " . nexus_json_encode($bonusLog));
|
2023-06-01 01:41:14 +08:00
|
|
|
clear_user_cache($user->id, $user->passkey);
|
2022-01-19 23:54:55 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-06-21 02:01:26 +08:00
|
|
|
}
|