blessing-skin-server/app/Listeners/TextureRemoved.php

40 lines
1.0 KiB
PHP
Raw Normal View History

2019-05-07 15:16:53 +08:00
<?php
namespace App\Listeners;
use App\Models\User;
2019-05-07 15:16:53 +08:00
class TextureRemoved
{
2019-08-31 09:20:11 +08:00
public function handle($event)
2019-05-07 15:16:53 +08:00
{
$texture = $event->texture;
$texture->likers()->get()->each(function ($user) use ($texture) {
$user->closet()->detach($texture->tid);
if (option('return_score')) {
2019-07-30 14:29:02 +08:00
$user->score += option('score_per_closet_item');
$user->save();
2019-05-07 15:16:53 +08:00
}
});
2019-08-31 09:20:11 +08:00
if ($uploader = User::find($texture->uploader)) {
2019-05-07 15:16:53 +08:00
$ret = 0;
if (option('return_score')) {
$ret += $texture->size * (
$texture->public
? option('score_per_storage')
: option('private_score_per_storage')
);
}
if ($texture->public && option('take_back_scores_after_deletion', true)) {
$ret -= option('score_award_per_texture', 0);
}
2019-07-30 14:29:02 +08:00
$uploader->score += $ret;
$uploader->save();
2019-05-07 15:16:53 +08:00
}
}
}