fix admin change password

This commit is contained in:
Tokumeikoi 2020-05-25 15:48:12 +08:00
parent 6e509dab73
commit dab9afca53
3 changed files with 55 additions and 2 deletions

View File

@ -5,6 +5,8 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Http\Requests\User\TicketSave;
use App\Http\Requests\User\TicketWithdraw;
use App\Jobs\SendTelegramJob;
use App\Models\User;
use Illuminate\Http\Request;
use App\Models\Ticket;
use App\Models\TicketMessage;
@ -76,6 +78,7 @@ class TicketController extends Controller
abort(500, '工单创建失败');
}
DB::commit();
$this->sendNotify($ticket, $ticketMessage);
return response([
'data' => true
]);
@ -113,6 +116,7 @@ class TicketController extends Controller
abort(500, '工单回复失败');
}
DB::commit();
$this->sendNotify($ticket, $ticketMessage);
return response([
'data' => true
]);
@ -184,6 +188,12 @@ class TicketController extends Controller
private function sendNotify(Ticket $ticket, TicketMessage $ticketMessage)
{
$users = User::where('is_admin', 1)
->where('telegram_id', '!=', NULL)
->get();
foreach ($users as $user) {
$text = "📮[工单]{$ticket->subject}\r\n\r\n$ticketMessage->message";
SendTelegramJob::dispatch($user->telegram_id, $text);
}
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\Jobs;
use App\Services\TelegramService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SendTelegramJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $telegramId;
protected $text;
public $tries = 3;
public $timeout = 5;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(int $telegramId, string $text)
{
$this->onQueue('send_telegram');
$this->telegramId = $telegramId;
$this->text = $text;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$telegramService = new TelegramService();
$telegramService->sendMessage($this->telegramId, $this->text, 'markdown');
}
}

View File

@ -1,5 +1,5 @@
apps:
- name : 'V2Board'
script : 'php artisan queue:work --queue=send_email'
script : 'php artisan queue:work --queue=send_email,send_telegram'
instances: 4
out_file : './storage/logs/queue/queue.log'