2022-12-18 02:19:33 +08:00
|
|
|
<?php
|
|
|
|
|
require "../include/bittorrent.php";
|
|
|
|
|
|
|
|
|
|
$query = \App\Models\Medal::query();
|
|
|
|
|
$q = htmlspecialchars($_REQUEST['q'] ?? '');
|
|
|
|
|
if (!empty($q)) {
|
|
|
|
|
$query->where('username', 'name', "%{$q}%");
|
|
|
|
|
}
|
|
|
|
|
$total = (clone $query)->count();
|
2022-12-19 04:15:15 +08:00
|
|
|
$perPage = 20;
|
2022-12-18 02:19:33 +08:00
|
|
|
list($paginationTop, $paginationBottom, $limit, $offset) = pager($perPage, $total, "?");
|
|
|
|
|
$rows = (clone $query)->offset($offset)->take($perPage)->orderBy('id', 'desc')->get();
|
|
|
|
|
$q = htmlspecialchars($q);
|
|
|
|
|
$title = nexus_trans('medal.label');
|
|
|
|
|
$columnNameLabel = nexus_trans('label.name');
|
|
|
|
|
$columnImageLargeLabel = nexus_trans('medal.fields.image_large');
|
|
|
|
|
$columnPriceLabel = nexus_trans('medal.fields.price');
|
|
|
|
|
$columnDurationLabel = nexus_trans('medal.fields.duration');
|
|
|
|
|
$columnDescriptionLabel = nexus_trans('medal.fields.description');
|
|
|
|
|
$columnActionLabel = nexus_trans('nexus.action');
|
|
|
|
|
$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">
|
|
|
|
|
<input type="reset" onclick="document.getElementById('q').value='';document.getElementById('filterForm').submit();">
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
FORM;
|
|
|
|
|
stdhead($title);
|
|
|
|
|
begin_main_frame();
|
|
|
|
|
$table = <<<TABLE
|
|
|
|
|
<table border="1" cellspacing="0" cellpadding="5" width="100%">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="colhead">ID</td>
|
|
|
|
|
<td class="colhead">$columnNameLabel</td>
|
|
|
|
|
<td class="colhead">$columnImageLargeLabel</td>
|
|
|
|
|
<td class="colhead">$columnDurationLabel</td>
|
|
|
|
|
<td class="colhead">$columnDescriptionLabel</td>
|
|
|
|
|
<td class="colhead">$columnActionLabel</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
TABLE;
|
|
|
|
|
$table .= '<tbody>';
|
2022-12-19 04:15:15 +08:00
|
|
|
$userMedals = \App\Models\UserMedal::query()->where('uid', $CURUSER['id'])->orderBy('id', 'desc')->get()->keyBy('medal_id');
|
2022-12-18 02:19:33 +08:00
|
|
|
foreach ($rows as $row) {
|
|
|
|
|
if ($userMedals->has($CURUSER['id'])) {
|
|
|
|
|
$btnText = nexus_trans('medal.buy_already');
|
|
|
|
|
$disabled = ' disabled';
|
2022-12-19 04:15:15 +08:00
|
|
|
$class = '';
|
2022-12-18 02:19:33 +08:00
|
|
|
} else {
|
|
|
|
|
$btnText = nexus_trans('medal.buy_btn');
|
|
|
|
|
$disabled = '';
|
2022-12-19 04:15:15 +08:00
|
|
|
$class = 'buy';
|
2022-12-18 02:19:33 +08:00
|
|
|
}
|
|
|
|
|
$action = sprintf(
|
2022-12-19 04:15:15 +08:00
|
|
|
'<input type="button" class="%s" data-id="%s" value="%s"%s>',
|
|
|
|
|
$class, $row->id, $btnText, $disabled
|
2022-12-18 02:19:33 +08:00
|
|
|
);
|
|
|
|
|
$table .= sprintf(
|
2022-12-19 04:15:15 +08:00
|
|
|
'<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>',
|
2022-12-18 02:19:33 +08:00
|
|
|
$row->id, $row->name, $row->image_large, $row->duration, $row->description, $action
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$table .= '</tbody></table>';
|
2022-12-19 04:15:15 +08:00
|
|
|
echo $table . $paginationBottom;
|
|
|
|
|
$js = <<<JS
|
|
|
|
|
jQuery('.buy').on('click', function (e) {
|
|
|
|
|
let medalId = jQuery(this).attr('data-id')
|
|
|
|
|
layer.confirm("确定要购买吗?", function (index) {
|
|
|
|
|
let params = {
|
|
|
|
|
action: "buyMedal",
|
|
|
|
|
params: {medal_id: medalId}
|
|
|
|
|
}
|
|
|
|
|
console.log(params)
|
|
|
|
|
jQuery.post('ajax.php', params, function(response) {
|
|
|
|
|
console.log(response)
|
|
|
|
|
if (response.ret != 0) {
|
|
|
|
|
layer.alert(response.msg)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
window.location.reload()
|
|
|
|
|
}, 'json')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
JS;
|
|
|
|
|
\Nexus\Nexus::js($js, 'footer', false);
|
2022-12-18 02:19:33 +08:00
|
|
|
stdfoot();
|
|
|
|
|
|