finish plugin: sticky promotion

This commit is contained in:
xiaomlove
2022-06-08 14:15:59 +08:00
parent 44c750234a
commit 09f6e5b274
62 changed files with 954 additions and 178 deletions
+2
View File
@@ -15,11 +15,13 @@ class BonusLogs extends NexusModel
const BUSINESS_TYPE_CANCEL_HIT_AND_RUN = 1;
const BUSINESS_TYPE_BUY_MEDAL = 2;
const BUSINESS_TYPE_BUY_ATTENDANCE_CARD = 3;
const BUSINESS_TYPE_STICKY_PROMOTION = 4;
public static array $businessTypes = [
self::BUSINESS_TYPE_CANCEL_HIT_AND_RUN => ['text' => 'Cancel H&R'],
self::BUSINESS_TYPE_BUY_MEDAL => ['text' => 'Buy medal'],
self::BUSINESS_TYPE_BUY_ATTENDANCE_CARD => ['text' => 'Buy attendance card'],
self::BUSINESS_TYPE_STICKY_PROMOTION => ['text' => 'Buy torrent sticky promotion'],
];
public static function getBonusForCancelHitAndRun()
+25
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use App\Repositories\TagRepository;
use Illuminate\Database\Eloquent\Casts\Attribute;
use JeroenG\Explorer\Application\Explored;
use Laravel\Scout\Searchable;
@@ -27,6 +28,7 @@ class Torrent extends NexusModel
protected $casts = [
'added' => 'datetime',
'pt_gen' => 'array',
'promotion_until' => 'datetime',
];
public static $commentFields = [
@@ -156,6 +158,10 @@ class Torrent extends NexusModel
$spState = $this->sp_state;
$global = self::getGlobalPromotionState();
$log = sprintf('torrent: %s sp_state: %s, global sp state: %s', $this->id, $spState, $global);
if ($this->__ignore_global_sp_state) {
$log .= "[IGNORE_GLOBAL_SP_STATE]";
$global = self::PROMOTION_NORMAL;
}
if ($global != self::PROMOTION_NORMAL) {
$spState = $global;
$log .= sprintf(", global != %s, set sp_state to global: %s", self::PROMOTION_NORMAL, $global);
@@ -168,6 +174,13 @@ class Torrent extends NexusModel
return $spState;
}
public function posStateText(): Attribute
{
return new Attribute(
get: fn($value, $attributes) => nexus_trans('torrent.pos_state_' . $attributes['pos_state'])
);
}
public static function getGlobalPromotionState()
{
if (is_null(self::$globalPromotionState)) {
@@ -180,6 +193,18 @@ class Torrent extends NexusModel
return self::$globalPromotionState;
}
public static function getFieldsForList($appendTableName = false): array|bool
{
$fields = 'id, sp_state, promotion_time_type, promotion_until, banned, picktype, pos_state, category, source, medium, codec, standard, processing, team, audiocodec, leechers, seeders, name, small_descr, times_completed, size, added, comments,anonymous,owner,url,cache_stamp, pt_gen, hr';
$fields = preg_split('/[,\s]+/', $fields);
if ($appendTableName) {
foreach ($fields as &$value) {
$value = "torrents." . $value;
}
}
return $fields;
}
public function getHrAttribute(): string
{
$hrMode = Setting::get('hr.mode');
+12 -5
View File
@@ -11,6 +11,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\HasApiTokens;
use Nexus\Database\NexusDB;
class User extends Authenticatable
{
@@ -127,6 +128,7 @@ class User extends Authenticatable
protected $fillable = [
'username', 'email', 'passhash', 'secret', 'stylesheet', 'editsecret', 'added', 'modcomment', 'enabled', 'status',
'leechwarn', 'leechwarnuntil', 'page', 'class', 'uploaded', 'downloaded', 'clientselect', 'showclienterror', 'last_home',
'seedbonus', 'bonuscomment',
];
/**
@@ -396,15 +398,20 @@ class User extends Authenticatable
}
public function updateWithModComment(array $update, $modComment): bool
{
return $this->updateWithComment($update, $modComment, 'modcomment');
}
public function updateWithComment(array $update, $comment, $commentField): bool
{
if (!$this->exists) {
throw new \RuntimeException('This method only works when user exists!');
throw new \RuntimeException('This method only works when user exists !');
}
//@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);
$comment = addslashes($comment);
do_log("update: " . json_encode($update) . ", $commentField: $comment", 'notice');
$update[$commentField] = NexusDB::raw("if($commentField = '', '$comment', concat_ws('\n', '$comment', $commentField))");
return $this->update($update);
}
public function canAccessAdmin()