improve user bonuscomment

This commit is contained in:
xiaomlove
2022-05-29 18:22:56 +08:00
parent 36a1f83d7d
commit e7eaaeb8a7
7 changed files with 13 additions and 8 deletions
+6 -3
View File
@@ -26,7 +26,6 @@ class BonusRepository extends BaseRepository
$requireBonus = BonusLogs::getBonusForCancelHitAndRun();
NexusDB::transaction(function () use ($user, $hitAndRun, $requireBonus) {
$comment = nexus_trans('hr.bonus_cancel_comment', [
'now' => Carbon::now()->toDateTimeString(),
'bonus' => $requireBonus,
], $user->locale);
$comment = addslashes($comment);
@@ -85,7 +84,7 @@ class BonusRepository extends BaseRepository
], $user->locale);
$comment = addslashes($comment);
do_log("comment: $comment");
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_BUY_ATTENDANCE_CARD, "$comment");
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_BUY_ATTENDANCE_CARD, $comment);
User::query()->where('id', $user->id)->increment('attendance_card');
});
@@ -100,6 +99,7 @@ class BonusRepository extends BaseRepository
throw new \LogicException("User bonus point not enough.");
}
NexusDB::transaction(function () use ($user, $requireBonus, $logBusinessType, $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";
@@ -107,7 +107,10 @@ class BonusRepository extends BaseRepository
$affectedRows = NexusDB::table($user->getTable())
->where('id', $user->id)
->where('seedbonus', $oldUserBonus)
->update(['seedbonus' => $newUserBonus]);
->update([
'seedbonus' => $newUserBonus,
'bonuscomment' => NexusDB::raw("if(bonuscomment = '', '$bonusComment', concat_ws('\n', '$bonusComment', bonuscomment))")
]);
if ($affectedRows != 1) {
do_log("update user seedbonus affected rows != 1, query: " . last_query(), 'error');
throw new \RuntimeException("Update user seedbonus fail.");
+2 -2
View File
@@ -508,7 +508,7 @@ if ($action == "exchange") {
}
$vip_until = date("Y-m-d H:i:s",(strtotime(date("Y-m-d H:i:s")) + 28*86400));
$bonuscomment = date("Y-m-d") . " - " .$points. " Points for 1 month VIP Status.\n " .htmlspecialchars($bonuscomment);
sql_query("UPDATE users SET class = '".UC_VIP."', vip_added = 'yes', vip_until = ".sqlesc($vip_until).", seedbonus = seedbonus - $points WHERE id = ".sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
sql_query("UPDATE users SET class = '".UC_VIP."', vip_added = 'yes', vip_until = ".sqlesc($vip_until).", seedbonus = seedbonus - $points, bonuscomment=".sqlesc($bonuscomment)." WHERE id = ".sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
nexus_redirect("" . get_protocol_prefix() . "$BASEURL/mybonus.php?do=vip");
}
//=== trade for invites
@@ -518,7 +518,7 @@ if ($action == "exchange") {
$invites = $CURUSER['invites'];
$inv = $invites+$bonusarray['menge'];
$bonuscomment = date("Y-m-d") . " - " .$points. " Points for invites.\n " .htmlspecialchars($bonuscomment);
sql_query("UPDATE users SET invites = ".sqlesc($inv).", seedbonus = seedbonus - $points WHERE id = ".sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
sql_query("UPDATE users SET invites = ".sqlesc($inv).", seedbonus = seedbonus - $points, bonuscomment=".sqlesc($bonuscomment)." WHERE id = ".sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
nexus_redirect("" . get_protocol_prefix() . "$BASEURL/mybonus.php?do=invite");
}
//=== trade for special title
+1
View File
@@ -2,4 +2,5 @@
return [
'comment_buy_medal' => 'Spend :bonus bonus buy :medal_name',
'comment_buy_attendance_card' => 'Spend :bonus bonus buy one attend card',
];
+1 -1
View File
@@ -23,5 +23,5 @@ return [
'unreached_disable_comment' => 'H&R quantity reached the upper limit and account was disabled by the system',
'unreached_disable_message_content' => 'Your account has been disabled because the cumulative H&R count has been reached the system limit: :ban_user_when_counts_reach',
'bonus_cancel_comment' => ':now, spend :bonus canceled',
'bonus_cancel_comment' => 'spend :bonus canceled',
];
+1 -1
View File
@@ -23,5 +23,5 @@ return [
'unreached_disable_comment' => 'H&R 数量达上限被系统禁用。',
'unreached_disable_message_content' => '由于累计 H&R 数量已达系统上限::ban_user_when_counts_reach,你的账号已被禁用。',
'bonus_cancel_comment' => ':now 花费 :bonus 魔力进行了消除',
'bonus_cancel_comment' => '花费 :bonus 魔力进行了消除',
];
+1
View File
@@ -2,4 +2,5 @@
return [
'comment_buy_medal' => '花費 :bonus 魔力購買了 :medal_name',
'comment_buy_attendance_card' => '花費 :bonus 魔力購買了 1 張補簽卡',
];
+1 -1
View File
@@ -23,5 +23,5 @@ return [
'unreached_disable_comment' => 'H&R 數量達上限被系統禁用。',
'unreached_disable_message_content' => '由於累計 H&R 數量已達系統上限::ban_user_when_counts_reach,你的賬號已被禁用。',
'bonus_cancel_comment' => ':now 花費 :bonus 魔力進行了消除',
'bonus_cancel_comment' => '花費 :bonus 魔力進行了消除',
];