Avec la librairie de decrement avant implantation dans les process
This commit is contained in:
parent
2ee383d310
commit
ec201b41fa
65
composer.lock
generated
65
composer.lock
generated
@ -285,16 +285,16 @@
|
||||
},
|
||||
{
|
||||
"name": "doctrine/dbal",
|
||||
"version": "v2.5.11",
|
||||
"version": "v2.5.12",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine/dbal.git",
|
||||
"reference": "1b1effbddbdc0f40d1c8f849f44bcddac4f52a48"
|
||||
"reference": "7b9e911f9d8b30d43b96853dab26898c710d8f44"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/doctrine/dbal/zipball/1b1effbddbdc0f40d1c8f849f44bcddac4f52a48",
|
||||
"reference": "1b1effbddbdc0f40d1c8f849f44bcddac4f52a48",
|
||||
"url": "https://api.github.com/repos/doctrine/dbal/zipball/7b9e911f9d8b30d43b96853dab26898c710d8f44",
|
||||
"reference": "7b9e911f9d8b30d43b96853dab26898c710d8f44",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -352,7 +352,7 @@
|
||||
"persistence",
|
||||
"queryobject"
|
||||
],
|
||||
"time": "2017-02-04T21:20:13+00:00"
|
||||
"time": "2017-02-08T12:53:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "doctrine/inflector",
|
||||
@ -510,25 +510,25 @@
|
||||
],
|
||||
"description": "Generic Syntax Highlighter",
|
||||
"homepage": "http://qbnz.com/highlighter/",
|
||||
"time": "2016-10-09 19:25:28"
|
||||
"time": "2016-10-09T19:25:28+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"version": "6.2.2",
|
||||
"version": "6.2.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/guzzle.git",
|
||||
"reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60"
|
||||
"reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/ebf29dee597f02f09f4d5bbecc68230ea9b08f60",
|
||||
"reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/8d6c6cc55186db87b7dc5009827429ba4e9dc006",
|
||||
"reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/promises": "^1.0",
|
||||
"guzzlehttp/psr7": "^1.3.1",
|
||||
"guzzlehttp/psr7": "^1.4",
|
||||
"php": ">=5.5"
|
||||
},
|
||||
"require-dev": {
|
||||
@ -572,7 +572,7 @@
|
||||
"rest",
|
||||
"web service"
|
||||
],
|
||||
"time": "2016-10-08T15:01:37+00:00"
|
||||
"time": "2017-02-28T22:50:30+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/promises",
|
||||
@ -627,16 +627,16 @@
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "1.3.1",
|
||||
"version": "1.4.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b"
|
||||
"reference": "0d6c7ca039329247e4f0f8f8f6506810e8248855"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/5c6447c9df362e8f8093bda8f5d8873fe5c7f65b",
|
||||
"reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/0d6c7ca039329247e4f0f8f8f6506810e8248855",
|
||||
"reference": "0d6c7ca039329247e4f0f8f8f6506810e8248855",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -672,29 +672,36 @@
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Schultze",
|
||||
"homepage": "https://github.com/Tobion"
|
||||
}
|
||||
],
|
||||
"description": "PSR-7 message implementation",
|
||||
"description": "PSR-7 message implementation that also provides common utility methods",
|
||||
"keywords": [
|
||||
"http",
|
||||
"message",
|
||||
"request",
|
||||
"response",
|
||||
"stream",
|
||||
"uri"
|
||||
"uri",
|
||||
"url"
|
||||
],
|
||||
"time": "2016-06-24T23:00:38+00:00"
|
||||
"time": "2017-02-27T10:51:17+00:00"
|
||||
},
|
||||
{
|
||||
"name": "league/csv",
|
||||
"version": "8.2.0",
|
||||
"version": "8.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thephpleague/csv.git",
|
||||
"reference": "ef7eef710810c8bd0cf9371582ccd0123ff96d4b"
|
||||
"reference": "43fd8b022815a0758d85e925dd92a43fe0d41bb4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thephpleague/csv/zipball/ef7eef710810c8bd0cf9371582ccd0123ff96d4b",
|
||||
"reference": "ef7eef710810c8bd0cf9371582ccd0123ff96d4b",
|
||||
"url": "https://api.github.com/repos/thephpleague/csv/zipball/43fd8b022815a0758d85e925dd92a43fe0d41bb4",
|
||||
"reference": "43fd8b022815a0758d85e925dd92a43fe0d41bb4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -738,20 +745,20 @@
|
||||
"read",
|
||||
"write"
|
||||
],
|
||||
"time": "2017-01-25T13:32:07+00:00"
|
||||
"time": "2017-02-23T08:25:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "mikehaertl/php-shellcommand",
|
||||
"version": "1.2.3",
|
||||
"version": "1.2.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mikehaertl/php-shellcommand.git",
|
||||
"reference": "a628505cd99b201375dd6bcd0b062ee07c8ba556"
|
||||
"reference": "b0c0bf3ce49a01bd7ddbe07a9bed4ba85b869fa4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/mikehaertl/php-shellcommand/zipball/a628505cd99b201375dd6bcd0b062ee07c8ba556",
|
||||
"reference": "a628505cd99b201375dd6bcd0b062ee07c8ba556",
|
||||
"url": "https://api.github.com/repos/mikehaertl/php-shellcommand/zipball/b0c0bf3ce49a01bd7ddbe07a9bed4ba85b869fa4",
|
||||
"reference": "b0c0bf3ce49a01bd7ddbe07a9bed4ba85b869fa4",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
@ -774,7 +781,7 @@
|
||||
"keywords": [
|
||||
"shell"
|
||||
],
|
||||
"time": "2017-01-26T08:29:31+00:00"
|
||||
"time": "2017-02-09T18:28:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "mikehaertl/php-tmpfile",
|
||||
|
169
library/Metier/Credit/Decrement.php
Normal file
169
library/Metier/Credit/Decrement.php
Normal file
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
|
||||
class Metier_Credit_Decrement extends Scores_Ws_Server
|
||||
{
|
||||
protected $conn;
|
||||
private $session_period=3600;
|
||||
private $sessionvar=array();
|
||||
|
||||
public function __construct($db = null)
|
||||
{
|
||||
// Set Database
|
||||
if ($conn === null) {
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
} else {
|
||||
$this->conn = $conn;
|
||||
}
|
||||
|
||||
if (Zend_Registry::isRegistered('logger')) {
|
||||
$this->logger = Zend_Registry::get('logger');
|
||||
$this->logger->info('Decrement');
|
||||
}
|
||||
}
|
||||
public function canUse($idLog,$user){
|
||||
$this->getRateType($user,$idLog);
|
||||
$canUseResult=new stdClass();
|
||||
$canUseResult->idLog=$idLog;
|
||||
$canUseResult->result=false;
|
||||
if($this->rateType==0){
|
||||
$canUseResult->result=true;
|
||||
}else{
|
||||
$userCredit=$this->getUserCredit($idLog,$user,$this->rateType);
|
||||
$canUseResult->result=($userCredit>=$this->logCost);
|
||||
}
|
||||
$canUseResult->typecredit=$this->rateType;
|
||||
return $canUseResult;
|
||||
|
||||
}
|
||||
public function setUsed($idLog,$user){
|
||||
if(!isset($this->rateType)){
|
||||
$this->getRateType($user,$idLog);
|
||||
}
|
||||
$declog=array(
|
||||
'idUser' => $user->id,
|
||||
'idLog' => $idLog,
|
||||
'login' => $user->login,
|
||||
'consumption' => $this->logCost,
|
||||
'created' => Date('Y-m-d H:i:s'),
|
||||
);
|
||||
$this->conn->insert('sdv1.credit__consumption',$declog);
|
||||
switch($this->rateType){
|
||||
case 1:
|
||||
$this->setBalance($user,null);
|
||||
break;
|
||||
case 2:
|
||||
$this->setBalance($user,$idLog);
|
||||
break;
|
||||
}
|
||||
//$newbalance=
|
||||
return $this->logCost.'--->'.$this->rateType;
|
||||
}
|
||||
private function setBalance($user, $idLog){
|
||||
$sql='select * from sdv1.credit__balance where idUser= :idUser and idLog=:idLog;';
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $user->id);
|
||||
$stmt->bindValue('idLog', $idLog);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 1) {
|
||||
//@todo:faire une alerte à supportdev - ce n'est pas bloquant mais ça ne devrait pas se produire
|
||||
}
|
||||
if ($stmt->rowCount() >= 1) {
|
||||
$ratedLog = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$data=array(
|
||||
'balance' => $ratedLog['balance']-$this->logCost,
|
||||
'updated' => Date('Y-m-d H:i:s'),
|
||||
);
|
||||
$this->conn->update('sdv1.credit__balance',$data,array('id'=>$ratedlog['id']));
|
||||
}else{
|
||||
$data=array(
|
||||
'idUser' => $user->id,
|
||||
'login' => $user->login,
|
||||
'idClient' => $user->idClient,
|
||||
'idLog' => $idLog,
|
||||
'balance' => 0-$this->logCost,
|
||||
'created' => Date('Y-m-d H:i:s'),
|
||||
);
|
||||
$this->conn->insert('sdv1.credit__balance',$data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function getRateType($user,$idLog){
|
||||
if($this->sessionGetRateType()){
|
||||
return;
|
||||
}
|
||||
$this->rateType=0;
|
||||
$this->logCost=0;
|
||||
// --- Check Credit Authorization and parameters
|
||||
$sql = "SELECT rateType,cost FROM sdv1.credit__rate
|
||||
WHERE IdClient = :clientId AND serviceCode = :serviceCode AND idLog = :idLog" ;
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('clientId', $user->idClient);
|
||||
$stmt->bindValue('serviceCode', $user->serviceCode);
|
||||
$stmt->bindValue('idLog', $idLog);
|
||||
$this->logger->info($user->serviceCode);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() == 1) {
|
||||
$ratedLog = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$this->rateType=$ratedLog->rateType;
|
||||
$this->logCost=$ratedLog->cost;
|
||||
$this->logger->info(__LINE__ . 'getRateType OK');
|
||||
}else{
|
||||
$this->rateType=0;
|
||||
$this->logCost=0;
|
||||
$this->logger->info(__LINE__ . 'getRateType KO');
|
||||
}
|
||||
}
|
||||
private function sessionGetRateType(){
|
||||
//@todo: gestion de l'info en session
|
||||
return false;
|
||||
}
|
||||
private function getUserCredit($idLog,$user,$type){
|
||||
switch($type){
|
||||
case 1:
|
||||
//Systeme type Paybox : Credit par utilisateur pour tous les logs
|
||||
$r=$this->getUserallogs($user);
|
||||
break;
|
||||
case 2:
|
||||
//Systeme type Contrat limité : Credit par log pour tous les utilisateurs d'un client
|
||||
$r=$this->getLogallusers($idLog,$user->idClient);
|
||||
break;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
private function getUserallogs($user){
|
||||
$sql = "SELECT SUM(balance) as credit FROM sdv1.credit__balance
|
||||
WHERE idUser = :idUser group by idUser" ;
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $user->id);
|
||||
$this->logger->info($user->serviceCode);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() == 1) {
|
||||
$ratedLog = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$r=$ratedLog->credit;
|
||||
}else{
|
||||
$r=0;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
private function getLogallusers($idLog,$idClient){
|
||||
$sql = "SELECT SUM(balance) as credit FROM sdv1.credit__balance
|
||||
WHERE idClient = :idClient and idLog= :idLog group by idClient,idLog" ;
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('idUser', $user->id);
|
||||
$this->logger->info($user->serviceCode);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() == 1) {
|
||||
$ratedLog = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$r=$ratedLog->credit;
|
||||
}else{
|
||||
$r=0;
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user