mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
finish plugin: sticky promotion
This commit is contained in:
@@ -23,6 +23,9 @@ class BonusRepository extends BaseRepository
|
||||
if ($hitAndRun->uid != $uid) {
|
||||
throw new \LogicException("H&R: $hitAndRunId not belongs to user: $uid.");
|
||||
}
|
||||
if ($hitAndRun->status == HitAndRun::STATUS_PARDONED) {
|
||||
throw new \LogicException("H&R: $hitAndRunId already pardoned.");
|
||||
}
|
||||
$requireBonus = BonusLogs::getBonusForCancelHitAndRun();
|
||||
NexusDB::transaction(function () use ($user, $hitAndRun, $requireBonus) {
|
||||
$comment = nexus_trans('hr.bonus_cancel_comment', [
|
||||
@@ -92,8 +95,11 @@ class BonusRepository extends BaseRepository
|
||||
|
||||
}
|
||||
|
||||
private function consumeUserBonus($user, $requireBonus, $logBusinessType, $logComment = '')
|
||||
public function consumeUserBonus($user, $requireBonus, $logBusinessType, $logComment = '')
|
||||
{
|
||||
if ($requireBonus <= 0) {
|
||||
return;
|
||||
}
|
||||
if ($user->seedbonus < $requireBonus) {
|
||||
do_log("user: {$user->id}, bonus: {$user->seedbonus} < requireBonus: $requireBonus", 'error');
|
||||
throw new \LogicException("User bonus point not enough.");
|
||||
|
||||
@@ -110,7 +110,7 @@ class HitAndRunRepository extends BaseRepository
|
||||
->with([
|
||||
'torrent' => function ($query) {$query->select(['id', 'size', 'name']);},
|
||||
'snatch',
|
||||
'user' => function ($query) {$query->select(['id', 'username', 'lang', 'class', 'donoruntil']);},
|
||||
'user' => function ($query) {$query->select(['id', 'username', 'lang', 'class', 'donoruntil', 'enabled']);},
|
||||
'user.language',
|
||||
]);
|
||||
if (!is_null($uid)) {
|
||||
@@ -309,6 +309,10 @@ class HitAndRunRepository extends BaseRepository
|
||||
do_log("[DO_NOT_DISABLE_USER], return");
|
||||
return true;
|
||||
}
|
||||
if ($hitAndRun->user->enabled == 'no') {
|
||||
do_log("[USER_ALREADY_DISABLED], return");
|
||||
return true;
|
||||
}
|
||||
//disable user
|
||||
/** @var User $user */
|
||||
$user = $hitAndRun->user;
|
||||
@@ -370,7 +374,7 @@ class HitAndRunRepository extends BaseRepository
|
||||
public function pardon($id, User $user): bool
|
||||
{
|
||||
$model = HitAndRun::query()->findOrFail($id);
|
||||
if (!in_array($model->status, [HitAndRun::STATUS_INSPECTING, HitAndRun::STATUS_UNREACHED])) {
|
||||
if (!in_array($model->status, $this->getCanPardonStatus())) {
|
||||
throw new \LogicException("Can't be pardoned due to status is: " . $model->status_text . " !");
|
||||
}
|
||||
$model->status = HitAndRun::STATUS_PARDONED;
|
||||
@@ -381,7 +385,7 @@ class HitAndRunRepository extends BaseRepository
|
||||
|
||||
public function bulkPardon(array $params, User $user): int
|
||||
{
|
||||
$query = $this->getBulkQuery($params)->where('status', HitAndRun::STATUS_INSPECTING);
|
||||
$query = $this->getBulkQuery($params)->whereIn('status', $this->getCanPardonStatus());
|
||||
$update = [
|
||||
'status' => HitAndRun::STATUS_PARDONED,
|
||||
'comment' => $this->getCommentUpdateRaw(addslashes('Pardon by ' . $user->username)),
|
||||
@@ -398,4 +402,9 @@ class HitAndRunRepository extends BaseRepository
|
||||
{
|
||||
return DB::raw(sprintf("if (comment = '', '%s', concat('\n', '%s', comment))", $comment, $comment));
|
||||
}
|
||||
|
||||
private function getCanPardonStatus(): array
|
||||
{
|
||||
return [HitAndRun::STATUS_INSPECTING, HitAndRun::STATUS_UNREACHED];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -676,10 +676,11 @@ class SearchRepository extends BaseRepository
|
||||
foreach ($response['hits']['hits'] as $value) {
|
||||
$torrentIdArr[] = $value['_source']['torrent_id'];
|
||||
}
|
||||
$fieldStr = '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';
|
||||
// $fieldStr = '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 = Torrent::getFieldsForList();
|
||||
$idStr = implode(',', $torrentIdArr);
|
||||
$result['data'] = Torrent::query()
|
||||
->selectRaw($fieldStr)
|
||||
->select($fields)
|
||||
->whereIn('id', $torrentIdArr)
|
||||
->orderByRaw("field(id,$idStr)")
|
||||
->get()
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\Models\Setting;
|
||||
use App\Models\Snatch;
|
||||
use App\Models\Torrent;
|
||||
use App\Models\User;
|
||||
use App\Models\UserBanLog;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -134,6 +135,9 @@ class TrackerRepository extends BaseRepository
|
||||
}
|
||||
}
|
||||
$repDict = $this->generateSuccessAnnounceResponse($torrent, $queries, $user, $withPeers);
|
||||
if ($isReAnnounce == self::ANNOUNCE_FIRST) {
|
||||
do_action('announced', $torrent->toArray(), $user->toArray(), $queries);
|
||||
}
|
||||
} catch (ClientNotAllowedException $exception) {
|
||||
do_log("[ClientNotAllowedException] " . $exception->getMessage());
|
||||
if (isset($user) && $user->showclienterror == 'no') {
|
||||
@@ -368,7 +372,7 @@ class TrackerRepository extends BaseRepository
|
||||
return $user;
|
||||
}
|
||||
|
||||
protected function checkTorrent($queries, User $user)
|
||||
protected function checkTorrent($queries, User $user): Torrent
|
||||
{
|
||||
// Check Info Hash Against Torrents Table
|
||||
$torrent = $this->getTorrentByInfoHash($queries['info_hash']);
|
||||
@@ -381,8 +385,7 @@ class TrackerRepository extends BaseRepository
|
||||
if ($torrent->banned == 'yes' && $user->class < Setting::get('authority.seebanned')) {
|
||||
throw new TrackerException("torrent banned");
|
||||
}
|
||||
|
||||
return $torrent;
|
||||
return array_filter('torrent_detail', $torrent);
|
||||
}
|
||||
|
||||
protected function checkPeer(Torrent $torrent, array $queries, User $user): void
|
||||
@@ -518,6 +521,12 @@ class TrackerRepository extends BaseRepository
|
||||
Cheater::query()->insert($data);
|
||||
$modComment = "We believe you're trying to cheat. And your account is disabled.";
|
||||
$user->updateWithModComment(['enabled' => User::ENABLED_NO], $modComment);
|
||||
$userBanLog = [
|
||||
'uid' => $user->id,
|
||||
'username' => $user->username,
|
||||
'reason' => "$comment(Upload speed:" . mksize($upSpeed) . "/s)"
|
||||
];
|
||||
UserBanLog::query()->insert($userBanLog);
|
||||
throw new TrackerException($modComment);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user