mybonus.php remove medal

This commit is contained in:
xiaomlove
2022-12-19 19:01:22 +08:00
parent 55fed75e97
commit b99ca57321
9 changed files with 65 additions and 26 deletions

View File

@@ -55,6 +55,9 @@ class BonusRepository extends BaseRepository
if ($exists) {
throw new \LogicException("user: $uid already own this medal: $medalId.");
}
if ($medal->get_type != Medal::GET_TYPE_EXCHANGE) {
throw new \LogicException("This medal can not be buy.");
}
$requireBonus = $medal->price;
NexusDB::transaction(function () use ($user, $medal, $requireBonus) {
$comment = nexus_trans('bonus.comment_buy_medal', [

View File

@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-12-13');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-12-19');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -2659,6 +2659,7 @@ else {
[<a href="torrents.php?inclbookmarked=1&amp;allsec=1&amp;incldead=0"><?php echo $lang_functions['text_bookmarks'] ?></a>]
<font class = 'color_bonus'><?php echo $lang_functions['text_bonus'] ?></font>[<a href="mybonus.php"><?php echo $lang_functions['text_use'] ?></a>]: <?php echo number_format($CURUSER['seedbonus'], 1)?>
<?php if($attendance){ printf(' <a href="attendance.php" class="">'.$lang_functions['text_attended'].'</a>', $attendance->points, $CURUSER['attendance_card']); }else{ printf(' <a href="attendance.php" class="faqlink">%s</a>', $lang_functions['text_attendance']);}?>
<a href="medal.php">[<?php echo nexus_trans('medal.label')?>]</a>
<font class = 'color_invite'><?php echo $lang_functions['text_invite'] ?></font>[<a href="invite.php?id=<?php echo $CURUSER['id']?>"><?php echo $lang_functions['text_send'] ?></a>]: <?php echo sprintf('%s(%s)', $CURUSER['invites'], \App\Models\Invite::query()->where('inviter', $CURUSER['id'])->where('invitee', '')->where('expired_at', '>', now())->count())?>
<?php if(get_user_class() >= \App\Models\User::CLASS_ADMINISTRATOR) printf('[<a href="%s" target="_blank">%s</a>]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?>
<br />
@@ -2671,7 +2672,7 @@ else {
<?php if(\App\Models\Claim::getConfigIsEnabled()) { ?><font class='color_bonus'><?php echo $lang_functions['menu_claim']?></font> <?php echo sprintf('[<a href="claim.php?uid=%s">%s</a>]', $CURUSER['id'], (new \App\Repositories\ClaimRepository())->getStats($CURUSER['id']))?><?php }?>
</span>
</td>
<?php if(get_setting('main.spsct') == 'yes' && get_setting('main.enable_global_search') == 'yes'){?>
<?php if(SearchBox::isSpecialEnabled() && get_setting('main.enable_global_search') == 'yes'){?>
<td class="bottom" align="left" style="border: none">
<form action="search.php" method="get" target="<?php echo nexus()->getScript() == 'search' ? '_self' : '_blank'?>">
<div style="display: flex;align-items: center">

View File

@@ -1,7 +1,7 @@
<?php
require "../include/bittorrent.php";
$query = \App\Models\Medal::query();
$query = \App\Models\Medal::query()->where('get_type', \App\Models\Medal::GET_TYPE_EXCHANGE);
$q = htmlspecialchars($_REQUEST['q'] ?? '');
if (!empty($q)) {
$query->where('username', 'name', "%{$q}%");
@@ -18,9 +18,9 @@ $columnPriceLabel = nexus_trans('medal.fields.price');
$columnDurationLabel = nexus_trans('medal.fields.duration');
$columnDescriptionLabel = nexus_trans('medal.fields.description');
$columnActionLabel = nexus_trans('nexus.action');
$header = '<h1 style="text-align: center">'.$title.'</h1>';
$filterForm = <<<FORM
<div>
<h1 style="text-align: center">$title</h1>
<form id="filterForm" action="{$_SERVER['REQUEST_URI']}" method="get">
<input id="q" type="text" name="q" value="{$q}" placeholder="username">
<input type="submit">
@@ -37,6 +37,7 @@ $table = <<<TABLE
<td class="colhead">ID</td>
<td class="colhead">$columnNameLabel</td>
<td class="colhead">$columnImageLargeLabel</td>
<td class="colhead">$columnPriceLabel</td>
<td class="colhead">$columnDurationLabel</td>
<td class="colhead">$columnDescriptionLabel</td>
<td class="colhead">$columnActionLabel</td>
@@ -44,10 +45,18 @@ $table = <<<TABLE
</thead>
TABLE;
$table .= '<tbody>';
$userMedals = \App\Models\UserMedal::query()->where('uid', $CURUSER['id'])->orderBy('id', 'desc')->get()->keyBy('medal_id');
$userMedals = \App\Models\UserMedal::query()->where('uid', $CURUSER['id'])
->orderBy('id', 'desc')
->get()
->keyBy('medal_id')
;
foreach ($rows as $row) {
if ($userMedals->has($CURUSER['id'])) {
$btnText = nexus_trans('medal.buy_already');
if ($userMedals->has($row->id) || $CURUSER['seedbonus'] < $row->price) {
if ($userMedals->has($row->id)) {
$btnText = nexus_trans('medal.buy_already');
} else {
$btnText = nexus_trans('medal.require_more_bonus');
}
$disabled = ' disabled';
$class = '';
} else {
@@ -60,16 +69,17 @@ foreach ($rows as $row) {
$class, $row->id, $btnText, $disabled
);
$table .= sprintf(
'<tr><td>%s</td><td>%s</td><td><img src="%s" style="max-width: 60px;max-height: 60px;" class="preview" /></td><td>%s</td><td>%s</td><td>%s</td>',
$row->id, $row->name, $row->image_large, $row->duration, $row->description, $action
'<tr><td>%s</td><td>%s</td><td><img src="%s" style="max-width: 60px;max-height: 60px;" class="preview" /></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>',
$row->id, $row->name, $row->image_large, number_format($row->price), $row->duration, $row->description, $action
);
}
$table .= '</tbody></table>';
echo $table . $paginationBottom;
echo $header . $table . $paginationBottom;
$confirmMsg = nexus_trans('medal.confirm_to_buy');
$js = <<<JS
jQuery('.buy').on('click', function (e) {
let medalId = jQuery(this).attr('data-id')
layer.confirm("确定要购买吗?", function (index) {
layer.confirm("{$confirmMsg}", function (index) {
let params = {
action: "buyMedal",
params: {medal_id: medalId}

View File

@@ -149,20 +149,21 @@ function bonusarray($option = 0){
$results[] = $bonus;
//Buy medal
$medals = \App\Models\Medal::query()->where('get_type', \App\Models\Medal::GET_TYPE_EXCHANGE)->get();
foreach ($medals as $medal) {
$results[] = [
'points' => $medal->price,
'art' => 'buy_medal',
'menge' => 0,
'name' => $medal->name,
'description' => sprintf(
'<div style="display: flex;align-items: center"><div style="padding: 10px">%s</div><div><img src="%s" style="max-height: 120px"/></div></div><input type="hidden" name="medal_id" value="%s">',
$medal->description, $medal->image_large, $medal->id
),
'medal_id' => $medal->id,
];
}
//migrate to medal.php since v1.8
// $medals = \App\Models\Medal::query()->where('get_type', \App\Models\Medal::GET_TYPE_EXCHANGE)->get();
// foreach ($medals as $medal) {
// $results[] = [
// 'points' => $medal->price,
// 'art' => 'buy_medal',
// 'menge' => 0,
// 'name' => $medal->name,
// 'description' => sprintf(
// '<div style="display: flex;align-items: center"><div style="padding: 10px">%s</div><div><img src="%s" style="max-height: 120px"/></div></div><input type="hidden" name="medal_id" value="%s">',
// $medal->description, $medal->image_large, $medal->id
// ),
// 'medal_id' => $medal->id,
// ];
// }
return $results;

View File

@@ -75,7 +75,7 @@ $moviepicker = $user["picker"] == 'yes';
print("<h1 style='margin:0px'>" . get_username($user['id'], true,false) . $country."</h1>");
if ($userInfo->valid_medals->isNotEmpty()) {
print build_medal_image($userInfo->{$medalType}, 200, $CURUSER['id'] == $user['id']);
print build_medal_image($userInfo->{$medalType}, 120, $CURUSER['id'] == $user['id']);
$warnMedalJs = <<<JS
jQuery('input[type="checkbox"][name="medal_wearing_status"]').on("change", function (e) {
let input = jQuery(this);

View File

@@ -12,4 +12,15 @@ return [
\App\Models\Medal::GET_TYPE_EXCHANGE => 'Exchange',
\App\Models\Medal::GET_TYPE_GRANT => 'Grant',
],
'fields' => [
'get_type' => 'Get type',
'description' => 'Description',
'image_large' => 'Image',
'price' => 'Price',
'duration' => 'Valid after buy (days)',
],
'buy_already' => 'Already buy',
'buy_btn' => 'Buy',
'confirm_to_buy' => 'Sure you want to buy?',
'require_more_bonus' => 'Require more bonus',
];

View File

@@ -21,4 +21,6 @@ return [
],
'buy_already' => '已经购买',
'buy_btn' => '购买',
'confirm_to_buy' => '确定要购买吗?',
'require_more_bonus' => '需要更多魔力值',
];

View File

@@ -12,4 +12,15 @@ return [
\App\Models\Medal::GET_TYPE_EXCHANGE => '兌換',
\App\Models\Medal::GET_TYPE_GRANT => '授予',
],
'fields' => [
'get_type' => '獲取方式',
'description' => '描述',
'image_large' => '圖片',
'price' => '價格',
'duration' => '購買後有效期(天)',
],
'buy_already' => '已經購買',
'buy_btn' => '購買',
'confirm_to_buy' => '確定要購買嗎?',
'require_more_bonus' => '需要更多魔力值',
];