充值汇报
This commit is contained in:
parent
ef4a7e9667
commit
c435ee2db9
@ -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 实例发送通知...
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
69
app/Notifications/UserBalanceNotification.php
Normal file
69
app/Notifications/UserBalanceNotification.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
68
app/Observers/BalanceObserve.php
Normal file
68
app/Observers/BalanceObserve.php
Normal 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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
3
resources/views/notifications/user/balance.blade.php
Normal file
3
resources/views/notifications/user/balance.blade.php
Normal file
@ -0,0 +1,3 @@
|
||||
@if ($balance->paid_at !== null)
|
||||
{{ $user->name }} 在 {{ $balance->paid_at->toDateTimeString() }} 充值了 {{ $balance->amount }} 元。
|
||||
@endif
|
Loading…
Reference in New Issue
Block a user