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.
261 lines
9.8 KiB
261 lines
9.8 KiB
5 days ago
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace App\Utils\Traits;
|
||
|
use App\Dictionary\SendMessage\Type;
|
||
|
use App\Dictionary\WeChat\MiniProgram\SubscribeId;
|
||
|
use App\Jobs\SendWeChatMessageJob;
|
||
|
use App\Models\Order as OrderModel;
|
||
|
use App\Models\RegistrationRecord;
|
||
|
use App\Models\SendMessageJob;
|
||
|
|
||
|
trait SendSubscribeMessage
|
||
|
{
|
||
|
|
||
|
protected static SendMessageJob $message_model;
|
||
|
|
||
|
/**
|
||
|
* 单例获取 SendMessageJob
|
||
|
* @return SendMessageJob
|
||
|
*/
|
||
|
public static function getSendMessageJob(): SendMessageJob
|
||
|
{
|
||
|
if (!self::$message_model) {
|
||
|
self::$message_model = new SendMessageJob();
|
||
|
}
|
||
|
return self::$message_model;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 发送绑定患者订阅消息
|
||
|
* @param string $open_id
|
||
|
* @param int $relate_patient_id
|
||
|
* @param string $patient_name
|
||
|
* @return void
|
||
|
*/
|
||
|
public function sendBindPatientSubscribeMessage(string $open_id, int $relate_patient_id, string $patient_name): void
|
||
|
{
|
||
|
$subscribe_id = SubscribeId::PATIENT_BIND_SUCCESS;
|
||
|
$data = [
|
||
|
'touser' => $open_id,
|
||
|
'template_id' => $subscribe_id->value,
|
||
|
'page' => 'pagesA/card/index',
|
||
|
'data' => [
|
||
|
'thing1' => ['value' => $patient_name],
|
||
|
'time2' => ['value' => date('Y-m-d H:i')],
|
||
|
'thing3' => ['value' => '您已绑定成功,可以进行线上线下就医服务。'],
|
||
|
],
|
||
|
'miniprogram_state' => env('custom.mini_program_message_state')
|
||
|
];
|
||
|
|
||
|
$message = self::getSendMessageJob()->insertMessageJobs(0, $relate_patient_id, Type::SINGLE_SUBSCRIBE, $subscribe_id, $data, '');
|
||
|
|
||
|
SendWeChatMessageJob::dispatch($message);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 发送绑定患者订阅消息
|
||
|
* @param string $open_id
|
||
|
* @param int $relate_patient_id
|
||
|
* @param string $patient_name
|
||
|
* @param string $inpatient_id 住院号
|
||
|
* @param string $patient_id 门诊号
|
||
|
* @return void
|
||
|
*/
|
||
|
public function sendUnbindPatientSubscribeMessage(string $open_id, int $relate_patient_id, string $patient_name, string $inpatient_id, string $patient_id): void
|
||
|
{
|
||
|
$subscribe_id = SubscribeId::PATIENT_UNBIND_SUCCESS;
|
||
|
$data = [
|
||
|
'touser' => $open_id,
|
||
|
'template_id' => $subscribe_id->value,
|
||
|
'page' => '',
|
||
|
'data' => [
|
||
|
'thing1' => ['value' => $patient_name],
|
||
|
'time2' => ['value' => date('Y-m-d H:i')],
|
||
|
'thing3' => ['value' => '您已解除绑定关系,无法使用线上线下就医服务。'],
|
||
|
'character_string5' => ['value' => $inpatient_id],
|
||
|
'character_string6' => ['value' => $patient_id],
|
||
|
],
|
||
|
'miniprogram_state' => env('custom.mini_program_message_state')
|
||
|
];
|
||
|
|
||
|
$message = self::getSendMessageJob()->insertMessageJobs(0, $relate_patient_id, Type::SINGLE_SUBSCRIBE, $subscribe_id, $data);
|
||
|
|
||
|
SendWeChatMessageJob::dispatch($message);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 发送就诊提醒消息
|
||
|
* @param RegistrationRecord $record
|
||
|
* @return void
|
||
|
*/
|
||
|
public function sendAppointmentReminderMessage(RegistrationRecord $record): void
|
||
|
{
|
||
|
$order = &$record->order;
|
||
|
$subscribe_id = SubscribeId::VISIT_REMIND;
|
||
|
$visit_time = $record->visit_date . ' '. $record->begin_time . '~'. $record->end_time;
|
||
|
$data = [
|
||
|
'touser' => $order->open_id,
|
||
|
'template_id' => $subscribe_id->value,
|
||
|
'page' => 'pagesA/register/regRecord',
|
||
|
'data' => [
|
||
|
'name1' => ['value' => $order->patient_name],
|
||
|
'time7' => ['value' => $visit_time],
|
||
|
'thing10' => ['value' => $record->dept_name. '('. $record->doctor_name. ')'],
|
||
|
'thing6' => ['value' => $record->dept_location],
|
||
|
'thing5' => ['value' => '请准时前往医院就诊。'],
|
||
|
],
|
||
|
'miniprogram_state' => env('custom.mini_program_message_state')
|
||
|
];
|
||
|
|
||
|
$message = self::getSendMessageJob()->insertMessageJobs(0, $order->relate_patient_id, Type::SINGLE_SUBSCRIBE, $subscribe_id, $data, '');
|
||
|
|
||
|
SendWeChatMessageJob::dispatch($message);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 发送挂号成功订阅消息
|
||
|
* @param OrderModel $order
|
||
|
* @return void
|
||
|
*/
|
||
|
public function sendRegistrationSuccessMessage(OrderModel $order): void
|
||
|
{
|
||
|
$record = &$order->registrationRecord;
|
||
|
$subscribe_id = SubscribeId::REGISTRATION_SUCCESS;
|
||
|
$visit_time = $record->visit_date . ' '. $record->begin_time . '~'. $record->end_time;
|
||
|
$data = [
|
||
|
'touser' => $order->open_id,
|
||
|
'template_id' => $subscribe_id->value,
|
||
|
'page' => 'pagesA/register/regRecord',
|
||
|
'data' => [
|
||
|
'thing5' => ['value' => $record->dept_name],
|
||
|
'thing17' => ['value' => $record->dept_location],
|
||
|
'character_string15' => ['value' => $visit_time],
|
||
|
'thing19' => ['value' => $record->doctor_name],
|
||
|
'amount13' => ['value' => $order->fee / 100],
|
||
|
],
|
||
|
'miniprogram_state' => env('custom.mini_program_message_state')
|
||
|
];
|
||
|
|
||
|
$message = self::getSendMessageJob()->insertMessageJobs(0, $order->relate_patient_id, Type::SINGLE_SUBSCRIBE, $subscribe_id, $data, '');
|
||
|
|
||
|
SendWeChatMessageJob::dispatch($message);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 发送挂号失败订阅消息
|
||
|
* @param OrderModel $order
|
||
|
* @return void
|
||
|
*/
|
||
|
public function sendRegistrationFailureMessage(OrderModel $order): void
|
||
|
{
|
||
|
$record = &$order->registrationRecord;
|
||
|
$subscribe_id = SubscribeId::REGISTRATION_FAILURE;
|
||
|
$visit_time = $record->visit_date . ' '. $record->begin_time . '~'. $record->end_time;
|
||
|
$data = [
|
||
|
'touser' => $order->open_id,
|
||
|
'template_id' => $subscribe_id->value,
|
||
|
'page' => 'pagesA/register/regRecord',
|
||
|
'data' => [
|
||
|
'thing2' => ['value' => $record->dept_name],
|
||
|
'thing3' => ['value' => $record->doctor_name],
|
||
|
'name1' => ['value' => $order->patient_name],
|
||
|
'time4' => ['value' => $visit_time],
|
||
|
'amount13' => ['value' => $order->fee / 100],
|
||
|
],
|
||
|
'miniprogram_state' => env('custom.mini_program_message_state')
|
||
|
];
|
||
|
|
||
|
$message = self::getSendMessageJob()->insertMessageJobs(0, $order->relate_patient_id, Type::SINGLE_SUBSCRIBE, $subscribe_id, $data, '');
|
||
|
|
||
|
SendWeChatMessageJob::dispatch($message);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 发送取消预约挂号消息
|
||
|
* @param OrderModel $order
|
||
|
* @return void
|
||
|
*/
|
||
|
public function sendRegistrationCancelMessage(OrderModel $order): void
|
||
|
{
|
||
|
$record = &$order->registrationRecord;
|
||
|
$subscribe_id = SubscribeId::REGISTRATION_CANCEL;
|
||
|
$visit_time = $record->visit_date . ' '. $record->begin_time . '~'. $record->end_time;
|
||
|
$data = [
|
||
|
'touser' => $order->open_id,
|
||
|
'template_id' => $subscribe_id->value,
|
||
|
'page' => 'pagesA/register/regRecord',
|
||
|
'data' => [
|
||
|
'thing1' => ['value' => $order->patient_name],
|
||
|
'thing2' => ['value' => $record->dept_name],
|
||
|
'thing3' => ['value' => $record->doctor_name],
|
||
|
'time4' => ['value' => $visit_time],
|
||
|
'thing5' => ['value' => '已成功取消预约,如有需要请重新预约。'],
|
||
|
],
|
||
|
'miniprogram_state' => env('custom.mini_program_message_state')
|
||
|
];
|
||
|
|
||
|
$message = self::getSendMessageJob()->insertMessageJobs(0, $order->relate_patient_id, Type::SINGLE_SUBSCRIBE, $subscribe_id, $data, '');
|
||
|
|
||
|
SendWeChatMessageJob::dispatch($message);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 发送门诊缴费成功消息
|
||
|
* @param OrderModel $order
|
||
|
* @return void
|
||
|
*/
|
||
|
public function sendOutpatientPaymentSuccessMessage(OrderModel $order): void
|
||
|
{
|
||
|
$record = &$order->outpatientPaymentRecord;
|
||
|
$subscribe_id = SubscribeId::OUTPATIENT_PAYMENT_SUCCESS;
|
||
|
$data = [
|
||
|
'touser' => $order->open_id,
|
||
|
'template_id' => $subscribe_id->value,
|
||
|
'page' => 'pagesA/outpatient/outPayList',
|
||
|
'data' => [
|
||
|
'date5' => ['value' => date('Y-m-d')],
|
||
|
'amount6' => ['value' => $order->fee / 100],
|
||
|
'character_string7' => ['value' => $order->order_id],
|
||
|
'character_string14' => ['value' => $order->patient_id],
|
||
|
'thing9' => ['value' => '门诊缴费'],
|
||
|
],
|
||
|
'miniprogram_state' => env('custom.mini_program_message_state')
|
||
|
];
|
||
|
|
||
|
$message = self::getSendMessageJob()->insertMessageJobs(0, $order->relate_patient_id, Type::SINGLE_SUBSCRIBE, $subscribe_id, $data, '');
|
||
|
|
||
|
SendWeChatMessageJob::dispatch($message);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 发送门诊缴费失败消息
|
||
|
* @param OrderModel $order
|
||
|
* @return void
|
||
|
*/
|
||
|
public function sendOutpatientPaymentFailureMessage(OrderModel $order): void
|
||
|
{
|
||
|
$record = &$order->outpatientPaymentRecord;
|
||
|
$subscribe_id = SubscribeId::OUTPATIENT_PAYMENT_FAILURE;
|
||
|
$data = [
|
||
|
'touser' => $order->open_id,
|
||
|
'template_id' => $subscribe_id->value,
|
||
|
'page' => '',
|
||
|
'data' => [
|
||
|
|
||
|
'character_string1' => ['value' => $order->order_id],
|
||
|
'thing2' => ['value' => '门诊缴费'],
|
||
|
'name3' => ['value' => $order->patient_name],
|
||
|
'amount4' => ['value' => $order->fee / 100],
|
||
|
'date6' => ['value' => date('Y-m-d')],
|
||
|
],
|
||
|
'miniprogram_state' => env('custom.mini_program_message_state')
|
||
|
];
|
||
|
|
||
|
$message = self::getSendMessageJob()->insertMessageJobs(0, $order->relate_patient_id, Type::SINGLE_SUBSCRIBE, $subscribe_id, $data, '');
|
||
|
|
||
|
SendWeChatMessageJob::dispatch($message);
|
||
|
}
|
||
|
}
|