修复 用户充值提醒
This commit is contained in:
parent
0e8972329f
commit
d4bee87389
@ -59,6 +59,7 @@ public function store(Request $request): RedirectResponse
|
||||
$module->api_token = $api_token;
|
||||
$module->url = $request->input('url');
|
||||
$module->status = $request->input('status');
|
||||
$module->wecom_key = $request->input('wecom_key');
|
||||
|
||||
$module->save();
|
||||
|
||||
@ -73,6 +74,7 @@ private function rules(): array
|
||||
'name' => 'required|string|max:255',
|
||||
'url' => 'required|url',
|
||||
'status' => 'required|string|in:up,down,maintenance',
|
||||
'wecom_key' => 'required|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
@ -101,8 +103,6 @@ public function show(Module $module): View
|
||||
*/
|
||||
public function edit(Module $module): View
|
||||
{
|
||||
//
|
||||
|
||||
return view('admin.modules.edit', compact('module'));
|
||||
}
|
||||
|
||||
@ -126,6 +126,7 @@ public function update(Request $request, Module $module): RedirectResponse
|
||||
$module->name = $request->input('name');
|
||||
$module->url = $request->input('url');
|
||||
$module->status = $request->input('status');
|
||||
$module->wecom_key = $request->input('wecom_key');
|
||||
|
||||
$module->save();
|
||||
|
||||
|
@ -2,14 +2,16 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Notifications\UserCharged;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo as BelongsToAlias;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use function auth;
|
||||
|
||||
class Balance extends Model
|
||||
{
|
||||
use Cachable;
|
||||
use Cachable, Notifiable;
|
||||
|
||||
protected $fillable = [
|
||||
'order_id',
|
||||
@ -35,6 +37,14 @@ protected static function boot()
|
||||
|
||||
$balance->order_id = date('YmdHis') . $balance->id . rand(1000, 9999);
|
||||
});
|
||||
|
||||
static::updated(function ($balance) {
|
||||
if ($balance->isDirty('paid_at')) {
|
||||
if ($balance->paid_at) {
|
||||
$balance->notify(new UserCharged());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function user(): BelongsToAlias
|
||||
|
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Balance;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UserBalance extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
// public function via($notifiable)
|
||||
// {
|
||||
// // return [WeComRobotChannel::class];
|
||||
// }
|
||||
|
||||
public function toGroup(mixed $notifiable): void
|
||||
{
|
||||
if ($notifiable instanceof Balance) {
|
||||
|
||||
if ($notifiable->paid_at !== null) {
|
||||
$view = 'notifications.user.balance';
|
||||
$notifiable->load('user');
|
||||
$user = $notifiable->user;
|
||||
|
||||
|
||||
$wecom_key = config('settings.wecom.robot_hook.billing');
|
||||
|
||||
|
||||
$data = [
|
||||
'balance' => $notifiable,
|
||||
'user' => $user,
|
||||
];
|
||||
|
||||
$resp = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' . $wecom_key, [
|
||||
'msgtype' => 'markdown',
|
||||
'markdown' => [
|
||||
'content' => view($view, $data)->render(),
|
||||
],
|
||||
]);
|
||||
|
||||
if (!$resp->successful()) {
|
||||
Log::error('企业微信机器人发送失败', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
54
app/Notifications/UserCharged.php
Normal file
54
app/Notifications/UserCharged.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Balance;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class UserCharged extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param Balance $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function via(Balance $notifiable): array
|
||||
{
|
||||
return [WeComChannel::class];
|
||||
}
|
||||
|
||||
public function toWeCom(Balance $notifiable): array
|
||||
{
|
||||
$notifiable->load('user');
|
||||
|
||||
$user = $notifiable->user;
|
||||
|
||||
$wecom_key = config('settings.wecom.robot_hook.billing');
|
||||
|
||||
return [
|
||||
'key' => $wecom_key,
|
||||
'view' => 'notifications.charge_success',
|
||||
'data' => [
|
||||
'user' => $user,
|
||||
'balance' => $notifiable,
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
}
|
@ -23,6 +23,11 @@
|
||||
<input type="text" class="form-control" id="url" name="url">
|
||||
</div>
|
||||
|
||||
<div class="form-group mt-1">
|
||||
<label for="name">企业微信 群机器人 WebHook Key</label>
|
||||
<input type="text" class="form-control" id="wecom_key" name="wecom_key">
|
||||
</div>
|
||||
|
||||
<!-- 选择状态 -->
|
||||
<div class="form-group mt-1">
|
||||
<label for="status">状态</label>
|
||||
@ -36,4 +41,4 @@
|
||||
<button type="submit" class="btn btn-primary mt-3">提交</button>
|
||||
</form>
|
||||
|
||||
@endsection
|
||||
@endsection
|
||||
|
@ -26,6 +26,11 @@
|
||||
<input type="text" class="form-control" id="url" name="url" value="{{ $module->url }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mt-1">
|
||||
<label for="name">企业微信 群机器人 WebHook Key</label>
|
||||
<input type="text" class="form-control" id="wecom_key" name="wecom_key">
|
||||
</div>
|
||||
|
||||
<div class="form-group mt-1">
|
||||
<label for="status">状态</label>
|
||||
<select class="form-control" id="status" name="status">
|
||||
|
3
resources/views/notifications/charge_success.blade.php
Normal file
3
resources/views/notifications/charge_success.blade.php
Normal file
@ -0,0 +1,3 @@
|
||||
@if ($data['balance']->paid_at !== null)
|
||||
{{ $data['user']->name }} 在 {{ $data['balance']->paid_at->toDateTimeString() }} 通过 <x-payment :payment="$data['balance']->payment" /> 充值了 {{ $data['balance']->amount }} 元。
|
||||
@endif
|
@ -1,3 +0,0 @@
|
||||
@if ($balance->paid_at !== null)
|
||||
{{ $user->name }} 在 {{ $balance->paid_at->toDateTimeString() }} 通过 {{ $balance->payment }} 充值了 {{ $balance->amount }} 元。
|
||||
@endif
|
Loading…
Reference in New Issue
Block a user