mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-15 20:50:51 +08:00
fix: remove dependency on job_batches table for batch email sending
This commit is contained in:
@@ -16,7 +16,7 @@ use App\Utils\Helper;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -443,7 +443,7 @@ class UserController extends Controller
|
||||
$sort = $request->input('sort') ? $request->input('sort') : 'created_at';
|
||||
$builder = User::orderBy($sort, $sortType);
|
||||
$this->applyFiltersAndSorts($request, $builder);
|
||||
|
||||
|
||||
$subject = $request->input('subject');
|
||||
$content = $request->input('content');
|
||||
$templateValue = [
|
||||
@@ -451,29 +451,18 @@ class UserController extends Controller
|
||||
'url' => admin_setting('app_url'),
|
||||
'content' => $content
|
||||
];
|
||||
|
||||
|
||||
$chunkSize = 1000;
|
||||
$totalProcessed = 0;
|
||||
|
||||
|
||||
$builder->chunk($chunkSize, function ($users) use ($subject, $templateValue, &$totalProcessed) {
|
||||
$jobs = [];
|
||||
|
||||
foreach ($users as $user) {
|
||||
$jobs[] = new SendEmailJob([
|
||||
dispatch(new SendEmailJob([
|
||||
'email' => $user->email,
|
||||
'subject' => $subject,
|
||||
'template_name' => 'notify',
|
||||
'template_value' => $templateValue
|
||||
], 'send_email_mass');
|
||||
], 'send_email_mass'));
|
||||
}
|
||||
|
||||
if (!empty($jobs)) {
|
||||
Bus::batch($jobs)
|
||||
->allowFailures()
|
||||
->dispatch();
|
||||
}
|
||||
|
||||
$totalProcessed += $users->count();
|
||||
});
|
||||
|
||||
return $this->success(true);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Services\MailService;
|
||||
use Illuminate\Bus\Batchable;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@@ -12,7 +11,7 @@ use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SendEmailJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Batchable;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $params;
|
||||
|
||||
public $tries = 3;
|
||||
@@ -36,7 +35,7 @@ class SendEmailJob implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
$mailLog = MailService::sendEmail($this->params);
|
||||
if($mailLog['error']){
|
||||
if ($mailLog['error']) {
|
||||
$this->release(); //发送失败将触发重试
|
||||
}
|
||||
}
|
||||
|
||||
2
public/assets/admin/assets/index.js
vendored
2
public/assets/admin/assets/index.js
vendored
File diff suppressed because one or more lines are too long
33
public/assets/admin/locales/en-US.js
vendored
33
public/assets/admin/locales/en-US.js
vendored
@@ -2632,13 +2632,36 @@ window.XBOARD_TRANSLATIONS['en-US'] = {
|
||||
}
|
||||
},
|
||||
"actions": {
|
||||
"unbind": "Unbind",
|
||||
"unbindTelegramTitle": "Confirm Unbind Telegram",
|
||||
"unbindTelegramDescription": "This action will unbind the user's Telegram account. The user will need to rebind to receive notifications. Are you sure you want to continue?"
|
||||
"title": "Actions",
|
||||
"send_email": "Send Email",
|
||||
"export_csv": "Export CSV",
|
||||
"traffic_reset_stats": "Traffic Reset Stats",
|
||||
"batch_ban": "Batch Ban",
|
||||
"confirm_ban": {
|
||||
"title": "Confirm Batch Ban",
|
||||
"filtered_description": "This action will ban all users that match your current filters. This action cannot be undone.",
|
||||
"all_description": "This action will ban all users in the system. This action cannot be undone.",
|
||||
"cancel": "Cancel",
|
||||
"confirm": "Confirm Ban",
|
||||
"banning": "Banning..."
|
||||
}
|
||||
},
|
||||
"messages": {
|
||||
"telegramUnbound": "Telegram unbound successfully",
|
||||
"telegramUnbindFailed": "Failed to unbind Telegram"
|
||||
"success": "Success",
|
||||
"error": "Error",
|
||||
"export": {
|
||||
"success": "Export successful",
|
||||
"failed": "Export failed"
|
||||
},
|
||||
"batch_ban": {
|
||||
"success": "Batch ban successful",
|
||||
"failed": "Batch ban failed"
|
||||
},
|
||||
"send_mail": {
|
||||
"success": "Email sent successfully",
|
||||
"failed": "Failed to send email",
|
||||
"required_fields": "Please fill in all required fields"
|
||||
}
|
||||
},
|
||||
"traffic_reset": {
|
||||
"title": "Traffic Reset",
|
||||
|
||||
33
public/assets/admin/locales/zh-CN.js
vendored
33
public/assets/admin/locales/zh-CN.js
vendored
@@ -2598,9 +2598,19 @@ window.XBOARD_TRANSLATIONS['zh-CN'] = {
|
||||
}
|
||||
},
|
||||
"actions": {
|
||||
"unbind": "解绑",
|
||||
"unbindTelegramTitle": "确认解绑Telegram",
|
||||
"unbindTelegramDescription": "此操作将解绑用户的Telegram账号,用户需要重新绑定才能接收通知。确定要继续吗?"
|
||||
"title": "操作",
|
||||
"send_email": "发送邮件",
|
||||
"export_csv": "导出 CSV",
|
||||
"traffic_reset_stats": "流量重置统计",
|
||||
"batch_ban": "批量封禁",
|
||||
"confirm_ban": {
|
||||
"title": "确认批量封禁",
|
||||
"filtered_description": "此操作将封禁所有符合当前筛选条件的用户。此操作无法撤销。",
|
||||
"all_description": "此操作将封禁系统中的所有用户。此操作无法撤销。",
|
||||
"cancel": "取消",
|
||||
"confirm": "确认封禁",
|
||||
"banning": "封禁中..."
|
||||
}
|
||||
},
|
||||
"traffic_reset": {
|
||||
"title": "流量重置",
|
||||
@@ -2714,8 +2724,21 @@ window.XBOARD_TRANSLATIONS['zh-CN'] = {
|
||||
}
|
||||
},
|
||||
"messages": {
|
||||
"telegramUnbound": "Telegram解绑成功",
|
||||
"telegramUnbindFailed": "Telegram解绑失败"
|
||||
"success": "成功",
|
||||
"error": "错误",
|
||||
"export": {
|
||||
"success": "导出成功",
|
||||
"failed": "导出失败"
|
||||
},
|
||||
"batch_ban": {
|
||||
"success": "批量封禁成功",
|
||||
"failed": "批量封禁失败"
|
||||
},
|
||||
"send_mail": {
|
||||
"success": "邮件发送成功",
|
||||
"failed": "邮件发送失败",
|
||||
"required_fields": "请填写所有必填字段"
|
||||
}
|
||||
},
|
||||
"send_mail": {
|
||||
"title": "发送邮件",
|
||||
|
||||
Reference in New Issue
Block a user