充值汇报

This commit is contained in:
iVampireSP.com 2022-10-31 19:26:30 +08:00
parent ef4a7e9667
commit c435ee2db9
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
7 changed files with 156 additions and 44 deletions

View File

@ -1,33 +0,0 @@
<?php
namespace App\Broadcasting;
use App\Models\User;
use Illuminate\Notifications\Notification;
class WeComRobotChannel
{
/**
* Create a new channel instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* 发送给定的通知。
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return void
*/
public function send($notifiable, Notification $notification)
{
// $message = $notification->toVoice($notifiable);
// 向 $notifiable 实例发送通知...
}
}

View File

@ -42,11 +42,11 @@ public function store(Request $request)
'payment' => 'alipay',
];
// // if local
// if (env('APP_ENV') == 'local') {
// $data['payment'] = null;
// $data['paid_at'] = now();
// }
// if local
if (env('APP_ENV') == 'local') {
$data['payment'] = null;
$data['paid_at'] = now();
}
$balance = $balance->create($data);

View File

@ -0,0 +1,69 @@
<?php
namespace App\Notifications;
use App\Models\User\Balance;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Http;
use App\Broadcasting\WeComRobotChannel;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
class UserBalanceNotification 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 array
*/
public function via($notifiable)
{
return [WeComRobotChannel::class];
}
public function toGroup($notifiable)
{
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);
}
}
}
}
}

View File

@ -33,7 +33,7 @@ public function __construct()
*/
public function via($notifiable)
{
return [WeComRobotChannel::class];
return [];
}
public function toGroup($notifiable)
@ -78,7 +78,7 @@ public function toGroup($notifiable)
$module->makeHidden(['wecom_key']);
$body = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' . $wecom_key, [
$resp = Http::post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' . $wecom_key, [
'msgtype' => 'markdown',
'markdown' => [
'content' => view($view, [
@ -90,9 +90,13 @@ public function toGroup($notifiable)
],
]);
Log::info('企业微信机器人发送消息', [
'body' => $body->body(),
'status' => $body->status(),
]);
if (!$resp->successful()) {
Log::error('企业微信机器人发送失败', [
'resp' => $resp->json(),
'workOrder' => $workOrder,
'reply' => $reply,
'module' => $module,
]);
}
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace App\Observers;
use App\Models\User\Balance;
use App\Notifications\UserBalanceNotification;
class BalanceObserve
{
/**
* Handle the Balance "created" event.
*
* @param \App\Models\User\Balance $balance
* @return void
*/
public function created(Balance $balance)
{
//
return (new UserBalanceNotification())
->toGroup($balance);
}
/**
* Handle the Balance "updated" event.
*
* @param \App\Models\User\Balance $balance
* @return void
*/
public function updated(Balance $balance)
{
//
return (new UserBalanceNotification())
->toGroup($balance);
}
/**
* Handle the Balance "deleted" event.
*
* @param \App\Models\User\Balance $balance
* @return void
*/
public function deleted(Balance $balance)
{
//
}
/**
* Handle the Balance "restored" event.
*
* @param \App\Models\User\Balance $balance
* @return void
*/
public function restored(Balance $balance)
{
//
}
/**
* Handle the Balance "force deleted" event.
*
* @param \App\Models\User\Balance $balance
* @return void
*/
public function forceDeleted(Balance $balance)
{
//
}
}

View File

@ -32,5 +32,6 @@ public function boot() {
\App\Models\WorkOrder\WorkOrder::observe(\App\Observers\WorkOrder\WorkOrderObserver::class);
\App\Models\WorkOrder\Reply::observe(\App\Observers\WorkOrder\ReplyObserver::class);
\App\Models\User\Balance::observe(\App\Observers\BalanceObserve::class);
}
}

View File

@ -0,0 +1,3 @@
@if ($balance->paid_at !== null)
{{ $user->name }} {{ $balance->paid_at->toDateTimeString() }} 充值了 {{ $balance->amount }} 元。
@endif