SD-22 contacts
This commit is contained in:
parent
601e79f329
commit
5442f508a6
41
composer.lock
generated
41
composer.lock
generated
@ -481,14 +481,17 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/GeSHi/geshi-1.0.git",
|
||||
"reference": "57e2186cea10332de1e59d03834a0863f981e1a4"
|
||||
"reference": "c71a0d7aa7520aa2abc1b2d10c8fed1301ea8329"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/GeSHi/geshi-1.0/zipball/57e2186cea10332de1e59d03834a0863f981e1a4",
|
||||
"reference": "57e2186cea10332de1e59d03834a0863f981e1a4",
|
||||
"url": "https://api.github.com/repos/GeSHi/geshi-1.0/zipball/c71a0d7aa7520aa2abc1b2d10c8fed1301ea8329",
|
||||
"reference": "c71a0d7aa7520aa2abc1b2d10c8fed1301ea8329",
|
||||
"shasum": ""
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.7"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
@ -510,7 +513,7 @@
|
||||
],
|
||||
"description": "Generic Syntax Highlighter",
|
||||
"homepage": "http://qbnz.com/highlighter/",
|
||||
"time": "2016-10-09T19:25:28+00:00"
|
||||
"time": "2017-03-17T06:35:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
@ -627,16 +630,16 @@
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "1.4.1",
|
||||
"version": "1.4.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "0d6c7ca039329247e4f0f8f8f6506810e8248855"
|
||||
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/0d6c7ca039329247e4f0f8f8f6506810e8248855",
|
||||
"reference": "0d6c7ca039329247e4f0f8f8f6506810e8248855",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
|
||||
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -688,7 +691,7 @@
|
||||
"uri",
|
||||
"url"
|
||||
],
|
||||
"time": "2017-02-27T10:51:17+00:00"
|
||||
"time": "2017-03-20T17:10:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "league/csv",
|
||||
@ -821,16 +824,16 @@
|
||||
},
|
||||
{
|
||||
"name": "mikehaertl/phpwkhtmltopdf",
|
||||
"version": "2.2.0",
|
||||
"version": "2.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mikehaertl/phpwkhtmltopdf.git",
|
||||
"reference": "318aed9ad8d7622c6d00a0fdf3b199e71d48e47e"
|
||||
"reference": "877dd0b13d7006cbaa4a272d62152e07310f4bd3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/mikehaertl/phpwkhtmltopdf/zipball/318aed9ad8d7622c6d00a0fdf3b199e71d48e47e",
|
||||
"reference": "318aed9ad8d7622c6d00a0fdf3b199e71d48e47e",
|
||||
"url": "https://api.github.com/repos/mikehaertl/phpwkhtmltopdf/zipball/877dd0b13d7006cbaa4a272d62152e07310f4bd3",
|
||||
"reference": "877dd0b13d7006cbaa4a272d62152e07310f4bd3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -866,20 +869,20 @@
|
||||
"wkhtmltoimage",
|
||||
"wkhtmltopdf"
|
||||
],
|
||||
"time": "2016-06-02T08:06:45+00:00"
|
||||
"time": "2017-03-16T10:45:28+00:00"
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
"version": "1.22.0",
|
||||
"version": "1.22.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Seldaek/monolog.git",
|
||||
"reference": "bad29cb8d18ab0315e6c477751418a82c850d558"
|
||||
"reference": "1e044bc4b34e91743943479f1be7a1d5eb93add0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/bad29cb8d18ab0315e6c477751418a82c850d558",
|
||||
"reference": "bad29cb8d18ab0315e6c477751418a82c850d558",
|
||||
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/1e044bc4b34e91743943479f1be7a1d5eb93add0",
|
||||
"reference": "1e044bc4b34e91743943479f1be7a1d5eb93add0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -944,7 +947,7 @@
|
||||
"logging",
|
||||
"psr-3"
|
||||
],
|
||||
"time": "2016-11-26T00:15:39+00:00"
|
||||
"time": "2017-03-13T07:08:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-message",
|
||||
|
53
library/Metier/Credit/Contact.php
Normal file
53
library/Metier/Credit/Contact.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
|
||||
class Metier_Credit_Contact extends Scores_Ws_Server
|
||||
{
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
public function __construct($db = null)
|
||||
{
|
||||
// Set Database
|
||||
if ($this->conn === null) {
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
} else {
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
if (Zend_Registry::isRegistered('logger')) {
|
||||
$this->logger = Zend_Registry::get('logger');
|
||||
}
|
||||
}
|
||||
public function saveFirstContact($data){
|
||||
try{
|
||||
$res=$this->conn->insert('sdv1.credit__contact',$data);
|
||||
}catch(Exception $e){
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function getlisteContacts($idUser){
|
||||
$sql='select * from sdv1.credit__contact where idUSer=:idUser;';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $idUser);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$infos=$stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
}else{
|
||||
$infos=array($idUser => 'No message');
|
||||
|
||||
}
|
||||
return $infos;
|
||||
}
|
||||
|
||||
}
|
@ -51,7 +51,6 @@ class Metier_Credit_Decrement extends Scores_Ws_Server
|
||||
'siret' => $siret,
|
||||
'created' => Date('Y-m-d H:i:s'),
|
||||
);
|
||||
$this->logger->info(implode("##",$declog));
|
||||
$res=$this->conn->insert('sdv1.credit__consumption',$declog);
|
||||
switch($this->rateType){
|
||||
case 1:
|
||||
@ -142,7 +141,7 @@ class Metier_Credit_Decrement extends Scores_Ws_Server
|
||||
return $r;
|
||||
}
|
||||
private function getUserallogs($user){
|
||||
$sql = "SELECT SUM(balance) as credit FROM sdv1.credit__balance
|
||||
$sql = "SELECT SUM(balance) as credit, count(*) as nbLig FROM sdv1.credit__balance
|
||||
WHERE idUser = :idUser group by idUser" ;
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $user->id);
|
||||
@ -150,13 +149,17 @@ class Metier_Credit_Decrement extends Scores_Ws_Server
|
||||
if ($stmt->rowCount() == 1) {
|
||||
$ratedLog = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$r=$ratedLog->credit;
|
||||
if($r==0 and $ratedLog->nbLig==0){
|
||||
$this->logFirstCredit(1000,$user);
|
||||
$r=1000;
|
||||
}
|
||||
}else{
|
||||
$r=0;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
private function getLogallusers($idLog,$idClient){
|
||||
$sql = "SELECT SUM(balance) as credit FROM sdv1.credit__balance
|
||||
$sql = "SELECT SUM(balance) as credit, count(*) as nbLines FROM sdv1.credit__balance
|
||||
WHERE idClient = :idClient and idLog= :idLog group by idClient,idLog" ;
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $user->id);
|
||||
@ -169,4 +172,50 @@ class Metier_Credit_Decrement extends Scores_Ws_Server
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
private function logFirstCredit($val,$user){
|
||||
|
||||
if($val>0){
|
||||
$values=array(
|
||||
'idUser' => $user->id,
|
||||
'idCmd' => $user->id.'ww'.time(),
|
||||
'login' => $user->login,
|
||||
'nbCredit' => $val,
|
||||
'amount' =>0,
|
||||
'amount_ht' => 0,
|
||||
'amount_tva' => 0,
|
||||
'currency' => '',
|
||||
'valid' => 1,
|
||||
'date_sent' => Date('Y-m-d H:i:s'),
|
||||
'date_received' => null,
|
||||
'paybox_answer' => null,
|
||||
'transaction' => json_encode(array('level' => 'Offre gratuite nouvel abonne','date' =>Date('Y-m-d H:i:s'), 'user' => $user->id)),
|
||||
'comment' => 'Offre gratuite nouvel abonne'
|
||||
);
|
||||
try{
|
||||
$this->conn->insert('sdv1.credit__paid',$values);
|
||||
}catch(Exception $e){
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
$values=array(
|
||||
'idUser' => $user->id,
|
||||
'login' => $user->login,
|
||||
'idClient' =>$user->idClient,
|
||||
'idLog' => '',
|
||||
'balance' => 1000,
|
||||
'created' => Date('Y-m-d H:i:s'),
|
||||
'updated' => null
|
||||
);
|
||||
try{
|
||||
$this->conn->insert('sdv1.credit__balance',$values);
|
||||
}catch(Exception $e){
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -5,4 +5,6 @@ return array(
|
||||
'MensuelconsoCredit' => 'MensuelconsoCredit',
|
||||
'PayCredit' => 'PayCredit',
|
||||
'UseCredit' => 'UseCredit',
|
||||
'ContactCredit' => 'ContactCredit',
|
||||
'GetcontactsCredit' => 'GetcontactsCredit',
|
||||
);
|
||||
|
@ -42,11 +42,12 @@ class Credit extends Scores_Ws_Server
|
||||
*/
|
||||
public function infoCredit()
|
||||
{
|
||||
$info=new infoCredit();
|
||||
$info=new InfoCredit();
|
||||
$this->authenticate();
|
||||
$this->permission($this->libdroits,__FUNCTION__);
|
||||
$crdt=new Metier_Credit_Information();
|
||||
return $crdt->getHistoUser($this->User,20,50);
|
||||
$info=$crdt->getHistoUser($this->User,20,50);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,89 +169,39 @@ class Credit extends Scores_Ws_Server
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie le droit de consommer une page
|
||||
* @param string idLog
|
||||
* @return CanUse
|
||||
|
||||
public function canUseByCredit($idLog)
|
||||
* Enregistrement des demandes de contact
|
||||
* @param string contactdata
|
||||
* @return ContactCredit
|
||||
*/
|
||||
public function contactCredit($contactdata)
|
||||
{
|
||||
$data=(array)json_decode($contactdata);
|
||||
$this->authenticate();
|
||||
$this->permission($this->libdroits);
|
||||
$ContactCreditResult=new ContactCredit();
|
||||
$ContactCreditResult->contactdata=$contactdata;
|
||||
$crdt=new Metier_Credit_Contact();
|
||||
$ok=$crdt->saveFirstContact($data);
|
||||
if(!$ok){
|
||||
$ContactCreditResult->result=false;
|
||||
}else{
|
||||
$ContactCreditResult->result=true;
|
||||
}
|
||||
return $ContactCreditResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lecture des demandes de contact
|
||||
* @return GetcontactsCredit
|
||||
*/
|
||||
public function getcontactsCredit(){
|
||||
$this->authenticate();
|
||||
$idUser = $this->User->id;
|
||||
$canUseResult=$this->checkCredit($idLog);
|
||||
return $canUseResult;
|
||||
$this->permission($this->libdroits);
|
||||
$GetcontactsCreditResult=new GetcontactsCredit();
|
||||
$crdt=new Metier_Credit_Contact();
|
||||
$GetcontactsCreditResult->result=$crdt->getlisteContacts($idUser);
|
||||
return $GetcontactsCreditResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retire des crédits à un utilisateur
|
||||
* @param $nbCredit
|
||||
* @return bool|multitype
|
||||
|
||||
public function subCredit($nbCredit)
|
||||
{
|
||||
$this->authenticate();
|
||||
$this->permission('subcredit');
|
||||
|
||||
try {
|
||||
$sql = 'INSERT INTO sdv1.credit__consumption(idClient, login, balance, created)
|
||||
VALUES(:idClient, :login, :consumption, :created)';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idClient', $this->User->idClient);
|
||||
$stmt->bindValue('login', $this->User->login);
|
||||
$stmt->bindValue('balance', $nbCredit);
|
||||
$stmt->bindValue('created', date('YmdHis'));
|
||||
$stmt->execute();
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$this->updateCredit($this->User->idClient, $this->User->login, $nbCredit);
|
||||
|
||||
$this->wsLog('subcredit', $this->User->idClient, $nbCredit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifie les crédits à un utilisateur
|
||||
* @param $idClient
|
||||
* @param $login
|
||||
* @param $nbCredit
|
||||
|
||||
public function updateCredit($idClient, $login, $nbCredit)
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT * FROM sdv1.credit__balance c
|
||||
WHERE c.idClient=:idClient";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idClient', $idClient);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$rnvpResult = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$balance = $rnvpResult->balance;
|
||||
|
||||
$balance += $nbCredit;
|
||||
|
||||
$sql = "UPDATE sdv1.credit__balance SET balance=:balance AND updated=:updated;";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('balance', $balance);
|
||||
$stmt->bindValue('updated', date('YmdHis'));
|
||||
$stmt->execute();
|
||||
} else {
|
||||
$sql = 'INSERT INTO sdv1.credit__balance(idClient, login, balance, created, updated)
|
||||
VALUES(:idClient, :login, :balance, :created, :updated)';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idClient', $idClient);
|
||||
$stmt->bindValue('login', $login);
|
||||
$stmt->bindValue('balance', $nbCredit);
|
||||
$stmt->bindValue('created', date('YmdHis'));
|
||||
$stmt->bindValue('updated', date('YmdHis'));
|
||||
$stmt->execute();
|
||||
}
|
||||
} catch(\Doctrine\DBAL\DBALException $e) {
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -81,6 +81,27 @@ class UseCredit
|
||||
* @var string
|
||||
*/
|
||||
public $idLog;
|
||||
|
||||
}
|
||||
|
||||
class ContactCredit
|
||||
{
|
||||
/**
|
||||
* Success or failed
|
||||
* @var boolean
|
||||
*/
|
||||
public $result;
|
||||
/**
|
||||
* Params sent
|
||||
* @var string
|
||||
*/
|
||||
public $contactdata;
|
||||
}
|
||||
|
||||
class GetcontactsCredit
|
||||
{
|
||||
/**
|
||||
* List of contacts
|
||||
* @var array
|
||||
*/
|
||||
public $result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user