CHANGE_ chat bot : GWM
This commit is contained in:
parent
6f564858ce
commit
2884852102
@ -271,7 +271,8 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) {
|
||||
|
||||
|
||||
|
||||
|
||||
$routes->get("getEmployeePolicy", "EmployeeRestController::getEmployeePolicy");
|
||||
$routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy");
|
||||
$routes->get("getChatResponse", "ChatBotController::getChatResponse");
|
||||
$routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
|
||||
$routes->get("getChatResponse", "ChatBotController::getChatResponse");
|
||||
|
||||
@ -73,31 +73,69 @@ class ChatBotController extends AdminController
|
||||
|
||||
public function getChatResponse()
|
||||
{
|
||||
// try {
|
||||
try {
|
||||
$request_for = $this->request->getGet('request_for');
|
||||
$option = $this->request->getGet('option');
|
||||
$is_option = $this->request->getGet('is_option');
|
||||
$custom_options = $this->request->getGet('custom_options');
|
||||
|
||||
$requestData = $this->ChatBotModel->where('request', $request_for)
|
||||
$responseData = $this->ChatBotModel->where('request', $request_for)
|
||||
->where('is_active', 1 )
|
||||
->first();
|
||||
|
||||
if ($requestData) {
|
||||
|
||||
if ($responseData) {
|
||||
|
||||
|
||||
|
||||
if($option != 0){
|
||||
if(isset($option) && $option != 0){
|
||||
|
||||
$decodedData = json_decode($requestData['options'],true);
|
||||
$decodedData = json_decode($responseData['options'],true);
|
||||
|
||||
$requestFor = $decodedData[$request_for][$option];
|
||||
$requestFor = $decodedData[$option];
|
||||
|
||||
$requestData = $this->ChatBotModel->where('request', $requestFor)
|
||||
$responseData = $this->ChatBotModel->where('request', $requestFor)
|
||||
->where('is_active', 1 )
|
||||
->first();
|
||||
}
|
||||
|
||||
if(isset($custom_options))
|
||||
{
|
||||
|
||||
$result = ['request_for'=>$requestData['request'],'options'=>json_decode($requestData['options'],true)];
|
||||
}
|
||||
|
||||
if(isset($is_option) && $is_option == 0){
|
||||
|
||||
$text = $this->request->getGet('text');
|
||||
$value = $this->request->getGet('value');
|
||||
$Data = $this->ChatBotModel->where('options', $text)->where('is_active', 1 )->first();
|
||||
if($Data){
|
||||
|
||||
if($Data['options'] == 'Please Enter Your Mobile Number To View Your Policies')
|
||||
{
|
||||
$result = $this->getAllPolicyByMobileNumber($value,'text');
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200);
|
||||
}else if($Data['options'] == 'Please Enter Your Mobile Number To Raise Ticket'){
|
||||
$result = $this->getAllPolicyByMobileNumber($value,'options');
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200);
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
$result = $this->sendDefaultMessage();
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$result = [
|
||||
'request_for' => $responseData['request'],
|
||||
'options' => json_decode($responseData['options'], true),
|
||||
'text' => $responseData['is_option'] != 1 ? $responseData['options'] : null,
|
||||
'is_option' => $responseData['is_option']
|
||||
];
|
||||
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200);
|
||||
|
||||
|
||||
@ -107,12 +145,123 @@ class ChatBotController extends AdminController
|
||||
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => 'No Data'],404);
|
||||
}
|
||||
// } catch (\Throwable $th) {
|
||||
// return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
||||
// }
|
||||
} catch (\Throwable $th) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function sendDefaultMessage()
|
||||
{
|
||||
$responseData = $this->ChatBotModel->where('id', 1)->where('is_active', 1 )->first();
|
||||
return [
|
||||
'request_for' => $responseData['request'],
|
||||
'options' => json_decode($responseData['options'], true),
|
||||
'text' => $responseData['is_option'] != 1 ? $responseData['options'] : null,
|
||||
'is_option' => $responseData['is_option']
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getAllPolicyByMobileNumber($mobileNo,$action)
|
||||
{
|
||||
$employee = $this->employeeModel->where('mobile', $mobileNo)->where('is_active', 1 )->first();
|
||||
if($employee){
|
||||
|
||||
$employeeData = $this->employeeModel->where('emp_code', $employee['emp_code'])
|
||||
->where('client_id',$employee['client_id'])
|
||||
->where('client_branch_id',$employee['client_branch_id'])
|
||||
->where('is_active', 1 )->findAll();
|
||||
$whereArrayForId = [];
|
||||
foreach ( $employeeData as $key => $value) { array_push($whereArrayForId, $value['id']); }
|
||||
|
||||
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.* , policies.name as policy_name , policy_type.policy_type as policy_type')
|
||||
->join('policies', 'client_policy.policy_id = policies.id', 'left')
|
||||
->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left')
|
||||
->where('client_policy.client_id', $employee['client_id'] )
|
||||
->where('client_policy.client_branch_id', $employee['client_branch_id'] )
|
||||
->where('client_policy.is_active', 1 )
|
||||
->where('client_policy.policy_status', 1)
|
||||
->orderby('client_policy.id' , 'ASC')
|
||||
->findAll();
|
||||
$options = [];
|
||||
$text = '';
|
||||
if(count($ClientPolicyData) > 0 && count($employeeData) > 0)
|
||||
{
|
||||
|
||||
foreach ($ClientPolicyData as $key => $ClientPolicyValue) {
|
||||
|
||||
$data['policy_name'] = $ClientPolicyValue['policy_name'];
|
||||
$data['policy_type'] = $ClientPolicyValue['policy_type'];
|
||||
$data['policy_no'] = $ClientPolicyValue['policy_no'];
|
||||
|
||||
|
||||
|
||||
$employee_policy = $this->employeePolicyModel->select('employees.*,employee_polices.employee_id , employee_polices.basic_cover_si , employee_polices.premium , employee_polices.gst , employee_polices.tpa_id , employee_polices.rand_string , employee_polices.uhid as uhid')
|
||||
->join('employees', 'employee_polices.employee_id = employees.id', 'left')
|
||||
->whereIn('employee_polices.employee_id',$whereArrayForId)
|
||||
->where('employee_polices.client_policy_id',$ClientPolicyValue['id'])
|
||||
->where('employee_polices.is_active', 1 )->findAll();
|
||||
if(count($employee_policy) > 0)
|
||||
{
|
||||
$policy[$ClientPolicyValue['id']] = $ClientPolicyValue['policy_name']."(".$ClientPolicyValue['policy_type'].")";
|
||||
array_push($options, $policy);
|
||||
$text .= $ClientPolicyValue['policy_name']."(".$ClientPolicyValue['policy_type'].") % ";
|
||||
}else{
|
||||
$text .= "There is no any active policies ";
|
||||
}
|
||||
|
||||
}
|
||||
if($action == 'options'){
|
||||
return [
|
||||
'request_for' => $this->request->getGet('request_for'),
|
||||
'options' => $options[count($options) - 1],
|
||||
'text' => null,
|
||||
'is_option' => "1",
|
||||
'custom_options'=>'create_ticket'
|
||||
];
|
||||
}else{
|
||||
return [
|
||||
'request_for' => $this->request->getGet('request_for'),
|
||||
'options' => null,
|
||||
'text' => $text,
|
||||
'is_option' => "0"
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
return [
|
||||
'request_for' => $this->request->getGet('request_for'),
|
||||
'options' => null,
|
||||
'text' => "Dear ".$employee['name'].", % Policy not yet bound for you.",
|
||||
'is_option' => "0"
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
return [
|
||||
'request_for' => $this->request->getGet('request_for'),
|
||||
'options' => null,
|
||||
'text' => "Invalid Mobile Number",
|
||||
'is_option' => "0"
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -937,6 +937,7 @@ class EmployeeRestController extends AdminController
|
||||
//-------------------------------------
|
||||
public function getAgeRange($terms,$familyFloatesValue)
|
||||
{
|
||||
|
||||
$ageRangeArray = ['self' => ['min' => 18, 'max' => 60] , 'spouse' => ['min' => 18, 'max' => 60] , 'child' => ['min' => 0, 'max' => 25] , 'elders' => ['min' => 18, 'max' => 60] ];
|
||||
|
||||
$ageKey = (preg_replace('/\d/', '', $familyFloatesValue) == 'parent' || preg_replace('/\d/', '', $familyFloatesValue) == 'parent_in_law') ? 'elders' : preg_replace('/\d/', '', $familyFloatesValue);
|
||||
@ -951,7 +952,7 @@ public function getAgeRange($terms,$familyFloatesValue)
|
||||
|
||||
public function getEmployeePolicy()
|
||||
{
|
||||
try {
|
||||
// try {
|
||||
|
||||
$id = $this->request->getGet('id');
|
||||
$emp_code = $this->request->getGet('emp_code');
|
||||
@ -970,7 +971,7 @@ public function getEmployeePolicy()
|
||||
->where('is_active', 1 )
|
||||
->where('is_addon_value',0)->findAll();
|
||||
|
||||
|
||||
|
||||
if ($empPolicy) {
|
||||
|
||||
$result = [];
|
||||
@ -1039,12 +1040,17 @@ public function getEmployeePolicy()
|
||||
$array->floter_text_description = '';
|
||||
}
|
||||
|
||||
// Convert familyFloaters terms data to plain array
|
||||
// remove parent and parent-in-law from familyFloaters
|
||||
if($familyFloates->{'either-parents-pil'} != 0){
|
||||
unset($familyFloates->parents);
|
||||
unset($familyFloates->parents_in_law);
|
||||
}
|
||||
$floters = $this->FloterConvertion($familyFloates);
|
||||
|
||||
$data = [];
|
||||
foreach ($floters as $familyFloatesValue) {
|
||||
$dependent = preg_replace('/\d/', '', $familyFloatesValue);
|
||||
// dd($empData);
|
||||
if(count($empData)){
|
||||
foreach ($empData as $key => $value) {
|
||||
if ($value['family_floater_key'] === $dependent) {
|
||||
@ -1070,8 +1076,8 @@ public function getEmployeePolicy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Remove Unwanted floter key from floters array based on either-parents-pil term value
|
||||
if($familyFloates->{'either-parents-pil'} == 1 && count($floters))
|
||||
@ -1089,7 +1095,21 @@ public function getEmployeePolicy()
|
||||
$floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false);
|
||||
}
|
||||
}
|
||||
|
||||
else if($familyFloates->{'either-parents-pil'} == 2 && count($floters))
|
||||
{
|
||||
$count_parent = 0;
|
||||
$count_parent_in_law = 0;
|
||||
foreach ($floters as $value) {
|
||||
if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; }
|
||||
if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;}
|
||||
}
|
||||
if(($count_parent + $count_parent_in_law) == 2) {
|
||||
$floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false);
|
||||
}
|
||||
|
||||
}
|
||||
dd($floters);
|
||||
|
||||
// Add family floter buttons placement data for FE validation
|
||||
if(count($floters)){
|
||||
foreach ($floters as $familyFloatesValue) {
|
||||
@ -1142,9 +1162,9 @@ public function getEmployeePolicy()
|
||||
}else{
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => []], 200);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
||||
}
|
||||
// } catch (\Exception $e) {
|
||||
// return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@ -1210,6 +1230,13 @@ public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id,$cl
|
||||
$array->floter_text_description = '';
|
||||
}
|
||||
|
||||
|
||||
// remove parent and parent-in-law from familyFloaters
|
||||
if($familyFloates->{'either-parents-pil'} != 0){
|
||||
unset($familyFloates->parents);
|
||||
unset($familyFloates->parents_in_law);
|
||||
}
|
||||
|
||||
// Convert familyFloaters terms data to plain array
|
||||
$floters = $this->FloterConvertion($familyFloates);
|
||||
$data = [];
|
||||
@ -1259,6 +1286,19 @@ public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id,$cl
|
||||
$floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false);
|
||||
}
|
||||
}
|
||||
else if($familyFloates->{'either-parents-pil'} == 2 && count($floters))
|
||||
{
|
||||
$count_parent = 0;
|
||||
$count_parent_in_law = 0;
|
||||
foreach ($floters as $value) {
|
||||
if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; }
|
||||
if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;}
|
||||
}
|
||||
if(($count_parent + $count_parent_in_law) == 2) {
|
||||
$floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Add family floter buttons placement data for FE validation
|
||||
if(count($floters)){
|
||||
@ -1287,8 +1327,9 @@ public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id,$cl
|
||||
public function FloterConvertion($array){
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if ($value > 0) {
|
||||
if ($value > 0 && $key != 'elders_count') {
|
||||
if ($value != 0 && $key === 'childrens') {
|
||||
for ($i = 1; $i <= $value; $i++) {
|
||||
$result[] = "child" . $i;
|
||||
@ -1458,6 +1499,11 @@ public function getAddOnPolicy()
|
||||
|
||||
// Map family floaters that already exist in the employee table
|
||||
$familyFloates = $policy_terms->family_floaters;
|
||||
// remove parent and parent-in-law from familyFloaters
|
||||
if($familyFloates->{'either-parents-pil'} != 0){
|
||||
unset($familyFloates->parents);
|
||||
unset($familyFloates->parents_in_law);
|
||||
}
|
||||
// Convert familyFloaters terms data to plain array
|
||||
$floters = $this->FloterConvertion($familyFloates);
|
||||
|
||||
@ -1532,6 +1578,34 @@ public function getAddOnPolicy()
|
||||
|
||||
|
||||
}
|
||||
else if($familyFloates->{'either-parents-pil'} == 2 && count($floters))
|
||||
{
|
||||
if(count($addOnEmployeeData) == 0)
|
||||
{
|
||||
$GMCEmpData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code'))
|
||||
->where('is_addon_value',0)
|
||||
->where('is_active', 1 )
|
||||
->where('family_floater_key','parent')
|
||||
->findAll();
|
||||
|
||||
if(count($GMCEmpData) > 0){
|
||||
$floters = array_diff($floters, ["parent1","parent2"]);
|
||||
}else{
|
||||
$floters = array_diff($floters, ["parent_in_law1","parent_in_law2"]);
|
||||
}
|
||||
}else{
|
||||
$count_parent = 0;
|
||||
$count_parent_in_law = 0;
|
||||
foreach ($floters as $value) {
|
||||
if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; }
|
||||
if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;}
|
||||
}
|
||||
if(($count_parent + $count_parent_in_law) == 2) {
|
||||
$floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ class ChatBotModel extends Model
|
||||
"id",
|
||||
"request",
|
||||
"options",
|
||||
"is_option",
|
||||
"created_by",
|
||||
"updated_by",
|
||||
"is_active",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user