mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
user medal add more bulk actions
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Models\UserMedal;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
@@ -148,4 +149,51 @@ class MedalRepository extends BaseRepository
|
||||
return NexusDB::statement($sql);
|
||||
}
|
||||
|
||||
public function increaseExpireAt(Collection $collection, string $field, int $duration): void
|
||||
{
|
||||
$this->checkExpireField($field);
|
||||
$idArr = $collection->pluck('id')->toArray();
|
||||
$result = NexusDB::table("user_medals")
|
||||
->whereIn('id', $idArr)
|
||||
->whereNotNull($field)
|
||||
->update([$field => NexusDB::raw("`$field` + INTERVAL $duration DAY")]);
|
||||
do_log(sprintf(
|
||||
"operator: %s, increase records: %s $field + $duration day, result: %s",
|
||||
get_pure_username(), implode(', ', $idArr), $result
|
||||
));
|
||||
}
|
||||
|
||||
public function updateExpireAt(Collection $collection, string $field, Carbon $expireAt): void
|
||||
{
|
||||
$this->checkExpireField($field);
|
||||
$idArr = $collection->pluck('id')->toArray();
|
||||
$result = NexusDB::table("user_medals")
|
||||
->whereIn('id', $idArr)
|
||||
->update([$field => $expireAt]);
|
||||
do_log(sprintf(
|
||||
"operator: %s, update records: %s $field $expireAt, result: %s",
|
||||
get_pure_username(), implode(', ', $idArr), $result
|
||||
));
|
||||
}
|
||||
|
||||
public function cancelExpireAt(Collection $collection, string $field): void
|
||||
{
|
||||
$this->checkExpireField($field);
|
||||
$idArr = $collection->pluck('id')->toArray();
|
||||
$result = NexusDB::table("user_medals")
|
||||
->whereIn('id', $idArr)
|
||||
->update([$field => NexusDB::raw("null")]);
|
||||
do_log(sprintf(
|
||||
"operator: %s, update records: %s $field null, result: %s",
|
||||
get_pure_username(), implode(', ', $idArr), $result
|
||||
));
|
||||
}
|
||||
|
||||
private function checkExpireField(string $field): void
|
||||
{
|
||||
if (!in_array($field, ['expire_at', 'bonus_addition_expire_at'])) {
|
||||
throw new \InvalidArgumentException("invalid field: $field");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user