[H&R] basically

This commit is contained in:
xiaomlove
2021-06-21 02:01:26 +08:00
parent 45aba84111
commit d2a8f1a1a6
39 changed files with 966 additions and 74 deletions

27
app/Models/BonusLogs.php Normal file
View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models;
class BonusLogs extends NexusModel
{
protected $table = 'bonus_logs';
protected $fillable = ['uid', 'business_type', 'old_total_value', 'value', 'new_total_value', 'comment'];
const DEFAULT_BONUS_CANCEL_ONE_HIT_AND_RUN = 10000;
const BUSINESS_TYPE_CANCEL_HIT_AND_RUN = 1;
public static $businessTypes = [
self::BUSINESS_TYPE_CANCEL_HIT_AND_RUN => ['text' => 'Cancel H&R'],
];
public static function getBonusForCancelHitAndRun()
{
$result = Setting::get('bonus.cancel_hr');
return $result ?? self::DEFAULT_BONUS_CANCEL_ONE_HIT_AND_RUN;
}
}

View File

@@ -6,25 +6,73 @@ class HitAndRun extends NexusModel
{
protected $table = 'hit_and_runs';
protected $fillable = ['uid', 'peer_id', 'torrent_id', 'status', 'comment'];
protected $fillable = ['uid', 'snatch_id', 'torrent_id', 'status', 'comment'];
public $timestamps = true;
const STATUS_INSPECTING = 1;
const STATUS_PASSED = 2;
const STATUS_NOT_PASSED = 3;
const STATUS_CANCELED = 4;
const STATUS_REACHED = 2;
const STATUS_UNREACHED = 3;
const STATUS_PARDONED = 4;
public static $status = [
self::STATUS_INSPECTING => ['text' => '考察中'],
self::STATUS_PASSED => ['text' => '已通过'],
self::STATUS_NOT_PASSED => ['text' => '未通过'],
self::STATUS_CANCELED => ['text' => '已取消'],
self::STATUS_INSPECTING => ['text' => 'Inspecting'],
self::STATUS_REACHED => ['text' => 'Reached'],
self::STATUS_UNREACHED => ['text' => 'Unreached'],
self::STATUS_PARDONED => ['text' => 'Pardoned'],
];
const MODE_DISABLED = 'disabled';
const MODE_MANUAL = 'manual';
const MODE_GLOBAL = 'global';
public static $modes = [
self::MODE_DISABLED => ['text' => 'Disabled'],
self::MODE_MANUAL => ['text' => 'Manual'],
self::MODE_GLOBAL => ['text' => 'Global'],
];
public function getStatusTextAttribute()
{
return self::$status[$this->status] ?? '';
return nexus_trans('hr.status_' . $this->status);
}
public static function listStatus(): array
{
$result = self::$status;
foreach ($result as $key => &$value) {
$value['text'] = nexus_trans('hr.status_' . $key);
}
return $result;
}
public static function listModes(): array
{
$result = self::$modes;
foreach ($result as $key => &$value) {
$value['text'] = nexus_trans('hr.mode_' . $key);
}
return $result;
}
public static function getIsEnabled(): bool
{
return Setting::get('hr.mode') != self::MODE_DISABLED;
}
public function torrent(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Torrent::class, 'torrent_id');
}
public function snatch(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Snatch::class, 'snatched_id');
}
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class, 'uid');
}

View File

@@ -41,6 +41,31 @@ class Torrent extends NexusModel
self::POS_STATE_STICKY_FIRST => ['text' => 'Sticky first', 'icon_counts' => 2],
];
const HR_YES = 1;
const HR_NO = 0;
public static $hrStatus = [
self::HR_NO => ['text' => 'NO'],
self::HR_YES => ['text' => 'YES'],
];
public function getHrAttribute(): string
{
$hrMode = Setting::get('hr.mode');
if ($hrMode == HitAndRun::MODE_GLOBAL) {
return self::HR_YES;
}
if ($hrMode == HitAndRun::MODE_DISABLED) {
return self::HR_NO;
}
return $this->getRawOriginal('hr');
}
public function getHrTextAttribute()
{
return self::$hrStatus[$this->hr] ?? '';
}
public static function getBasicInfo(): array
{
$result = [];

View File

@@ -108,7 +108,7 @@ class User extends Authenticatable
*/
protected $fillable = [
'username', 'email', 'passhash', 'secret', 'stylesheet', 'editsecret', 'added', 'modcomment', 'enabled', 'status',
'leechwarn', 'leechwarnuntil'
'leechwarn', 'leechwarnuntil', 'page'
];
/**
@@ -238,6 +238,11 @@ class User extends Authenticatable
'torrentid');
}
public function hitAndRuns(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(HitAndRun::class, 'uid');
}
public function getAvatarAttribute($value)
{
if ($value) {
@@ -260,6 +265,7 @@ class User extends Authenticatable
//@todo how to do prepare bindings here ?
$modComment = addslashes($modComment);
$update['modcomment'] = DB::raw("concat_ws('\n', '$modComment', modcomment)");
do_log("update: " . json_encode($update) . ", modcomment: $modComment", 'notice');
return $this->update($update);
}