From b99ca57321e0460f14c0c350ea318085b63d7721 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 19 Dec 2022 19:01:22 +0800 Subject: [PATCH] mybonus.php remove medal --- app/Repositories/BonusRepository.php | 3 +++ include/constants.php | 2 +- include/functions.php | 3 ++- public/medal.php | 28 ++++++++++++++++++--------- public/mybonus.php | 29 ++++++++++++++-------------- public/userdetails.php | 2 +- resources/lang/en/medal.php | 11 +++++++++++ resources/lang/zh_CN/medal.php | 2 ++ resources/lang/zh_TW/medal.php | 11 +++++++++++ 9 files changed, 65 insertions(+), 26 deletions(-) diff --git a/app/Repositories/BonusRepository.php b/app/Repositories/BonusRepository.php index 052bf4cd..a00ca11c 100644 --- a/app/Repositories/BonusRepository.php +++ b/app/Repositories/BonusRepository.php @@ -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', [ diff --git a/include/constants.php b/include/constants.php index 261acffe..36b4c666 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ ] []: '.$lang_functions['text_attended'].'', $attendance->points, $CURUSER['attendance_card']); }else{ printf(' %s', $lang_functions['text_attendance']);}?> + [] []: where('inviter', $CURUSER['id'])->where('invitee', '')->where('expired_at', '>', now())->count())?> = \App\Models\User::CLASS_ADMINISTRATOR) printf('[%s]', nexus_env('FILAMENT_PATH', 'nexusphp'), $lang_functions['text_management_system'])?>
@@ -2671,7 +2672,7 @@ else { %s]', $CURUSER['id'], (new \App\Repositories\ClaimRepository())->getStats($CURUSER['id']))?> - +
diff --git a/public/medal.php b/public/medal.php index bf87cabe..5695fb55 100644 --- a/public/medal.php +++ b/public/medal.php @@ -1,7 +1,7 @@ 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 = '

'.$title.'

'; $filterForm = << -

$title

@@ -37,6 +37,7 @@ $table = <<ID + @@ -44,10 +45,18 @@ $table = <<
$columnNameLabel $columnImageLargeLabel$columnPriceLabel $columnDurationLabel $columnDescriptionLabel $columnActionLabel
TABLE; $table .= ''; -$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( - '', - $row->id, $row->name, $row->image_large, $row->duration, $row->description, $action + '', + $row->id, $row->name, $row->image_large, number_format($row->price), $row->duration, $row->description, $action ); } $table .= '
%s%s%s%s%s
%s%s%s%s%s%s
'; -echo $table . $paginationBottom; +echo $header . $table . $paginationBottom; +$confirmMsg = nexus_trans('medal.confirm_to_buy'); $js = <<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( - '
%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( +// '
%s
', +// $medal->description, $medal->image_large, $medal->id +// ), +// 'medal_id' => $medal->id, +// ]; +// } return $results; diff --git a/public/userdetails.php b/public/userdetails.php index f75f5f1b..3c5fc791 100644 --- a/public/userdetails.php +++ b/public/userdetails.php @@ -75,7 +75,7 @@ $moviepicker = $user["picker"] == 'yes'; print("

" . get_username($user['id'], true,false) . $country."

"); 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 = << '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', ]; diff --git a/resources/lang/zh_CN/medal.php b/resources/lang/zh_CN/medal.php index 2596be7b..e6368c6d 100644 --- a/resources/lang/zh_CN/medal.php +++ b/resources/lang/zh_CN/medal.php @@ -21,4 +21,6 @@ return [ ], 'buy_already' => '已经购买', 'buy_btn' => '购买', + 'confirm_to_buy' => '确定要购买吗?', + 'require_more_bonus' => '需要更多魔力值', ]; diff --git a/resources/lang/zh_TW/medal.php b/resources/lang/zh_TW/medal.php index 3ec07fd5..6941b279 100644 --- a/resources/lang/zh_TW/medal.php +++ b/resources/lang/zh_TW/medal.php @@ -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' => '需要更多魔力值', ];