增加 WorkOrder WeCom 通知
This commit is contained in:
parent
88af12e386
commit
3b73ee2efe
@ -7,6 +7,7 @@
|
|||||||
use App\Models\Host;
|
use App\Models\Host;
|
||||||
use App\Models\Module;
|
use App\Models\Module;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Notifications\WorkOrder as WorkOrderNotification;
|
||||||
use Eloquent;
|
use Eloquent;
|
||||||
use GeneaLabs\LaravelModelCaching\CachedBuilder;
|
use GeneaLabs\LaravelModelCaching\CachedBuilder;
|
||||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||||
@ -14,6 +15,7 @@
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
@ -71,7 +73,7 @@
|
|||||||
*/
|
*/
|
||||||
class WorkOrder extends Model
|
class WorkOrder extends Model
|
||||||
{
|
{
|
||||||
use Cachable;
|
use Cachable, Notifiable;
|
||||||
|
|
||||||
protected $table = 'work_orders';
|
protected $table = 'work_orders';
|
||||||
|
|
||||||
@ -130,8 +132,10 @@ protected static function boot()
|
|||||||
});
|
});
|
||||||
|
|
||||||
// updated
|
// updated
|
||||||
static::updated(function ($model) {
|
static::updated(function (self $model) {
|
||||||
dispatch(new WorkOrderJob($model, 'put'));
|
dispatch(new WorkOrderJob($model, 'put'));
|
||||||
|
|
||||||
|
$model->notify(new WorkOrderNotification($model));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
92
app/Notifications/WorkOrder.php
Normal file
92
app/Notifications/WorkOrder.php
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications;
|
||||||
|
|
||||||
|
use App\Models\WorkOrder\WorkOrder as WorkOrderModel;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
|
class WorkOrder extends Notification
|
||||||
|
{
|
||||||
|
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(mixed $notifiable): array
|
||||||
|
{
|
||||||
|
return [WeComChannel::class];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mail representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
|
* @return MailMessage
|
||||||
|
*/
|
||||||
|
public function toMail(mixed $notifiable): MailMessage
|
||||||
|
{
|
||||||
|
return (new MailMessage)
|
||||||
|
->line('The introduction to the notification.')
|
||||||
|
->action('Notification Action', url('/'))
|
||||||
|
->line('Thank you for using our application!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the array representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray(mixed $notifiable): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toWeCom(WorkOrderModel $workOrder): false|array
|
||||||
|
{
|
||||||
|
|
||||||
|
$workOrder->load(['module', 'user']);
|
||||||
|
|
||||||
|
$module = $workOrder->module;
|
||||||
|
|
||||||
|
if ($workOrder->notify === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消隐藏字段
|
||||||
|
$module->makeVisible(['wecom_key']);
|
||||||
|
|
||||||
|
if ($module->wecom_key == null) {
|
||||||
|
$wecom_key = config('settings.wecom.robot_hook.default');
|
||||||
|
} else {
|
||||||
|
$wecom_key = $module->wecom_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'key' => $wecom_key,
|
||||||
|
'view' => 'notifications.work_order',
|
||||||
|
'data' => $workOrder
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user