+ Notification when applying for credit

This commit is contained in:
Djery-Tom 2020-10-09 15:10:26 +01:00
parent d4a386341f
commit e487f7518d
5 changed files with 42 additions and 5 deletions

View File

@ -2,6 +2,7 @@
"name": "ilink/backend",
"require": {
"phpmailer/phpmailer": "^6.1",
"twilio/sdk": "^6.4"
"twilio/sdk": "^6.4",
"guzzlehttp/guzzle": "^7.1",
}
}

View File

@ -220,7 +220,8 @@ na.validation_code as validation_code,ag.id as agentId,na.solde AS balance,na.et
*/
public function getAgentWithCodeMembre($code){
$listIdmemberParrain=mysqli_query($this->con,
"SELECT na.id as agentId,na.transactionNumber as transactionNumber,ag.email as email,ag.number_super as nbre_reseau,ag.number_geoBySuper as nbre_sous_reseau,cg.category as category, cg.code_parrain as code_parrain,cg.code_membre as code_membre,cg.id as idCode from agents ag RIGHT JOIN networks_agents na on ag.id=na.agent_id RIGHT JOIN codeGenerer cg ON cg.id=na.codeGenerer_id WHERE cg.code_membre='$code'");
"SELECT na.id as agentId,na.transactionNumber as transactionNumber,ag.email as email, ag.lastname, ag.firstname , cc.currency_code,ag.number_super as nbre_reseau,ag.number_geoBySuper as nbre_sous_reseau,cg.category as category, cg.code_parrain as code_parrain,cg.code_membre as code_membre,cg.id as idCode from agents ag RIGHT JOIN networks_agents na on ag.id=na.agent_id RIGHT JOIN codeGenerer cg ON cg.id=na.codeGenerer_id
INNER JOIN towns t ON ag.town_id = t.id INNER JOIN countries_currencies cc ON cc.id = t.country_id WHERE cg.code_membre='$code'");
if($listIdmemberParrain){
$membre=mysqli_fetch_array($listIdmemberParrain,MYSQLI_ASSOC);
return $membre;
@ -718,8 +719,10 @@ na.id as networkAgentId,
if($agent) {
$idag=$agent['agentId'];
$q = mysqli_query($this->con, "INSERT INTO demandeCredits(network_agent_id,montant,status) VALUES('$idag','$montant','0')");
$id = mysqli_insert_id($this->con);
if ($q) {
return ['success' => 1, "agent" => $agent];
return ['success' => 1, "agent" => $agent, "id" => $id,
"currency_code" => $agent['currency_code'], "agent_name" => $agent['lastname'].' '.$agent['firstname']];
}
}
return false;

View File

@ -589,6 +589,28 @@ class Requester
return $result;
}
/**
* Envoi une notification à un agent
* @param $agent_code
* @param $message
* @param null $data
*/
public function sendPushNotificationToAgent($agent_code, $message, $data = null)
{
$client = new \GuzzleHttp\Client([
'base_uri' => 'localhost:8083',
]);
$headers = [
'Authorization' => 'RfXvPQzQRgwpzQYPnLfWpZzgx4QseHlg',
];
$body = new \stdClass();
$body->agent_code = $agent_code;
$body->message = $message;
$body->data = $data;
$promise = $client->requestAsync('POST', '/onesignal/pushToAgent', ['json' => $body, 'headers' => $headers])->then();
$promise->wait();
}
/**
* Enregistre une demande de credit
* @param string $phone Numero du demandeur
@ -618,6 +640,14 @@ class Requester
$this->messenger->setSubject($subject);
try{
$this->messenger->sendMail();
//Send notification
$data = new \stdClass();
$data->screen = "historyItemDetails";
$data->data = new \stdClass();
$data->data->id = $result['id'];
$this->sendPushNotificationToAgent($codeParrain,
sprintf($this->messageText['NOTIFICATION_CREDIT_DEMAND_TEXT_SUCCESS'],$result['agent_name'],$montant,$result['currency_code']),$data);
}catch (Exception $e){
return json_encode(error_get_last());
}

View File

@ -29,5 +29,7 @@
"MESSAGE_ATTRIBUTE":"Hi, \n \nYour number has just been assigned. \nYour ID:%s\n\nYour validation code:%s \n \nService, \niLinkWorld team.",
"MESSAGE_TREAT":"Your credit application has been processed,please check in the application \n \n Sincerely, The iLinkWorld Team",
"MESSAGE_ACTIVE_ACCOUNT":"Hi %s, \n \nYour %s account has just been created. \nYour ID:%s \n\nYour verification code:%s \n \nService, \niLbinkWorld Team.",
"MESSAGE_SUCCESS_RECOVERY_PASSWORD":"The password has been changed and a message has been sent to you"
"MESSAGE_SUCCESS_RECOVERY_PASSWORD":"The password has been changed and a message has been sent to you",
"NOTIFICATION_CREDIT_DEMAND_TEXT_SUCCESS":"%s sent you a credit request for %s %s."
}

View File

@ -29,5 +29,6 @@
"MESSAGE_ATTRIBUTE":"Salut ,\n\nVotre numero vient d'être attribue.\nVotre identifiant : %s\n\nVotre code de validation : %s\n\nCordialement,\nEquipe iLinkWorld.",
"MESSAGE_TREAT":"Votre demande de crédit vient d'être traité,veuillez consulter dans l'application \n\n Cordialement,L'equipe iLnkWorld.",
"MESSAGE_ACTIVE_ACCOUNT":"Salut %s, \n \nvotre compte %s a été activé. \nvotre ID:%s \n\nvotre code de activation:%s \n \nCordialement, \nEquipe iLinkWorld .",
"MESSAGE_SUCCESS_RECOVERY_PASSWORD": "Le mot de passe a été modifié et un message vous a été envoyé à "
"MESSAGE_SUCCESS_RECOVERY_PASSWORD": "Le mot de passe a été modifié et un message vous a été envoyé à ",
"NOTIFICATION_CREDIT_DEMAND_TEXT_SUCCESS":"%s vous a envoyé une demande de crédit de %s %s."
}