bugs fix livechat

This commit is contained in:
Linksehat Staging Server
2024-06-03 09:07:12 +07:00
parent 6fb7034e2e
commit 6ce4282a3b
7 changed files with 110 additions and 77 deletions

View File

@@ -297,44 +297,11 @@ class DuitkuController extends Controller
// Update start chat
$livechat->start_date = date('Y-m-d H:i:s');
$livechat->save();
// Buat dan simpan data channel ke dalam tabel
$channel = Channel::updateOrCreate([
'name' => $livechat->patient_id .'_' . $request->doctor_id,
],
[
'name' => $livechat->patient_id .'_' . $livechat->doctor_id,
'type' => 'Private',
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id,
]);
// Menggunakan updateOrCreate untuk menambahkan data UserChannel untuk member_id
$userChannelMember = UserChannel::updateOrCreate(
[
'user_id' => $livechat->patient_id,
'channel_id' => $channel->id
],
[
'user_id' => $livechat->patient_id,
'channel_id' => $channel->id
]
);
// Menggunakan updateOrCreate untuk menambahkan data UserChannel untuk doctor_id
$userChannelDoctor = UserChannel::updateOrCreate(
[
'user_id' => $livechat->doctor_id,
'channel_id' => $channel->id
],
[
'user_id' => $livechat->doctor_id,
'channel_id' => $channel->id
]
);
// Send Notification
$doctorId = $livechat->doctor_id;
$userDokter = UserAso::find($doctorId);
$userDokter = UserAso::where('person_id',$doctorId)->first();
$title = 'Payment Succes Livechat';
$patient = User::where('nID', $livechat->patient_id)->first();
$body = 'Payment Succes Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
@@ -343,11 +310,12 @@ class DuitkuController extends Controller
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'channel_id' => (string) $channel->id,
'livechat_id' => (string) $livechat->id,
'type' => 'success-payment'
];
$userDokter->notify(new SendNotification($title, $body, $dataNotif));
$patient->notify(new SendNotification($title, $body, $dataNotif));
// Berikan respons yang sesuai ke klien
return response()->json(['message' => 'Channel created successfully', 'channel' => $channel]);
@@ -362,7 +330,7 @@ class DuitkuController extends Controller
// Send Notification
$doctorId = $livechat->doctor_id;
$userDokter = UserAso::find($doctorId);
$userDokter = UserAso::where('person_id',$doctorId)->first();
$title = 'Payment Failed Livechat';
$patient = User::where('nID', $livechat->patient_id)->first();
$body = 'Payment Failed Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
@@ -371,11 +339,12 @@ class DuitkuController extends Controller
'doctor_id' => $livechat->doctor_id
])->first();
$dataNotif = [
'channel_id' => $channel->id,
'livechat_id' => $livechat->id,
'channel_id' => (string) $channel->id,
'livechat_id' => (string) $livechat->id,
'type' => 'failed-payment'
];
$userDokter->notify(new SendNotification($title, $body, $dataNotif));
$patient->notify(new SendNotification($title, $body, $dataNotif));
return response()->json(['message' => 'User Gagal melakukan pembayaran']);
}