From cf1b5ad13541d520871f50d2eb624e6cd5b7b2d5 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 19 Dec 2022 04:15:15 +0800 Subject: [PATCH] finish medal.php --- public/ajax.php | 7 +++++++ public/medal.php | 35 ++++++++++++++++++++++++++++------ resources/lang/zh_CN/medal.php | 2 +- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/public/ajax.php b/public/ajax.php index 8fe245a5..c9d9a0cc 100644 --- a/public/ajax.php +++ b/public/ajax.php @@ -131,3 +131,10 @@ function clearShoutBox($params) \Nexus\Database\NexusDB::table('shoutbox')->delete(); return true; } + +function buyMedal($params) +{ + global $CURUSER; + $rep = new \App\Repositories\BonusRepository(); + return $rep->consumeToBuyMedal($CURUSER['id'], $params['medal_id']); +} diff --git a/public/medal.php b/public/medal.php index c81d12ed..bf87cabe 100644 --- a/public/medal.php +++ b/public/medal.php @@ -7,7 +7,7 @@ if (!empty($q)) { $query->where('username', 'name', "%{$q}%"); } $total = (clone $query)->count(); -$perPage = 50; +$perPage = 20; list($paginationTop, $paginationBottom, $limit, $offset) = pager($perPage, $total, "?"); $rows = (clone $query)->offset($offset)->take($perPage)->orderBy('id', 'desc')->get(); $q = htmlspecialchars($q); @@ -44,25 +44,48 @@ $table = << TABLE; $table .= ''; -$userMedals = \App\Models\UserMedal::query()->where('uid', $CURUSER['id'])->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'); $disabled = ' disabled'; + $class = ''; } else { $btnText = nexus_trans('medal.buy_btn'); $disabled = ''; + $class = 'buy'; } $action = sprintf( - '', - $btnText, $disabled + '', + $class, $row->id, $btnText, $disabled ); $table .= sprintf( - '', + '', $row->id, $row->name, $row->image_large, $row->duration, $row->description, $action ); } $table .= '
%s%s%s%s%s
%s%s%s%s%s
'; -echo $filterForm . $table . $paginationBottom; +echo $table . $paginationBottom; +$js = << '购买后有效期(天)', ], 'buy_already' => '已经购买', - 'but_btn' => '购买', + 'buy_btn' => '购买', ];