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

@@ -34,7 +34,8 @@ class ChatController extends Controller
// Buat dan simpan data channel ke dalam tabel
$channel = Channel::updateOrCreate([
'name' => $request->member_id .'_' . $request->doctor_id,
'member_id' => $request->member_id,
'doctor_id' => $request->doctor_id,
],
[
'name' => $request->member_id .'_' . $request->doctor_id,
@@ -91,6 +92,7 @@ class ChatController extends Controller
$arr['avatar'] = $avatarMember;
$arr['name'] = $user->sFirstName .' '.$user->sLastName;
$arr['last_message'] = $lastMessage;
$arr['channel_id'] = $d['id'];
array_push($data, $arr);
}

View File

@@ -67,7 +67,8 @@ class AuthDoctorController extends Controller
$res_data = [
// 'user' => $user,
'token' => $user->createToken('app')->plainTextToken
'token' => $user->createToken('app')->plainTextToken,
'id' => $user->person->id
];
return ApiResponse::apiResponse("Success", $res_data, trans('Message.success'), 200);

View File

@@ -47,6 +47,7 @@ class ChatDoctorController extends Controller
if($chat) {
foreach($chat as $c){
$patient = UserLMS::where('nID',$c->patient_id)->with('detail')->first();
$channel = Channel::where(['doctor_id'=> $c->doctor_id, 'member_id' => $c->patient_id])->first();
if ( $patient->detail) {
$urlAvatarDefault = $patient->detail->nIDJenisKelamin == 1 ? 'https://linksehat.dev/assets/img/users/male-avatar.png' : 'https://linksehat.dev/assets/img/users/female-avatar.png';
$avatarMember = $patient->detail->sImage ?? $urlAvatarDefault;
@@ -56,14 +57,19 @@ class ChatDoctorController extends Controller
$arr['id'] = $c->id;
$arr['patient_id'] = $patient->nID;
$arr['avatar'] = $avatarMember;
$arr['name'] = $patient->sFirstName .' '.$patient->sLastName; ;
$arr['name'] = $patient->sFirstName .' '.$patient->sLastName;
$arr['channel_id'] = $channel->id;
array_push($dataIncomingChat, $arr);
}
}
$dataChannel = Channel::where('doctor_id',$user->person_id)->get()->toArray();
$dataOnGoing = [];
if ($dataChannel){
$chatOngoing = Livechat::where([
'doctor_id'=> $user->person_id,
'status' => 5
])->get()->first();
if ($chatOngoing && $dataChannel){
foreach($dataChannel as $d){
$user = UserLMS::with('detail')->where('nID', $d['member_id'])->first();
$lastMessage = Message::where('channel_id', $d['id'])
@@ -80,6 +86,7 @@ class ChatDoctorController extends Controller
$arr['avatar'] = $avatarMember;
$arr['name'] = $user->sFirstName .' '.$user->sLastName;
$arr['last_message'] = $lastMessage;
$arr['channel_id'] = $d['id'];
array_push($dataOnGoing, $arr);
}
@@ -145,13 +152,16 @@ class ChatDoctorController 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' => 'decline-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
if ($user->nIDUser) { // Jika Dependent yang request
$user = UserLMS::where('nIDUser',$livechat->patient_id)->first();
}
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
@@ -188,13 +198,16 @@ class ChatDoctorController 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' => 'approve-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
if ($user->nIDUser) { // Jika Dependent yang request
$user = UserLMS::where('nIDUser',$livechat->patient_id)->first();
}
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {
@@ -229,14 +242,17 @@ class ChatDoctorController 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' => 'end-chat'
];
$user = UserLMS::where('nID',$livechat->patient_id)->first();
if ($user) {
if ($user->nIDUser) { // Jika Dependent yang request
$user = UserLMS::where('nIDUser',$livechat->patient_id)->first();
}
$user->notify(new SendNotification($title, $body, $dataNotif));
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
} else {

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']);
}

View File

@@ -21,7 +21,7 @@ use Illuminate\Support\Facades\Http;
use Modules\Linksehat\Transformers\Livechat\LivechatResource;
use Illuminate\Support\Facades\Validator;
use App\Http\Controllers\DuitkuController;
use App\Models\UserChannel;
use DB;
use Illuminate\Contracts\Filesystem\Cloud;
use Kreait\Firebase\Messaging\CloudMessage;
@@ -156,7 +156,6 @@ class LivechatController extends Controller
* Status Livechat
* 1=Request, 2=Accept, 3=Decline, 4=Waiting Payment, 5=Success Payment, 6 = End Chat, 7=Payment Failed
*/
$timezone = date_default_timezone_get();
$data['request_date'] = date('Y-m-d H:i:s');
$data['timezone'] = $timezone;
@@ -171,19 +170,55 @@ class LivechatController extends Controller
'image_path' => 'https' // Ganti dengan path yang benar jika ada
];
// Buat dan simpan data channel ke dalam tabel
$channel = Channel::updateOrCreate([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->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
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
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;
$user = UserAso::find($doctorId);
$user = UserAso::where('person_id',$doctorId)->first();
$title = 'New Request Livechat';
$patient = User::where('nID', $livechat->patient_id)->first();
$body = 'Request Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
$channel = Channel::where([
'member_id' => $livechat->patient_id,
'doctor_id' => $livechat->doctor_id
])->first();
// $channel = Channel::where([
// 'member_id' => $livechat->patient_id,
// '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' => 'request-chat'
];