Merge branch 'staging' of https://dev.sismedika.online/febio/aso into staging
This commit is contained in:
@@ -266,6 +266,10 @@ class AuthController extends Controller
|
||||
$token = $request->token;
|
||||
$status = $request->status;
|
||||
|
||||
$user->fcm_token = $request->token;
|
||||
$user->save();
|
||||
// $userUpdate = User::where
|
||||
|
||||
$user->notificationTokens()->updateOrCreate([
|
||||
'device_id' => $device_id,
|
||||
], [
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Modules\Linksehat\Http\Controllers\Api\Doctor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Notifications\SendNotification;
|
||||
use App\Models\User;
|
||||
use App\Models\OLDLMS\User as UserLMS;
|
||||
use App\Models\Livechat;
|
||||
@@ -132,6 +133,34 @@ class ChatDoctorController extends Controller
|
||||
$livechat->status = 3; // Decline
|
||||
// Menyimpan perubahan ke database
|
||||
$livechat->save();
|
||||
|
||||
// Send Notification
|
||||
$doctorId = $livechat->doctor_id;
|
||||
$title = 'Decline Livechat';
|
||||
$body = 'Decline Livechat';
|
||||
$channel = Channel::where([
|
||||
'member_id' => $livechat->patient_id,
|
||||
'doctor_id' => $livechat->doctor_id
|
||||
])->first();
|
||||
$dataNotif = [
|
||||
'channel_id' => $channel->id,
|
||||
'livechat_id' => $livechat->id,
|
||||
'type' => 'decline-chat'
|
||||
];
|
||||
|
||||
$user = UserLMS::where('nID',$livechat->patient_id)->first();
|
||||
if ($user) {
|
||||
$user->notify(new SendNotification($title, $body, $dataNotif));
|
||||
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
|
||||
} else {
|
||||
return Helper::responseJson(
|
||||
status: 'Not Found',
|
||||
statusCode: 404,
|
||||
message: 'Doctor not found.'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
|
||||
} else {
|
||||
return response()->json(['message' => 'Livechat not found'], 404);
|
||||
@@ -147,7 +176,34 @@ class ChatDoctorController extends Controller
|
||||
$livechat->accept_date = date('Y-m-d H:i:s'); // Accept
|
||||
// Menyimpan perubahan ke database
|
||||
$livechat->save();
|
||||
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
|
||||
|
||||
// Send Notification
|
||||
$doctorId = $livechat->doctor_id;
|
||||
$title = 'Approve Request Livechat';
|
||||
$body = 'Approve Livechat';
|
||||
$channel = Channel::where([
|
||||
'member_id' => $livechat->patient_id,
|
||||
'doctor_id' => $livechat->doctor_id
|
||||
])->first();
|
||||
$dataNotif = [
|
||||
'channel_id' => $channel->id,
|
||||
'livechat_id' => $livechat->id,
|
||||
'type' => 'approve-chat'
|
||||
];
|
||||
|
||||
$user = UserLMS::where('nID',$livechat->patient_id)->first();
|
||||
|
||||
if ($user) {
|
||||
$user->notify(new SendNotification($title, $body, $dataNotif));
|
||||
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
|
||||
} else {
|
||||
return Helper::responseJson(
|
||||
status: 'Not Found',
|
||||
statusCode: 404,
|
||||
message: 'Doctor not found.'
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
return response()->json(['message' => 'Livechat not found'], 404);
|
||||
}
|
||||
@@ -159,10 +215,36 @@ class ChatDoctorController extends Controller
|
||||
if ($livechat) {
|
||||
// Memperbarui atribut model
|
||||
$livechat->status = 6; // End Chat
|
||||
$livechat->end_date = date('Y-m-d H:i:s'); // Accept
|
||||
$livechat->end_date = date('Y-m-d H:i:s'); // Endchat
|
||||
// Menyimpan perubahan ke database
|
||||
$livechat->save();
|
||||
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
|
||||
|
||||
// Send Notification
|
||||
$doctorId = $livechat->doctor_id;
|
||||
$title = 'End Livechat';
|
||||
$body = 'End Livechat';
|
||||
$channel = Channel::where([
|
||||
'member_id' => $livechat->patient_id,
|
||||
'doctor_id' => $livechat->doctor_id
|
||||
])->first();
|
||||
$dataNotif = [
|
||||
'channel_id' => $channel->id,
|
||||
'livechat_id' => $livechat->id,
|
||||
'type' => 'end-chat'
|
||||
];
|
||||
|
||||
$user = UserLMS::where('nID',$livechat->patient_id)->first();
|
||||
|
||||
if ($user) {
|
||||
$user->notify(new SendNotification($title, $body, $dataNotif));
|
||||
return ApiResponse::apiResponse("Success",['message' => 'Livechat updated successfully'], trans('Message.success'), 200);
|
||||
} else {
|
||||
return Helper::responseJson(
|
||||
status: 'Not Found',
|
||||
statusCode: 404,
|
||||
message: 'Doctor not found.'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return response()->json(['message' => 'Livechat not found'], 404);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Notifications\SendNotification;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Speciality;
|
||||
use App\Models\Livechat;
|
||||
use App\Models\Channel;
|
||||
use App\Models\UserChannel;
|
||||
use App\Models\User as UserAso;
|
||||
use App\Models\OLDLMS\User;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -285,7 +288,7 @@ class DuitkuController extends Controller
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
if ($notif->resultCode == "00") {
|
||||
if ($notif->resultCode == "00") { // berhasil melakukan pembayaran
|
||||
// Action Success
|
||||
$livechat = Livechat::where('uuid', $notif->merchantOrderId)->first();
|
||||
// Update status pembayaran
|
||||
@@ -329,6 +332,23 @@ class DuitkuController extends Controller
|
||||
]
|
||||
);
|
||||
|
||||
// Send Notification
|
||||
$doctorId = $livechat->doctor_id;
|
||||
$userDokter = UserAso::find($doctorId);
|
||||
$title = 'Payment Succes Livechat';
|
||||
$patient = User::where('nID', $livechat->patient_id)->first();
|
||||
$body = 'Payment Succes Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
|
||||
$channel = Channel::where([
|
||||
'member_id' => $livechat->patient_id,
|
||||
'doctor_id' => $livechat->doctor_id
|
||||
])->first();
|
||||
$dataNotif = [
|
||||
'channel_id' => $channel->id,
|
||||
'livechat_id' => $livechat->id,
|
||||
'type' => 'success-payment'
|
||||
];
|
||||
$userDokter->notify(new SendNotification($title, $body, $dataNotif));
|
||||
|
||||
// Berikan respons yang sesuai ke klien
|
||||
return response()->json(['message' => 'Channel created successfully', 'channel' => $channel]);
|
||||
|
||||
@@ -340,6 +360,22 @@ class DuitkuController extends Controller
|
||||
$livechat->status = 7; // failed payment
|
||||
$livechat->save();
|
||||
|
||||
// Send Notification
|
||||
$doctorId = $livechat->doctor_id;
|
||||
$userDokter = UserAso::find($doctorId);
|
||||
$title = 'Payment Failed Livechat';
|
||||
$patient = User::where('nID', $livechat->patient_id)->first();
|
||||
$body = 'Payment Failed Livechat from ' . $patient->sFirstName . ' ' . $patient->sLastName;
|
||||
$channel = Channel::where([
|
||||
'member_id' => $livechat->patient_id,
|
||||
'doctor_id' => $livechat->doctor_id
|
||||
])->first();
|
||||
$dataNotif = [
|
||||
'channel_id' => $channel->id,
|
||||
'livechat_id' => $livechat->id,
|
||||
'type' => 'failed-payment'
|
||||
];
|
||||
$userDokter->notify(new SendNotification($title, $body, $dataNotif));
|
||||
return response()->json(['message' => 'User Gagal melakukan pembayaran']);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Notifications\SendNotification;
|
||||
use App\Helpers\Helper;
|
||||
use App\Helpers\DuitkuHelper;
|
||||
use App\Services\Duitku;
|
||||
@@ -9,8 +10,10 @@ use App\Models\Organization;
|
||||
use App\Models\PractitionerRole;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\PaymentsMethods;
|
||||
use App\Models\Channel;
|
||||
use App\Models\Livechat;
|
||||
use App\Models\OLDLMS\User;
|
||||
use App\Models\User as UserAso;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -126,18 +129,18 @@ class LivechatController extends Controller
|
||||
'organization_id' => $request->organization_id,
|
||||
'descriptions' => $request->descriptions
|
||||
];
|
||||
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'doctor_id' => 'required',
|
||||
'patient_id' => 'required',
|
||||
'descriptions' => 'required',
|
||||
], [
|
||||
'doctor_id.required' => 'ID Dokter harus diisi',
|
||||
'patient_id.required' => 'ID Dokter harus diisi',
|
||||
'descriptions.required' => 'Description harus diisi',
|
||||
'patient_id.required' => 'ID Pasien harus diisi',
|
||||
'descriptions.required' => 'Deskripsi harus diisi',
|
||||
]);
|
||||
|
||||
if ($validator->fails()){
|
||||
|
||||
if ($validator->fails()) {
|
||||
return Helper::responseJson(
|
||||
status: 'Bad Request',
|
||||
statusCode: 400,
|
||||
@@ -145,29 +148,54 @@ class LivechatController extends Controller
|
||||
);
|
||||
} else {
|
||||
// insert table livechat
|
||||
|
||||
|
||||
/**
|
||||
* Status Livechat
|
||||
* 1=Request, 2=Accept, 3=Decline, 4=Waiting Payment, 5=Success Payment, 6 = End Chat
|
||||
* 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;
|
||||
$data['uuid'] = (string) Str::orderedUuid();
|
||||
$data['status'] = 1;
|
||||
$data['status'] = 1; // Request
|
||||
|
||||
$livechat = Livechat::create($data);
|
||||
$doctor = $livechat->doctor;
|
||||
$data = [
|
||||
$responseData = [
|
||||
'id' => $livechat->id,
|
||||
'request_date' => $livechat->request_date,
|
||||
'image_path' =>'https'
|
||||
'image_path' => 'https' // Ganti dengan path yang benar jika ada
|
||||
];
|
||||
|
||||
// Send Notification
|
||||
$doctorId = $livechat->doctor_id;
|
||||
$user = UserAso::find($doctorId);
|
||||
$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();
|
||||
$dataNotif = [
|
||||
'channel_id' => $channel->id,
|
||||
'livechat_id' => $livechat->id,
|
||||
'type' => 'request-chat'
|
||||
];
|
||||
|
||||
|
||||
return Helper::responseJson(data: $data);
|
||||
if ($user) {
|
||||
$user->notify(new SendNotification($title, $body, $dataNotif));
|
||||
return Helper::responseJson(data: $responseData);
|
||||
} else {
|
||||
return Helper::responseJson(
|
||||
status: 'Not Found',
|
||||
statusCode: 404,
|
||||
message: 'Doctor not found.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function consultation_request_show($id){
|
||||
$livechat = Livechat::where('id', $id)->with(['doctor', 'practitioner'])->first();
|
||||
@@ -290,7 +318,6 @@ class LivechatController extends Controller
|
||||
// Membuat invoice menggunakan DuitkuHelper
|
||||
$duitku = DuitkuHelper::createInvoice($data);
|
||||
|
||||
|
||||
return response()->json(['success' => true, 'data' => $duitku], 200);
|
||||
} catch (Exception $e) {
|
||||
// Menangkap error dan mengembalikan respon error
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
namespace App\Models\OLDLMS;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -9,11 +9,14 @@ class NotificationToken extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $connection = 'oldlms';
|
||||
|
||||
protected $fillable = [
|
||||
'origin',
|
||||
'type',
|
||||
'token',
|
||||
'status',
|
||||
'device_id'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\OLDLMS;
|
||||
|
||||
use App\Models\NotificationToken;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
@@ -16,7 +14,7 @@ use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, SoftDeletes, HasApiTokens, HasRoles, Notifiable, Notifiable;
|
||||
use HasFactory, SoftDeletes, HasApiTokens, HasRoles, Notifiable;
|
||||
|
||||
const CREATED_AT = 'dCreateOn';
|
||||
const UPDATED_AT = 'dUpdateOn';
|
||||
@@ -40,6 +38,7 @@ class User extends Authenticatable
|
||||
'nIDHubunganKeluarga',
|
||||
'dUpdateOn',
|
||||
'sIPAddress',
|
||||
'fcm_token',
|
||||
];
|
||||
|
||||
protected function fullName(): Attribute
|
||||
@@ -73,4 +72,6 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->morphMany(NotificationToken::class, 'notifiabletoken');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
39
app/Notifications/SendNotification.php
Normal file
39
app/Notifications/SendNotification.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Fcm\FcmChannel;
|
||||
use NotificationChannels\Fcm\FcmMessage;
|
||||
|
||||
class SendNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
private $title;
|
||||
private $body;
|
||||
private $data;
|
||||
|
||||
public function __construct($title, $body, $data)
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->body = $body;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function via($notifiable)
|
||||
{
|
||||
return [FcmChannel::class];
|
||||
}
|
||||
|
||||
public function toFcm($notifiable)
|
||||
{
|
||||
return FcmMessage::create()
|
||||
->setData($this->data) // Menggunakan $this->data
|
||||
->setNotification([
|
||||
'title' => $this->title,
|
||||
'body' => $this->body,
|
||||
]);
|
||||
}
|
||||
}
|
||||
5
config/fcm.php
Normal file
5
config/fcm.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'server_key' => env('FCM_SERVER_KEY'),
|
||||
];
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->string('fcm_token')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('fcm_token');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user