mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-18 15:50:50 +08:00
medal add gift_fee_factor and user_medal add priority
This commit is contained in:
@@ -76,6 +76,12 @@ class MedalResource extends Resource
|
||||
->numeric()
|
||||
->default(0)
|
||||
,
|
||||
Forms\Components\TextInput::make('gift_fee_factor')
|
||||
->label(__('medal.fields.gift_fee_factor'))
|
||||
->helperText(__('medal.fields.gift_fee_factor_help'))
|
||||
->numeric()
|
||||
->default(0)
|
||||
,
|
||||
Forms\Components\Textarea::make('description')
|
||||
->label(__('label.description'))
|
||||
,
|
||||
@@ -96,6 +102,7 @@ class MedalResource extends Resource
|
||||
->formatStateUsing(fn ($record) => new HtmlString(sprintf('%s ~<br/>%s', $record->sale_begin_time ?? '--', $record->sale_end_time ?? '--')))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('bonus_addition_factor')->label(__('medal.fields.bonus_addition_factor')),
|
||||
Tables\Columns\TextColumn::make('gift_fee_factor')->label(__('medal.fields.gift_fee_factor')),
|
||||
Tables\Columns\TextColumn::make('price')->label(__('label.price')),
|
||||
|
||||
Tables\Columns\TextColumn::make('duration')->label(__('label.medal.duration')),
|
||||
|
||||
@@ -32,6 +32,7 @@ class BonusLogs extends NexusModel
|
||||
const BUSINESS_TYPE_BUY_TEMPORARY_INVITE = 15;
|
||||
const BUSINESS_TYPE_BUY_RAINBOW_ID = 16;
|
||||
const BUSINESS_TYPE_BUY_CHANGE_USERNAME_CARD = 17;
|
||||
const BUSINESS_TYPE_GIFT_MEDAL = 18;
|
||||
|
||||
public static array $businessTypes = [
|
||||
self::BUSINESS_TYPE_CANCEL_HIT_AND_RUN => ['text' => 'Cancel H&R'],
|
||||
@@ -51,6 +52,7 @@ class BonusLogs extends NexusModel
|
||||
self::BUSINESS_TYPE_BUY_TEMPORARY_INVITE => ['text' => 'Buy temporary invite'],
|
||||
self::BUSINESS_TYPE_BUY_RAINBOW_ID => ['text' => 'Buy rainbow ID'],
|
||||
self::BUSINESS_TYPE_BUY_CHANGE_USERNAME_CARD => ['text' => 'Buy change username card'],
|
||||
self::BUSINESS_TYPE_GIFT_MEDAL => ['text' => 'Gift medal to someone'],
|
||||
];
|
||||
|
||||
public static function getBonusForCancelHitAndRun()
|
||||
|
||||
@@ -18,6 +18,7 @@ class Medal extends NexusModel
|
||||
protected $fillable = [
|
||||
'name', 'description', 'image_large', 'image_small', 'price', 'duration', 'get_type',
|
||||
'display_on_medal_page', 'sale_begin_time', 'sale_end_time', 'inventory', 'bonus_addition_factor',
|
||||
'gift_fee_factor',
|
||||
];
|
||||
|
||||
public $timestamps = true;
|
||||
@@ -55,6 +56,23 @@ class Medal extends NexusModel
|
||||
return nexus_trans("label.permanent");
|
||||
}
|
||||
|
||||
public function checkCanBeBuy()
|
||||
{
|
||||
if ($this->get_type == self::GET_TYPE_GRANT) {
|
||||
throw new \RuntimeException(nexus_trans('medal.grant_only'));
|
||||
}
|
||||
$now = now();
|
||||
if ($this->sale_begin_time && $this->sale_begin_time->gt($now)) {
|
||||
throw new \RuntimeException(nexus_trans('medal.before_sale_begin_time'));
|
||||
}
|
||||
if ($this->sale_end_time && $this->sale_end_time->lt($now)) {
|
||||
throw new \RuntimeException(nexus_trans('medal.after_sale_end_time'));
|
||||
}
|
||||
if ($this->inventory !== null && $this->inventory <= 0) {
|
||||
throw new \RuntimeException(nexus_trans('medal.inventory_empty'));
|
||||
}
|
||||
}
|
||||
|
||||
public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'user_medals', 'medal_id', 'uid')->withTimestamps();
|
||||
|
||||
@@ -459,9 +459,9 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
public function medals(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Medal::class, 'user_medals', 'uid', 'medal_id')
|
||||
->withPivot(['id', 'expire_at', 'status'])
|
||||
->withPivot(['id', 'expire_at', 'status', 'priority'])
|
||||
->withTimestamps()
|
||||
->orderByPivot('id', 'desc')
|
||||
->orderByPivot('priority', 'desc')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Models\BonusLogs;
|
||||
use App\Models\HitAndRun;
|
||||
use App\Models\Invite;
|
||||
use App\Models\Medal;
|
||||
use App\Models\Message;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Models\UserMedal;
|
||||
@@ -58,19 +59,7 @@ 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.");
|
||||
}
|
||||
if ($medal->inventory !== null && $medal->inventory <= 0) {
|
||||
throw new \LogicException("Inventory empty.");
|
||||
}
|
||||
$now = now();
|
||||
if ($medal->sale_begin_time && $medal->sale_begin_time->gt($now)) {
|
||||
throw new \LogicException("Before sale begin time.");
|
||||
}
|
||||
if ($medal->sale_end_time && $medal->sale_end_time->lt($now)) {
|
||||
throw new \LogicException("After sale end time.");
|
||||
}
|
||||
$medal->checkCanBeBuy();
|
||||
$requireBonus = $medal->price;
|
||||
NexusDB::transaction(function () use ($user, $medal, $requireBonus) {
|
||||
$comment = nexus_trans('bonus.comment_buy_medal', [
|
||||
@@ -101,6 +90,67 @@ class BonusRepository extends BaseRepository
|
||||
|
||||
}
|
||||
|
||||
public function consumeToGiftMedal($uid, $medalId, $toUid): bool
|
||||
{
|
||||
$user = User::query()->findOrFail($uid);
|
||||
$toUser = User::query()->findOrFail($toUid);
|
||||
$medal = Medal::query()->findOrFail($medalId);
|
||||
$exists = $toUser->valid_medals()->where('medal_id', $medalId)->exists();
|
||||
do_log(last_query());
|
||||
if ($exists) {
|
||||
throw new \LogicException("user: $toUid already own this medal: $medalId.");
|
||||
}
|
||||
$medal->checkCanBeBuy();
|
||||
$giftFee = $medal->price * ($medal->gift_fee_factor ?? 0);
|
||||
$requireBonus = $medal->price + $giftFee;
|
||||
NexusDB::transaction(function () use ($user, $toUser, $medal, $requireBonus, $giftFee) {
|
||||
$comment = nexus_trans('bonus.comment_gift_medal', [
|
||||
'bonus' => $requireBonus,
|
||||
'medal_name' => $medal->name,
|
||||
'to_username' => $toUser->username,
|
||||
], $user->locale);
|
||||
do_log("comment: $comment");
|
||||
$this->consumeUserBonus($user, $requireBonus, BonusLogs::BUSINESS_TYPE_GIFT_MEDAL, "$comment(medal ID: {$medal->id})");
|
||||
|
||||
$expireAt = null;
|
||||
if ($medal->duration > 0) {
|
||||
$expireAt = Carbon::now()->addDays($medal->duration)->toDateTimeString();
|
||||
}
|
||||
$msg = [
|
||||
'sender' => 0,
|
||||
'receiver' => $toUser->id,
|
||||
'subject' => nexus_trans('message.receive_medal.subject', [], $toUser->locale),
|
||||
'msg' => nexus_trans('message.receive_medal.body', [
|
||||
'username' => $user->username,
|
||||
'cost_bonus' => $requireBonus,
|
||||
'medal_name' => $medal->name,
|
||||
'price' => $medal->price,
|
||||
'gift_fee_total' => $giftFee,
|
||||
'gift_fee_factor' => $medal->gift_fee_factor ?? 0,
|
||||
'expire_at' => $expireAt ?? nexus_trans('label.permanent'),
|
||||
'bonus_addition_factor' => $medal->bonus_addition_factor ?? 0,
|
||||
], $toUser->locale),
|
||||
'added' => now()
|
||||
];
|
||||
Message::add($msg);
|
||||
$toUser->medals()->attach([$medal->id => ['expire_at' => $expireAt, 'status' => UserMedal::STATUS_NOT_WEARING]]);
|
||||
if ($medal->inventory !== null) {
|
||||
$affectedRows = NexusDB::table('medals')
|
||||
->where('id', $medal->id)
|
||||
->where('inventory', $medal->inventory)
|
||||
->decrement('inventory')
|
||||
;
|
||||
if ($affectedRows != 1) {
|
||||
throw new \RuntimeException("Decrement medal({$medal->id}) inventory affected rows != 1($affectedRows)");
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function consumeToBuyAttendanceCard($uid): bool
|
||||
{
|
||||
$user = User::query()->findOrFail($uid);
|
||||
|
||||
@@ -74,7 +74,7 @@ class MedalRepository extends BaseRepository
|
||||
return $user->medals()->attach([$medal->id => ['expire_at' => $expireAt, 'status' => UserMedal::STATUS_NOT_WEARING]]);
|
||||
}
|
||||
|
||||
function toggleUserMedalStatus($id, $userId)
|
||||
public function toggleUserMedalStatus($id, $userId)
|
||||
{
|
||||
$userMedal = UserMedal::query()->findOrFail($id);
|
||||
if ($userMedal->uid != $userId) {
|
||||
@@ -91,4 +91,32 @@ class MedalRepository extends BaseRepository
|
||||
return $userMedal;
|
||||
}
|
||||
|
||||
public function saveUserMedal(int $userId, array $userMedalData)
|
||||
{
|
||||
$user = User::query()->findOrFail($userId);
|
||||
$validMedals = $user->valid_medals;
|
||||
if ($validMedals->isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
$statusCaseWhens = $priorityCaseWhens = $idArr = [];
|
||||
foreach ($validMedals as $medal) {
|
||||
$id = $medal->pivot->id;
|
||||
$idArr[] = $id;
|
||||
if (isset($userMedalData[$id]['status'])) {
|
||||
$status = UserMedal::STATUS_WEARING;
|
||||
} else {
|
||||
$status = UserMedal::STATUS_NOT_WEARING;
|
||||
}
|
||||
$statusCaseWhens[] = sprintf('when `id` = %s then %s', $id, $status);
|
||||
$priorityCaseWhens[] = sprintf('when `id` = %s then %s', $id, $userMedalData[$id]['priority'] ?? 0);
|
||||
}
|
||||
$sql = sprintf(
|
||||
'update user_medals set `status` = case %s end, `priority` = case %s end where id in (%s)',
|
||||
implode(' ', $statusCaseWhens), implode(' ', $priorityCaseWhens), implode(',', $idArr)
|
||||
);
|
||||
do_log("sql: $sql");
|
||||
clear_user_cache($userId);
|
||||
return NexusDB::statement($sql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('medals', function (Blueprint $table) {
|
||||
$table->float('gift_fee_factor', 10, 6)->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('medals', function (Blueprint $table) {
|
||||
$table->dropColumn(['gift_fee_factor']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('user_medals', function (Blueprint $table) {
|
||||
$table->integer('priority')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('user_medals', function (Blueprint $table) {
|
||||
$table->dropColumn(['priority']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-01-26');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-01-29');
|
||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
@@ -5870,20 +5870,33 @@ function msgalert($url, $text, $bgcolor = "red")
|
||||
function build_medal_image(\Illuminate\Support\Collection $medals, $maxHeight = 200, $withActions = false): string
|
||||
{
|
||||
$medalImages = [];
|
||||
$wrapBefore = '<div style="display: flex;justify-content: center;align-items: baseline;margin-top: 10px;">';
|
||||
$wrapAfter = '</div>';
|
||||
$wrapBefore = '<form><div style="display: flex;justify-content: center;margin-top: 10px;">';
|
||||
$wrapAfter = '</div></form>';
|
||||
foreach ($medals as $medal) {
|
||||
$html = sprintf('<div style="display: inline"><img src="%s" title="%s" class="preview" style="max-height: %spx"/>', $medal->image_large, $medal->name, $maxHeight);
|
||||
$html = sprintf('<div style="display: flex;flex-direction: column;justify-content: space-between;margin-right: 10px"><img src="%s" title="%s" class="preview" style="max-height: %spx;max-width: %spx"/>', $medal->image_large, $medal->name, $maxHeight, $maxHeight);
|
||||
if ($withActions) {
|
||||
$html .= sprintf(
|
||||
'<div style="display: flex;flex-direction: column;align-items:flex-start"><span>%s: %s</span><span>%s: %s</span><label>%s: <input type="number" name="priority_%s" value="%s" style="width: 50px" placeholder="%s"></label>',
|
||||
nexus_trans('label.expire_at'),
|
||||
$medal->pivot->expire_at ? format_datetime($medal->pivot->expire_at) : nexus_trans('label.permanent'),
|
||||
nexus_trans('medal.fields.bonus_addition_factor'),
|
||||
$medal->bonus_addition_factor ?? 0,
|
||||
nexus_trans('label.priority'),
|
||||
$medal->pivot->id,
|
||||
$medal->pivot->priority ?? 0,
|
||||
nexus_trans('label.priority_help')
|
||||
);
|
||||
$checked = '';
|
||||
if ($medal->pivot->status == \App\Models\UserMedal::STATUS_WEARING) {
|
||||
$checked = ' checked';
|
||||
}
|
||||
$html .= sprintf('<label>%s<input type="checkbox" name="medal_wearing_status" value="%s"%s></label>', nexus_trans('medal.action_wearing'), $medal->pivot->id, $checked);
|
||||
$html .= sprintf('<label>%s<input type="checkbox" name="status_%s" value="1"%s></label>', nexus_trans('medal.action_wearing'), $medal->pivot->id, $checked);
|
||||
$html .= '</div>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
$medalImages[] = $html;
|
||||
}
|
||||
$medalImages[] = sprintf('<div style="display: flex;flex-direction: column;justify-content: space-between;margin-right: 10px"><span></span><input type="button" id="save-user-medal-btn" value="%s"/></div>', nexus_trans('label.save'));
|
||||
return $wrapBefore . implode('', $medalImages) . $wrapAfter;
|
||||
}
|
||||
|
||||
@@ -5962,6 +5975,7 @@ function calculate_seed_bonus($uid, $torrentIdArr = null): array
|
||||
$valuetwo = $bzero_bonus * ( 2 / $pi);
|
||||
$valuethree = $logofpointone / ($nzero_bonus - 1);
|
||||
$timenow = time();
|
||||
$nowStr = date('Y-m-d H:i:s');
|
||||
$sectoweek = 7*24*60*60;
|
||||
|
||||
$A = $official_a = $size = $official_size = 0;
|
||||
@@ -5989,8 +6003,8 @@ function calculate_seed_bonus($uid, $torrentIdArr = null): array
|
||||
$officialAdditionalFactor = \App\Models\Setting::get('bonus.official_addition');
|
||||
$zeroBonusTag = \App\Models\Setting::get('bonus.zero_bonus_tag');
|
||||
$zeroBonusFactor = \App\Models\Setting::get('bonus.zero_bonus_factor');
|
||||
$userMedalResult = \Nexus\Database\NexusDB::select("select sum(bonus_addition_factor) as factor from medals where id in (select medal_id from user_medals where uid = $uid)");
|
||||
$medalAdditionalFactor = $userMedalResult[0]['factor'] ?? 0;
|
||||
$userMedalResult = \Nexus\Database\NexusDB::select("select sum(bonus_addition_factor) as factor from medals where id in (select medal_id from user_medals where uid = $uid and (expire_at is null or expire_at > '$nowStr'))");
|
||||
$medalAdditionalFactor = floatval($userMedalResult[0]['factor'] ?? 0);
|
||||
do_log("$logPrefix, sql: $sql, count: " . count($torrentResult) . ", officialTag: $officialTag, officialAdditionalFactor: $officialAdditionalFactor, zeroBonusTag: $zeroBonusTag, zeroBonusFactor: $zeroBonusFactor, medalAdditionalFactor: $medalAdditionalFactor");
|
||||
$last_action = "";
|
||||
foreach ($torrentResult as $torrent)
|
||||
|
||||
@@ -138,3 +138,26 @@ function buyMedal($params)
|
||||
$rep = new \App\Repositories\BonusRepository();
|
||||
return $rep->consumeToBuyMedal($CURUSER['id'], $params['medal_id']);
|
||||
}
|
||||
|
||||
function giftMedal($params)
|
||||
{
|
||||
global $CURUSER;
|
||||
$rep = new \App\Repositories\BonusRepository();
|
||||
return $rep->consumeToGiftMedal($CURUSER['id'], $params['medal_id'], $params['uid']);
|
||||
}
|
||||
|
||||
function saveUserMedal($params)
|
||||
{
|
||||
global $CURUSER;
|
||||
$data = [];
|
||||
foreach ($params as $param) {
|
||||
$fieldAndId = explode('_', $param['name']);
|
||||
$field = $fieldAndId[0];
|
||||
$id = $fieldAndId[1];
|
||||
$value = $param['value'];
|
||||
$data[$id][$field] = $value;
|
||||
}
|
||||
// dd($params, $data);
|
||||
$rep = new \App\Repositories\MedalRepository();
|
||||
return $rep->saveUserMedal($CURUSER['id'], $data);
|
||||
}
|
||||
|
||||
@@ -18,10 +18,12 @@ $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');
|
||||
$columnBuyLabel = nexus_trans('medal.buy_btn');
|
||||
$columnSaleBeginEndTimeLabel = nexus_trans('medal.fields.sale_begin_end_time');
|
||||
$columnInventoryLabel = nexus_trans('medal.fields.inventory');
|
||||
$columnBonusAdditionFactorLabel = nexus_trans('medal.fields.bonus_addition_factor');
|
||||
$columnGiftLabel = nexus_trans('medal.gift_btn');
|
||||
$columnGiftFeeFactorLabel = nexus_trans('medal.fields.gift_fee_factor');
|
||||
$header = '<h1 style="text-align: center">'.$title.'</h1>';
|
||||
$filterForm = <<<FORM
|
||||
<div>
|
||||
@@ -41,13 +43,15 @@ $table = <<<TABLE
|
||||
<td class="colhead">ID</td>
|
||||
<td class="colhead">$columnNameLabel</td>
|
||||
<td class="colhead">$columnImageLargeLabel</td>
|
||||
<td class="colhead">$columnSaleBeginEndTimeLabel</td>
|
||||
<td class="colhead" style="width: 115px">$columnSaleBeginEndTimeLabel</td>
|
||||
<td class="colhead">$columnBonusAdditionFactorLabel</td>
|
||||
<td class="colhead">$columnGiftFeeFactorLabel</td>
|
||||
<td class="colhead">$columnPriceLabel</td>
|
||||
<td class="colhead">$columnDurationLabel</td>
|
||||
<td class="colhead">$columnInventoryLabel</td>
|
||||
<td class="colhead">$columnDescriptionLabel</td>
|
||||
<td class="colhead">$columnActionLabel</td>
|
||||
<td class="colhead">$columnBuyLabel</td>
|
||||
<td class="colhead">$columnGiftLabel</td>
|
||||
</tr>
|
||||
</thead>
|
||||
TABLE;
|
||||
@@ -59,42 +63,51 @@ $userMedals = \App\Models\UserMedal::query()->where('uid', $CURUSER['id'])
|
||||
->keyBy('medal_id')
|
||||
;
|
||||
foreach ($rows as $row) {
|
||||
$disabled = ' disabled';
|
||||
$class = '';
|
||||
if ($userMedals->has($row->id)) {
|
||||
$btnText = nexus_trans('medal.buy_already');
|
||||
} elseif ($row->get_type == \App\Models\Medal::GET_TYPE_GRANT) {
|
||||
$btnText = nexus_trans('medal.grant_only');
|
||||
} elseif ($row->sale_begin_time && $row->sale_begin_time->gt($now)) {
|
||||
$btnText = nexus_trans('medal.before_sale_begin_time');
|
||||
} elseif ($row->sale_end_time && $row->sale_end_time->lt($now)) {
|
||||
$btnText = nexus_trans('medal.after_sale_end_time');
|
||||
} elseif ($row->inventory !== null && $row->inventory <= 0) {
|
||||
$btnText = nexus_trans('medal.inventory_empty');
|
||||
} elseif ($CURUSER['seedbonus'] < $row->price) {
|
||||
$btnText = nexus_trans('medal.require_more_bonus');
|
||||
} else {
|
||||
$btnText = nexus_trans('medal.buy_btn');
|
||||
$disabled = '';
|
||||
$class = 'buy';
|
||||
$buyDisabled = $giftDisabled = ' disabled';
|
||||
$buyClass = $giftClass = '';
|
||||
try {
|
||||
$row->checkCanBeBuy();
|
||||
if ($userMedals->has($row->id)) {
|
||||
$buyBtnText = nexus_trans('medal.buy_already');
|
||||
} elseif ($CURUSER['seedbonus'] < $row->price) {
|
||||
$buyBtnText = nexus_trans('medal.require_more_bonus');
|
||||
} else {
|
||||
$buyBtnText = nexus_trans('medal.buy_btn');
|
||||
$buyDisabled = '';
|
||||
$buyClass = 'buy';
|
||||
}
|
||||
if ($CURUSER['seedbonus'] < $row->price * (1 + ($row->gift_fee_factor ?? 0))) {
|
||||
$giftBtnText = nexus_trans('medal.require_more_bonus');
|
||||
} else {
|
||||
$giftBtnText = nexus_trans('medal.gift_btn');
|
||||
$giftDisabled = '';
|
||||
$giftClass = 'gift';
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
$buyBtnText = $giftBtnText = $exception->getMessage();
|
||||
}
|
||||
$action = sprintf(
|
||||
$buyAction = sprintf(
|
||||
'<input type="button" class="%s" data-id="%s" value="%s"%s>',
|
||||
$class, $row->id, $btnText, $disabled
|
||||
$buyClass, $row->id, $buyBtnText, $buyDisabled
|
||||
);
|
||||
$giftAction = sprintf(
|
||||
'<input type="number" class="uid" %s style="width: 60px" placeholder="UID"><input type="button" class="%s" data-id="%s" value="%s"%s>',
|
||||
$giftDisabled, $giftClass, $row->id, $giftBtnText, $giftDisabled
|
||||
);
|
||||
$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 ~<br>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>',
|
||||
$row->id, $row->name, $row->image_large, $row->sale_begin_time ?? '--', $row->sale_end_time ?? '--', $row->bonus_addition_factor, number_format($row->price), $row->durationText, $row->inventory ?? nexus_trans('label.infinite'), $row->description, $action
|
||||
'<tr><td><span class="nowrap">%s</span></td><td><span class="nowrap">%s</span></td><td><img src="%s" style="max-width: 60px;max-height: 60px;" class="preview" /></td><td>%s ~<br>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>',
|
||||
$row->id, $row->name, $row->image_large, $row->sale_begin_time ?? '--', $row->sale_end_time ?? '--', $row->bonus_addition_factor, $row->gift_fee_factor ?? 0, number_format($row->price), $row->durationText, $row->inventory ?? nexus_trans('label.infinite'), $row->description, $buyAction, $giftAction
|
||||
);
|
||||
}
|
||||
$table .= '</tbody></table>';
|
||||
echo $header . $table . $paginationBottom;
|
||||
end_main_frame();
|
||||
$confirmMsg = nexus_trans('medal.confirm_to_buy');
|
||||
$confirmBuyMsg = nexus_trans('medal.confirm_to_buy');
|
||||
$confirmGiftMsg = nexus_trans('medal.confirm_to_gift');
|
||||
$js = <<<JS
|
||||
jQuery('.buy').on('click', function (e) {
|
||||
let medalId = jQuery(this).attr('data-id')
|
||||
layer.confirm("{$confirmMsg}", function (index) {
|
||||
layer.confirm("{$confirmBuyMsg}", function (index) {
|
||||
let params = {
|
||||
action: "buyMedal",
|
||||
params: {medal_id: medalId}
|
||||
@@ -110,6 +123,29 @@ jQuery('.buy').on('click', function (e) {
|
||||
}, 'json')
|
||||
})
|
||||
})
|
||||
jQuery('.gift').on('click', function (e) {
|
||||
let medalId = jQuery(this).attr('data-id')
|
||||
let uid = jQuery(this).prev().val()
|
||||
if (!uid) {
|
||||
layer.alert('Require UID')
|
||||
return
|
||||
}
|
||||
layer.confirm("{$confirmGiftMsg}" + uid + " ?", function (index) {
|
||||
let params = {
|
||||
action: "giftMedal",
|
||||
params: {medal_id: medalId, uid: uid}
|
||||
}
|
||||
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);
|
||||
stdfoot();
|
||||
|
||||
@@ -77,14 +77,16 @@ print("<h1 style='margin:0px'>" . get_username($user['id'], true,false) . $count
|
||||
if ($userInfo->valid_medals->isNotEmpty()) {
|
||||
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);
|
||||
let checked = input.prop("checked")
|
||||
jQuery.post('ajax.php', {params: {id: this.value}, action: 'toggleUserMedalStatus'}, function (response) {
|
||||
jQuery('#save-user-medal-btn').on("click", function (e) {
|
||||
let form = jQuery(this).closest('form');
|
||||
let data = form.serializeArray();
|
||||
console.log(data)
|
||||
jQuery.post('ajax.php', {params: data, action: 'saveUserMedal'}, function (response) {
|
||||
console.log(response)
|
||||
if (response.ret != 0) {
|
||||
input.prop("checked", !checked)
|
||||
layer.alert(response.msg)
|
||||
} else {
|
||||
window.location.reload()
|
||||
}
|
||||
}, 'json')
|
||||
})
|
||||
|
||||
@@ -6,6 +6,7 @@ return [
|
||||
'comment_buy_temporary_invite' => 'Spend :bonus bonus buy :count temporary invite',
|
||||
'comment_buy_rainbow_id' => 'Spend :bonus bonus buy :duration days rainbow ID',
|
||||
'comment_buy_change_username_card' => 'Spend :bonus bonus buy change username card',
|
||||
'comment_gift_medal' => 'Spend :bonus bonus buy :medal_name and gift to :to_username',
|
||||
'table_thead' => [
|
||||
'reward_type' => 'Reward type',
|
||||
'count' => 'Count',
|
||||
|
||||
@@ -35,6 +35,7 @@ return [
|
||||
'reset' => 'Reset',
|
||||
'anonymous' => 'Anonymous',
|
||||
'infinite' => 'Infinite',
|
||||
'save' => 'Save',
|
||||
'setting' => [
|
||||
'nav_text' => 'Setting',
|
||||
'backup' => [
|
||||
|
||||
@@ -28,10 +28,17 @@ return [
|
||||
'users_count' => 'Sold counts',
|
||||
'bonus_addition_factor' => 'Bonus addition factor',
|
||||
'bonus_addition_factor_help' => 'For example: 0.01 means 1% addition, leave blank no addition',
|
||||
'gift_fee_factor' => 'Gift fee factor',
|
||||
'gift_fee_factor_help' => 'The additional fee charged for gifts to other users is equal to the price multiplied by this factor',
|
||||
],
|
||||
'buy_already' => 'Already buy',
|
||||
'buy_btn' => 'Buy',
|
||||
'confirm_to_buy' => 'Sure you want to buy?',
|
||||
'require_more_bonus' => 'Require more bonus',
|
||||
'grant_only' => 'Grant only',
|
||||
'before_sale_begin_time' => 'Before sale begin time',
|
||||
'after_sale_end_time' => 'After sale end time',
|
||||
'inventory_empty' => 'Inventory empty',
|
||||
'gift_btn' => 'Gift',
|
||||
'confirm_to_gift' => 'Confirm to gift to user ',
|
||||
];
|
||||
|
||||
@@ -27,4 +27,8 @@ return [
|
||||
'subject' => 'Temporary invite :change_type',
|
||||
'body' => 'Your temporary invite count had :change_type :count by :operator, reason: :reason.',
|
||||
],
|
||||
'receive_medal' => [
|
||||
'subject' => 'Receive gift medal',
|
||||
'body' => "User :username purchased a medal [:medal_name] at a cost of :cost_bonus and gave it to you. The medal is worth :price, the fee is :gift_fee_total(factor: :gift_fee_factor), you will have this medal until: :expire_at, and the medal's bonus addition factor is: :bonus_addition_factor.",
|
||||
],
|
||||
];
|
||||
|
||||
@@ -6,6 +6,7 @@ return [
|
||||
'comment_buy_temporary_invite' => '花费 :bonus 魔力购买了 :count 个临时邀请',
|
||||
'comment_buy_rainbow_id' => '花费 :bonus 魔力购买了 :duration 天的彩虹 ID',
|
||||
'comment_buy_change_username_card' => '花费 :bonus 魔力购买了改名卡',
|
||||
'comment_gift_medal' => '花费 :bonus 魔力购买了 :medal_name 并赠送给 :to_username',
|
||||
'table_thead' => [
|
||||
'reward_type' => '奖励类型',
|
||||
'count' => '数量',
|
||||
|
||||
@@ -35,6 +35,7 @@ return [
|
||||
'reset' => '重置',
|
||||
'anonymous' => '匿名',
|
||||
'infinite' => '无限',
|
||||
'save' => '保存',
|
||||
'setting' => [
|
||||
'nav_text' => '设置',
|
||||
'backup' => [
|
||||
|
||||
@@ -28,6 +28,8 @@ return [
|
||||
'users_count' => '已售数量',
|
||||
'bonus_addition_factor' => '魔力加成系数',
|
||||
'bonus_addition_factor_help' => '如:0.01 表示 1% 的加成,留空无加成',
|
||||
'gift_fee_factor' => '赠送手续费系数',
|
||||
'gift_fee_factor_help' => '赠送给其他用户时额外收取手续费等于价格乘以此系数',
|
||||
],
|
||||
'buy_already' => '已经购买',
|
||||
'buy_btn' => '购买',
|
||||
@@ -37,4 +39,6 @@ return [
|
||||
'before_sale_begin_time' => '未到可购买时间',
|
||||
'after_sale_end_time' => '已过可购买时间',
|
||||
'inventory_empty' => '库存不足',
|
||||
'gift_btn' => '赠送',
|
||||
'confirm_to_gift' => '确定要赠送给用户 ',
|
||||
];
|
||||
|
||||
@@ -27,4 +27,8 @@ return [
|
||||
'subject' => '临时邀请:change_type',
|
||||
'body' => '你的临时邀请被管理员 :operator :change_type :count 个,理由::reason。',
|
||||
],
|
||||
'receive_medal' => [
|
||||
'subject' => '收到赠送勋章',
|
||||
'body' => '用户 :username 花费魔力 :cost_bonus 购买了勋章[:medal_name]并赠送与你。此勋章价值 :price,手续费 :gift_fee_total(系数::gift_fee_factor),你将拥有此勋章有效期至: :expire_at,勋章的魔力加成系数为: :bonus_addition_factor。',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -6,6 +6,7 @@ return [
|
||||
'comment_buy_temporary_invite' => '花費 :bonus 魔力購買了 :count 個臨時邀請',
|
||||
'comment_buy_rainbow_id' => '花費 :bonus 魔力購買了 :duration 天的彩虹 ID',
|
||||
'comment_buy_change_username_card' => '花費 :bonus 魔力購買了改名卡',
|
||||
'comment_gift_medal' => '花費 :bonus 魔力購買了 :medal_name 並贈送給 :to_username',
|
||||
'table_thead' => [
|
||||
'reward_type' => '獎勵類型',
|
||||
'count' => '數量',
|
||||
|
||||
@@ -35,6 +35,7 @@ return [
|
||||
'reset' => '重置',
|
||||
'anonymous' => '匿名',
|
||||
'infinite' => '無限',
|
||||
'save' => '保存',
|
||||
'setting' => [
|
||||
'nav_text' => '設置',
|
||||
'backup' => [
|
||||
|
||||
@@ -28,10 +28,17 @@ return [
|
||||
'users_count' => '已售數量',
|
||||
'bonus_addition_factor' => '魔力加成系數',
|
||||
'bonus_addition_factor_help' => '如:0.01 表示 1% 的加成,留空無加成',
|
||||
'gift_fee_factor' => '贈送手續費系數',
|
||||
'gift_fee_factor_help' => '贈送給其他用戶時額外收取手續費等於價格乘以此系數',
|
||||
],
|
||||
'buy_already' => '已經購買',
|
||||
'buy_btn' => '購買',
|
||||
'confirm_to_buy' => '確定要購買嗎?',
|
||||
'require_more_bonus' => '需要更多魔力值',
|
||||
'grant_only' => '僅授予',
|
||||
'before_sale_begin_time' => '未到可購買時間',
|
||||
'after_sale_end_time' => '已過可購買時間',
|
||||
'inventory_empty' => '庫存不足',
|
||||
'gift_btn' => '贈送',
|
||||
'confirm_to_gift' => '確定要贈送給用戶 ',
|
||||
];
|
||||
|
||||
@@ -26,4 +26,8 @@ return [
|
||||
'subject' => '臨時邀請:change_type',
|
||||
'body' => '你的臨時邀請被管理員 :operator :change_type :count 個,理由::reason。',
|
||||
],
|
||||
'receive_medal' => [
|
||||
'subject' => '收到贈送勛章',
|
||||
'body' => '用戶 :username 花費魔力 :cost_bonus 購買了勛章[:medal_name]並贈送與你。此勛章價值 :price,手續費 :gift_fee_total(系數::gift_fee_factor),你將擁有此勛章有效期至: :expire_at,勛章的魔力加成系數為: :bonus_addition_factor。',
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user