1
0
Fork 0
master
panliang 2023-10-16 14:48:21 +08:00
parent 775d9327c2
commit 8075f3d221
1 changed files with 29 additions and 4 deletions

View File

@ -3,7 +3,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use App\Models\{PatientRecord, UserSocialite}; use App\Models\{PatientRecord, User, UserSocialite};
use Overtrue\LaravelWeChat\EasyWeChat; use Overtrue\LaravelWeChat\EasyWeChat;
use Slowlyo\OwlAdmin\Models\AdminUser; use Slowlyo\OwlAdmin\Models\AdminUser;
use App\Enums\SocialiteType; use App\Enums\SocialiteType;
@ -30,7 +30,7 @@ class PatientRecordNotify extends Command
public function handle() public function handle()
{ {
$now = now(); $now = now();
$list = PatientRecord::with(['patient.user']) $list = PatientRecord::with(['patient', 'user'])
->where('is_notified', 0) ->where('is_notified', 0)
->whereNotNull('notify_user_id') ->whereNotNull('notify_user_id')
->whereNotNull('next_treat_at') ->whereNotNull('next_treat_at')
@ -50,6 +50,10 @@ class PatientRecordNotify extends Command
->where('type', SocialiteType::WxOfficial) ->where('type', SocialiteType::WxOfficial)
->whereIn('user_id', $list->pluck('notify_user_id')) ->whereIn('user_id', $list->pluck('notify_user_id'))
->get(); ->get();
$users = UserSocialite::where('user_type', (new AdminUser)->getMorphClass())
->where('type', SocialiteType::WxOfficial)
->whereIn('user_id', $list->pluck('user_id'))
->get();
foreach ($list as $item) { foreach ($list as $item) {
$adminUser = $adminUsers->firstWhere('user_id', $item->notify_user_id); $adminUser = $adminUsers->firstWhere('user_id', $item->notify_user_id);
if ($adminUser) { if ($adminUser) {
@ -70,8 +74,29 @@ class PatientRecordNotify extends Command
] ]
]); ]);
if ($response->isFailed()) { if ($response->isFailed()) {
logger('病历记录: 通知, 模板消息发送, 失败', $response->toArray(false)); logger('病历记录: 通知医师, 模板消息发送, 失败', $response->toArray(false));
continue; }
}
$user = $users->firstWhere('user_id', $item->user_id);
if ($user) {
$response = $api->postJson('/cgi-bin/message/template/send', [
'touser' => $user->openid,
'template_id' => 'zdkOoIk7bfyzpW9Tuu-pxqh2no-93FCcqstFKLOTfu0',
'url' => url('/client/pages/record/detail?id=' . $item->id),
'data' => [
'thing1' => [
'value' => data_get($item->patient, 'name')
],
'time3' => [
'value' => $item->next_treat_at->format('Y年m月d日 H:i:s')
],
'phone_number6' => [
'value' => data_get($item->patient, 'phone')
]
]
]);
if ($response->isFailed()) {
logger('病历记录: 通知用户, 模板消息发送, 失败', $response->toArray(false));
} }
} }
$item->update(['is_notified' => 1]); $item->update(['is_notified' => 1]);