FIX_Notification undo
This commit is contained in:
parent
f01751cbcc
commit
150f7ae976
@ -736,13 +736,136 @@ class Notifications extends BaseController
|
|||||||
echo $history_msg."<br>";
|
echo $history_msg."<br>";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
echo ($inx+1).") Staus = ".$status." <br>";
|
echo ($inx+1).") Staus = ".$status." <br>";
|
||||||
$this->logger->error("status is Draft");
|
$this->logger->error("status is Draft");
|
||||||
}
|
}
|
||||||
# EXPIRY NOTIFY TEMPLATE EMAIL Closed
|
# EXPIRY NOTIFY TEMPLATE EMAIL Closed
|
||||||
|
if ($status === 'Approved') {
|
||||||
|
$existingcheck2 = $NotificationModel->checkEmailAlreadyExisting($userMobileNumber,$customerId);
|
||||||
|
$check_existing2 = 0;
|
||||||
|
$check_date2 = "";
|
||||||
|
$check_diff_days2 = "";
|
||||||
|
if(!empty($existingcheck2)){
|
||||||
|
|
||||||
|
foreach ($existingcheck2 as $i2 => $r2) {
|
||||||
|
if($r2['receiving_status'] == 1){
|
||||||
|
$check_existing2 = 1;
|
||||||
|
$check_date2 = $r2['sent_time'];
|
||||||
|
$sentTimestamp2 = strtotime($r2['sent_time']);
|
||||||
|
$provedTimestamp2 = strtotime($providedDate);
|
||||||
|
|
||||||
|
|
||||||
|
$diffInSeconds2 = abs($provedTimestamp2 - $sentTimestamp2);
|
||||||
|
$diffInDays2 = $diffInSeconds2 / (60 * 60 * 24);
|
||||||
|
|
||||||
|
$check_diff_days2 = $diffInDays2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($check_existing2){
|
||||||
|
echo ($inx+1).") whatsapp already send ".$check_date2."<br>";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
# EXPIRY NOTIFY TEMPLATE WHATSAPP
|
||||||
|
$whatsappTemplateName = $NotificationModel->getTempName('EXPIRY NOTIFY TEMPLATE WHATSAPP');
|
||||||
|
// print_r($whatsappTemplateName);die;
|
||||||
|
if ((count($whatsappTemplateName) > 0) && !empty($whatsappTemplateName)) {
|
||||||
|
$campaign_id = 2; // hardcoded because static Template.
|
||||||
|
$history_parents_data = ['campaign_id' => 2,'status' => 0];
|
||||||
|
$history_parent_id = $NotificationModel->save_notification_history_parents($history_parents_data);
|
||||||
|
if (empty($userMobileNumber)) {
|
||||||
|
$history_msg = 'There is no subscriber mobile number';
|
||||||
|
$history_child_updatedata = ['receiving_status'=>0,'result'=>$history_msg];
|
||||||
|
$history_child_where = ['fkid' => $history_parent_id,'id' => (int)$history_child_id];
|
||||||
|
$history_child_statement = $NotificationModel->update_notification_history_child($history_child_updatedata,$history_child_where);
|
||||||
|
$this->logger->error($history_child_statement);
|
||||||
|
|
||||||
|
$history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,$campaign_id);
|
||||||
|
$this->logger->error($history_parent_statement);
|
||||||
|
$this->logger->error($history_msg);
|
||||||
|
echo ($inx+1).") ".$history_msg."<br>";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
# Insertion on History Whatsapp Means Campaign ID 2 Hardcoded
|
||||||
|
$history_parents_data = ['campaign_id' => 2,'status' => 0];
|
||||||
|
$history_parent_id = $NotificationModel->save_notification_history_parents($history_parents_data);
|
||||||
|
|
||||||
|
# Step 7: Prepare whatsapp content based on the template
|
||||||
|
$whatsappContent = $whatsappTemplateName[0]['message'];
|
||||||
|
if (isset($fullName)) {
|
||||||
|
$whatsappContent = str_replace("{USER_NAME}", $fullName, $whatsappContent);
|
||||||
|
}
|
||||||
|
if (isset($schemename)) {
|
||||||
|
$whatsappContent = str_replace("{SCHEME_NAME}", $schemename, $whatsappContent);
|
||||||
|
}
|
||||||
|
if (isset($expirydate)) {
|
||||||
|
$expiryon = $expirydate ? date('d-m-Y', strtotime($expirydate)) : '';
|
||||||
|
$whatsappContent = str_replace("{EXPIRY_DATE}", $expiryon, $whatsappContent);
|
||||||
|
}
|
||||||
|
if (isset($customerId)) {
|
||||||
|
$whatsappContent = str_replace("{RENEWAL_LINK}", base_url() . 'subscription_renewal/' . $customerId, $whatsappContent);
|
||||||
|
}
|
||||||
|
# Step 8: Insertion on History Child for whatsapp
|
||||||
|
$history_child_data = [ 'fkid' => $history_parent_id,
|
||||||
|
'customer_id' => $customerId,
|
||||||
|
'receiving_entity' => $userMobileNumber,
|
||||||
|
'receiving_status' => 0,
|
||||||
|
'message' => strip_tags(ltrim($whatsappContent))];
|
||||||
|
$history_child_id = $NotificationModel->save_notification_history_child($history_child_data);
|
||||||
|
|
||||||
|
|
||||||
|
# Step 8: Send Whatsapp using NotificationHelper
|
||||||
|
$params = (object) Null;
|
||||||
|
$url = SEND_WAAI_URL;
|
||||||
|
$params->number = (int)'91' . $userMobileNumber;
|
||||||
|
$params->type = "text";
|
||||||
|
$params->message = strip_tags(ltrim($whatsappContent));
|
||||||
|
$params->instance_id = $_ENV['WAAI_INSTANCE'];
|
||||||
|
$params->access_token = $_ENV['WAAI_TOKEN'];
|
||||||
|
$this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Request = " . json_encode($params));
|
||||||
|
$this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Request type b4 = " . gettype($params));
|
||||||
|
$whatsapp_result = $notification->sendWhatsAppMessage($url, "POST", $params);
|
||||||
|
$receiving_status = $whatsapp_result['receiving_status'];
|
||||||
|
$history_msg = strtolower(gettype($whatsapp_result)) == "string" ? $whatsapp_result : json_encode($whatsapp_result['reponse']);
|
||||||
|
$history_child_updatedata = ['receiving_status'=>$receiving_status,'result'=>$history_msg];
|
||||||
|
$history_child_where = ['fkid' => $history_parent_id,'id' => (int)$history_child_id];
|
||||||
|
$history_child_statement = $NotificationModel->update_notification_history_child($history_child_updatedata,$history_child_where);
|
||||||
|
$this->logger->error($history_child_statement);
|
||||||
|
|
||||||
|
$history_parent_statement = $NotificationModel->update_notification_history_parent_status(['status' => 1],$history_parent_id,$campaign_id);
|
||||||
|
$this->logger->error($history_parent_statement);
|
||||||
|
$this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Reponse = " . $history_msg);
|
||||||
|
|
||||||
|
if(strtolower(gettype($whatsapp_result)) == "string"){
|
||||||
|
echo ($inx+1).") ".$whatsapp_result."<br>";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$result = json_encode($whatsapp_result['reponse']);
|
||||||
|
$decodedResult = json_decode($result, true);
|
||||||
|
if ($decodedResult && isset($decodedResult['message']['key']['remoteJid'])) {
|
||||||
|
$remoteJid = $decodedResult['message']['key']['remoteJid'];
|
||||||
|
$this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Remote Jid = " . $remoteJid);
|
||||||
|
echo ($inx+1).") Whatsapp sent successfully <br>";
|
||||||
|
} else {
|
||||||
|
// echo "Failed to extract remoteJid";
|
||||||
|
$this->logger->error("EXPIRAY NOTIFY TEMPLATE WHATSAPP Failed to extract remoteJid ");
|
||||||
|
echo ($inx+1).") Failed to send Whatsapp <br>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// $receiving_status = 0;
|
||||||
|
$history_msg = 'There is no Whatsapp template found by the name of EXPIRAY NOTIFY TEMPLATE WHATSAPP ';
|
||||||
|
$this->logger->error($history_msg);
|
||||||
|
echo "There is no Whatsapp template <br>";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
# EXPIRY NOTIFY TEMPLATE WHATSAPP Closed
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$this->logger->error("status is draft");
|
||||||
|
}
|
||||||
# Loop Closed
|
# Loop Closed
|
||||||
echo "Process Completed <br>";
|
echo "Process Completed <br>";
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user