| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Module\Promotion\Commands;
- use App\Module\Promotion\Services\ReferralCodeService;
- use Illuminate\Console\Command;
- /**
- * 清理过期推荐码命令
- *
- * 用于清理过期的推荐码,释放数据库空间。
- */
- class CleanExpiredReferralCodesCommand extends Command
- {
- /**
- * 命令名称
- *
- * @var string
- */
- protected $signature = 'promotion:clean-expired-referral-codes {--debug-info : 显示详细信息}';
- /**
- * 命令描述
- *
- * @var string
- */
- protected $description = '清理过期的推荐码';
- /**
- * 执行命令
- *
- * @return int
- */
- public function handle()
- {
- $this->info('开始清理过期推荐码...');
- $showDebugInfo = $this->option('debug-info');
- try {
- $count = ReferralCodeService::cleanExpiredReferralCodes();
- if ($showDebugInfo) {
- $this->info("共清理了 {$count} 个过期推荐码");
- } else {
- $this->info("清理完成");
- }
- return 0;
- } catch (\Exception $e) {
- $this->error("清理过期推荐码失败: " . $e->getMessage());
- if ($showDebugInfo) {
- $this->error($e->getTraceAsString());
- }
- return 1;
- }
- }
- }
|