mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-15 05:00:49 +08:00
record mybouns page bonus consume log
This commit is contained in:
@@ -17,6 +17,13 @@ class BonusLogs extends NexusModel
|
||||
const BUSINESS_TYPE_BUY_ATTENDANCE_CARD = 3;
|
||||
const BUSINESS_TYPE_STICKY_PROMOTION = 4;
|
||||
const BUSINESS_TYPE_POST_REWARD = 5;
|
||||
const BUSINESS_TYPE_EXCHANGE_UPLOAD = 6;
|
||||
const BUSINESS_TYPE_EXCHANGE_INVITE = 7;
|
||||
const BUSINESS_TYPE_CUSTOM_TITLE = 8;
|
||||
const BUSINESS_TYPE_BUY_VIP = 9;
|
||||
const BUSINESS_TYPE_GIFT_TO_SOMEONE = 10;
|
||||
const BUSINESS_TYPE_NO_AD = 11;
|
||||
const BUSINESS_TYPE_GIFT_TO_LOW_SHARE_RATIO = 12;
|
||||
|
||||
public static array $businessTypes = [
|
||||
self::BUSINESS_TYPE_CANCEL_HIT_AND_RUN => ['text' => 'Cancel H&R'],
|
||||
@@ -24,6 +31,13 @@ class BonusLogs extends NexusModel
|
||||
self::BUSINESS_TYPE_BUY_ATTENDANCE_CARD => ['text' => 'Buy attendance card'],
|
||||
self::BUSINESS_TYPE_STICKY_PROMOTION => ['text' => 'Buy torrent sticky promotion'],
|
||||
self::BUSINESS_TYPE_POST_REWARD => ['text' => 'Reward post'],
|
||||
self::BUSINESS_TYPE_EXCHANGE_UPLOAD => ['text' => 'Exchange upload'],
|
||||
self::BUSINESS_TYPE_EXCHANGE_INVITE => ['text' => 'Exchange invite'],
|
||||
self::BUSINESS_TYPE_CUSTOM_TITLE => ['text' => 'Custom title'],
|
||||
self::BUSINESS_TYPE_BUY_VIP => ['text' => 'Buy VIP'],
|
||||
self::BUSINESS_TYPE_GIFT_TO_SOMEONE => ['text' => 'Gift to someone'],
|
||||
self::BUSINESS_TYPE_NO_AD => ['text' => 'No ad'],
|
||||
self::BUSINESS_TYPE_GIFT_TO_LOW_SHARE_RATIO => ['text' => 'Gift to low share ratio'],
|
||||
];
|
||||
|
||||
public static function getBonusForCancelHitAndRun()
|
||||
|
||||
@@ -146,7 +146,7 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
protected $fillable = [
|
||||
'username', 'email', 'passhash', 'secret', 'stylesheet', 'editsecret', 'added', 'modcomment', 'enabled', 'status',
|
||||
'leechwarn', 'leechwarnuntil', 'page', 'class', 'uploaded', 'downloaded', 'clientselect', 'showclienterror', 'last_home',
|
||||
'seedbonus', 'bonuscomment', 'downloadpos'
|
||||
'seedbonus', 'bonuscomment', 'downloadpos', 'vip_added', 'vip_until', 'title',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -95,28 +95,35 @@ class BonusRepository extends BaseRepository
|
||||
|
||||
}
|
||||
|
||||
public function consumeUserBonus($user, $requireBonus, $logBusinessType, $logComment = '')
|
||||
public function consumeUserBonus($user, $requireBonus, $logBusinessType, $logComment = '', array $userUpdates = [])
|
||||
{
|
||||
if (!isset(BonusLogs::$businessTypes[$logBusinessType])) {
|
||||
throw new \InvalidArgumentException("Invalid logBusinessType: $logBusinessType");
|
||||
}
|
||||
if (isset($userUpdates['seedbonus']) || isset($userUpdates['bonuscomment'])) {
|
||||
throw new \InvalidArgumentException("Not support update seedbonus or bonuscomment");
|
||||
}
|
||||
if ($requireBonus <= 0) {
|
||||
return;
|
||||
}
|
||||
$user = $this->getUser($user);
|
||||
if ($user->seedbonus < $requireBonus) {
|
||||
do_log("user: {$user->id}, bonus: {$user->seedbonus} < requireBonus: $requireBonus", 'error');
|
||||
throw new \LogicException("User bonus point not enough.");
|
||||
}
|
||||
NexusDB::transaction(function () use ($user, $requireBonus, $logBusinessType, $logComment) {
|
||||
NexusDB::transaction(function () use ($user, $requireBonus, $logBusinessType, $logComment, $userUpdates) {
|
||||
$logComment = addslashes($logComment);
|
||||
$bonusComment = date('Y-m-d') . " - $logComment";
|
||||
$oldUserBonus = $user->seedbonus;
|
||||
$newUserBonus = bcsub($oldUserBonus, $requireBonus);
|
||||
$log = "user: {$user->id}, requireBonus: $requireBonus, oldUserBonus: $oldUserBonus, newUserBonus: $newUserBonus, logBusinessType: $logBusinessType, logComment: $logComment";
|
||||
do_log($log);
|
||||
$userUpdates['seedbonus'] = $newUserBonus;
|
||||
$userUpdates['bonuscomment'] = NexusDB::raw("if(bonuscomment = '', '$bonusComment', concat_ws('\n', '$bonusComment', bonuscomment))");
|
||||
$affectedRows = NexusDB::table($user->getTable())
|
||||
->where('id', $user->id)
|
||||
->where('seedbonus', $oldUserBonus)
|
||||
->update([
|
||||
'seedbonus' => $newUserBonus,
|
||||
'bonuscomment' => NexusDB::raw("if(bonuscomment = '', '$bonusComment', concat_ws('\n', '$bonusComment', bonuscomment))")
|
||||
]);
|
||||
->update($userUpdates);
|
||||
if ($affectedRows != 1) {
|
||||
do_log("update user seedbonus affected rows != 1, query: " . last_query(), 'error');
|
||||
throw new \RuntimeException("Update user seedbonus fail.");
|
||||
@@ -127,7 +134,7 @@ class BonusRepository extends BaseRepository
|
||||
'old_total_value' => $oldUserBonus,
|
||||
'value' => $requireBonus,
|
||||
'new_total_value' => $newUserBonus,
|
||||
'comment' => $logComment,
|
||||
'comment' => sprintf('[%s] %s', BonusLogs::$businessTypes[$logBusinessType]['text'], $logComment),
|
||||
];
|
||||
BonusLogs::query()->insert($bonusLog);
|
||||
do_log("bonusLog: " . nexus_json_encode($bonusLog));
|
||||
|
||||
Reference in New Issue
Block a user