[api] reward + thanks

This commit is contained in:
xiaomlove
2022-03-30 15:37:11 +08:00
parent b613a46b8d
commit 3e4a5766c4
38 changed files with 983 additions and 64 deletions
+39
View File
@@ -3,6 +3,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
class Comment extends NexusModel
{
protected $casts = [
@@ -10,6 +12,43 @@ class Comment extends NexusModel
'editdate' => 'datetime',
];
protected $fillable = ['user', 'torrent', 'added', 'text', 'ori_text', 'editedby', 'editdate', 'offer', 'request', 'anonymous'];
const TYPE_TORRENT = 'torrent';
const TYPE_REQUEST = 'request';
const TYPE_OFFER = 'offer';
const TYPE_MAPS = [
self::TYPE_TORRENT => [
'model' => Torrent::class,
'foreign_key' => 'torrent',
'target_name_field' => 'name',
'target_script' => 'details.php?id=%s'
],
self::TYPE_REQUEST => [
'model' => Request::class,
'foreign_key' => 'request',
'target_name_field' => 'request',
'target_script' => 'viewrequests.php?id=%s&req_details=1'
],
self::TYPE_OFFER => [
'model' => Offer::class,
'foreign_key' => 'offer',
'target_name_field' => 'name',
'target_script' => 'offers.php?id=%s&off_details=1'
],
];
public function scopeType(Builder $query, $type)
{
foreach (self::TYPE_MAPS as $key => $value) {
if ($type != $key) {
$query->where($value['foreign_key'], 0);
}
}
return $query;
}
public function related_torrent()
{
return $this->belongsTo(Torrent::class, 'torrent');
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App\Models;
class Offer extends NexusModel
{
protected $fillable = ['userid', 'name', 'descr', 'comments', 'added'];
protected $casts = [
'added' => 'datetime'
];
public function user()
{
return $this->belongsTo(User::class, 'userid');
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Models;
class Poll extends NexusModel
{
protected $fillable = ['added', 'question', 'option0', 'option1', 'option2', 'option3', 'option4', 'option5'];
protected $casts = [
'added' => 'datetime'
];
const MAX_OPTION_INDEX = 19;
public function answers()
{
return $this->hasMany(PollAnswer::class, 'pollid');
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace App\Models;
class PollAnswer extends NexusModel
{
protected $table = 'pollanswers';
protected $fillable = ['pollid', 'userid', 'selection',];
public function poll()
{
return $this->belongsTo(Poll::class, 'pollid');
}
public function user()
{
return $this->belongsTo(User::class, 'userid');
}
}
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App\Models;
class Request extends NexusModel
{
protected $fillable = ['userid', 'request', 'descr', 'comments', 'hits', 'added'];
protected $casts = [
'added' => 'datetime'
];
public function user()
{
return $this->belongsTo(User::class, 'userid');
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace App\Models;
class Reward extends NexusModel
{
protected $table = 'magic';
protected $fillable = ['torrentid', 'userid', 'value', ];
public $timestamps = true;
public function user()
{
return $this->belongsTo(User::class, 'userid');
}
}
+2
View File
@@ -5,6 +5,8 @@ namespace App\Models;
class Thank extends NexusModel
{
protected $fillable = ['torrentid', 'userid'];
public function user()
{
return $this->belongsTo(User::class, 'userid');
+15 -35
View File
@@ -28,6 +28,11 @@ class Torrent extends NexusModel
'added' => 'datetime'
];
public static $commentFields = [
'id', 'name', 'added', 'visible', 'banned', 'owner', 'sp_state', 'pos_state', 'hr', 'picktype', 'picktime',
'last_action', 'leechers', 'seeders', 'times_completed', 'views', 'size'
];
public static $basicRelations = [
'basic_category', 'basic_audio_codec', 'basic_codec', 'basic_media',
'basic_source', 'basic_standard', 'basic_team',
@@ -73,42 +78,9 @@ class Torrent extends NexusModel
self::PROMOTION_ONE_THIRD_DOWN => ['text' => '30%', 'up_multiplier' => 1, 'down_multiplier' => 0.3],
];
public function mappableAs(): array
{
return [
'id' => 'long',
'name' => [
'type' => 'text',
'analyzer' => 'ik_max_word',
],
'descr' => [
'type' => 'text',
'analyzer' => 'ik_max_word',
],
'owner' => 'long',
'source' => 'long',
'leechers' => 'long',
'seeders' => 'long',
'added' => 'date',
'owner_info' => [
const BONUS_REWARD_VALUES = [50, 100, 200, 500, 1000];
]
];
}
public function toSearchableArray()
{
return [
'id' => $this->id,
'name' => $this->name,
'descr' => $this->descr,
'owner' => $this->owner,
'source' => $this->source,
'leechers' => $this->leechers,
'seeders' => $this->seeders,
'added' => $this->added,
];
}
public function getSpStateRealTextAttribute()
{
@@ -185,7 +157,10 @@ class Torrent extends NexusModel
public static function getFieldLabels(): array
{
$fields = ['comments', 'times_completed', 'peers_count', 'thank_users_count', 'numfiles', 'bookmark_yes', 'bookmark_no'];
$fields = [
'comments', 'times_completed', 'peers_count', 'thank_users_count', 'numfiles', 'bookmark_yes', 'bookmark_no',
'reward_yes', 'reward_no', 'reward_logs', 'download', 'thanks_yes', 'thanks_no'
];
$result = [];
foreach($fields as $field) {
$result[$field] = nexus_trans("torrent.show.{$field}_label");
@@ -320,4 +295,9 @@ class Torrent extends NexusModel
return $this->belongsToMany(Tag::class, 'torrent_tags', 'torrent_id', 'tag_id')
->orderByRaw(sprintf("field(`tags`.`id`,%s)", TagRepository::getOrderByFieldIdString()));
}
public function reward_logs(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Reward::class, 'torrentid');
}
}
+15
View File
@@ -364,6 +364,21 @@ class User extends Authenticatable
return $this->valid_medals()->where('user_medals.status', UserMedal::STATUS_WEARING);
}
public function reward_torrent_logs(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Reward::class, 'userid');
}
public function thank_torrent_logs(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Thank::class, 'userid');
}
public function poll_answers(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(PollAnswer::class, 'userid');
}
public function getAvatarAttribute($value)
{
if ($value) {