Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a941bfe
commit 44f7960
Showing
3 changed files
with
67 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of zhuchunshu. | ||
* @link https://github.com/zhuchunshu | ||
* @document https://github.com/zhuchunshu/super-forum | ||
* @contact laravel@88.com | ||
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE | ||
*/ | ||
namespace App\Plugins\Core\src\Crontab; | ||
|
||
use App\Model\AdminOption; | ||
use App\Plugins\Topic\src\Models\Topic; | ||
use App\Plugins\User\src\Models\UsersNotice; | ||
use App\Plugins\User\src\Models\UsersPm; | ||
use Hyperf\Crontab\Annotation\Crontab; | ||
|
||
/** | ||
* 用户私信清理 | ||
* @Crontab(name="CleanUsersPm", rule="0 * * * *", callback="execute", enable={CleanUsersPm::class, "isEnable"}, memo="用户私信清理") | ||
* 用户私信清理. | ||
* @Crontab(name="CleanUsersPm", rule="0 *\/12 * * *", callback="execute", enable={CleanUsersPm::class, "isEnable"}, memo="用户私信清理") | ||
*/ | ||
class CleanUsersPm | ||
{ | ||
public function execute() | ||
public function execute(): void | ||
{ | ||
// 消息保留时间,单位:秒 | ||
$reserve = (int)get_options('pm_msg_reserve', 7)*24*60*60; | ||
$reserve = (int) get_options('pm_msg_reserve', 7) * 24 * 60 * 60; | ||
|
||
foreach (UsersPm::query()->get() as $pm) { | ||
if (time()-strtotime($pm->created_at)>=$reserve) { | ||
if (time() - strtotime($pm->created_at) >= $reserve) { | ||
UsersPm::query()->where('id', $pm->id)->delete(); | ||
} | ||
} | ||
} | ||
|
||
public function isEnable(): bool | ||
{ | ||
return !((int)$this->get_options('pm_msg_reserve', 7) === 0); | ||
return ! ((int) $this->get_options('pm_msg_reserve', 7) === 0); | ||
} | ||
private function core_default($string=null, $default=null) | ||
|
||
private function core_default($string = null, $default = null) | ||
{ | ||
if ($string) { | ||
return $string; | ||
} | ||
return $default; | ||
} | ||
private function get_options($name, $default="") | ||
|
||
private function get_options($name, $default = '') | ||
{ | ||
if (!cache()->has('admin.options.'.$name)) { | ||
cache()->set("admin.options.".$name, @AdminOption::query()->where("name", $name)->first()->value); | ||
if (! cache()->has('admin.options.' . $name)) { | ||
cache()->set('admin.options.' . $name, @AdminOption::query()->where('name', $name)->first()->value); | ||
} | ||
return $this->core_default(cache()->get("admin.options.".$name), $default); | ||
return $this->core_default(cache()->get('admin.options.' . $name), $default); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters