You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.4 KiB
91 lines
2.4 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Dictionary\PushMessage\Type;
|
|
use App\Dictionary\WeChat\Official\SubscribeId;
|
|
use App\Dictionary\WeChat\Official\TemplateId;
|
|
use App\Jobs\SendWeChatMessage;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Modules\Official\Structs\Message\CustomMessage;
|
|
use Modules\Official\Structs\Message\SubscribeMessage;
|
|
use Modules\Official\Structs\Message\TemplateData\Common;
|
|
use Modules\Official\Structs\Message\TemplateMessage;
|
|
|
|
class PushWechatMessage extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'relate_order_id',
|
|
'relate_patient_id',
|
|
'type',
|
|
'template_id',
|
|
'scene',
|
|
'content',
|
|
'number',
|
|
'status',
|
|
'sent_at',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'id' => 'integer',
|
|
'relate_order_id' => 'integer',
|
|
'relate_patient_id' => 'integer',
|
|
'number' => 'integer',
|
|
'status' => 'integer',
|
|
'sent_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Relationships Order.
|
|
*/
|
|
public function order(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Order::class, 'relate_order_id');
|
|
}
|
|
|
|
/**
|
|
* Relationships Patient.
|
|
*/
|
|
public function patient(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Patient::class, 'relate_patient_id');
|
|
}
|
|
|
|
/**
|
|
* 插入推送消息队列
|
|
* @param int $relate_order_id
|
|
* @param int $relate_patient_id
|
|
* @param TemplateId|SubscribeId|null $template_id
|
|
* @param TemplateMessage|SubscribeMessage|CustomMessage $message
|
|
* @return mixed
|
|
*/
|
|
public function insertMessageJobs(int $relate_order_id, int $relate_patient_id, TemplateId|SubscribeId|null $template_id, TemplateMessage|SubscribeMessage|CustomMessage $message): mixed
|
|
{
|
|
$data = [
|
|
'relate_order_id' => $relate_order_id,
|
|
'relate_patient_id' => $relate_patient_id,
|
|
'type' => Type::OFFICIAL_TEMPLATE->value,
|
|
'template_id' => $template_id,
|
|
'scene' => '',
|
|
'content' => serialize($message),
|
|
];
|
|
|
|
return $this->create($data);
|
|
}
|
|
}
|
|
|