Ws operationnel avec Extranet

This commit is contained in:
Claire DELBOS 2017-02-27 18:05:29 +01:00
parent 9a09028b4a
commit fc52e79c7d
4 changed files with 81 additions and 13 deletions

View File

@ -1,7 +1,8 @@
<?php
return array(
'Credit' => 'Credit',
'addCredit' => 'AddCredit',
'subCredit' => 'SubCredit',
'updateCredit' => 'UpdateCredit',
'infoCredit' => 'InfoCredit',
// 'addCredit' => 'AddCredit',
// 'subCredit' => 'SubCredit',
// 'updateCredit' => 'UpdateCredit',
);

View File

@ -11,15 +11,15 @@ class Credit extends Scores_Ws_Server
public function getCredit()
{
$this->authenticate();
$this->permission('credit');
//$this->permission('credit');
$idClient = $this->User->idClient;
$idUser = $this->User->id;
try {
$sql = "SELECT * FROM sdv1.credit__balance c
WHERE c.idClient=:idClient";
WHERE c.idUser=:idUser";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('idClient', $idClient);
$stmt->bindValue('idUser', $idUser);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$rnvpResult = $stmt->fetch(\PDO::FETCH_OBJ);
@ -31,14 +31,50 @@ class Credit extends Scores_Ws_Server
}
}
$this->wsLog('credit', $idClient);
$this->wsLog('credit', $idUser);
return $credit;
}
/**
* Retourne la totalite des infos de crédit à un utilisateur
* @return infoCredit
*/
public function infoCredit()
{
$info=new infoCredit();
$this->authenticate();
//$this->permission('credit');
$idUser = $this->User->id;
$sql = "SELECT * FROM sdv1.credit__balance c
WHERE c.idUser=:idUser";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('idUser', $idUser);
$stmt->execute();
$res=$stmt->fetch(\PDO::FETCH_ASSOC);
$info->balance=$res;
$sql = "SELECT * FROM sdv1.credit__paid c
WHERE c.idUser=:idUser limit 100";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('idUser', $idUser);
$stmt->execute();
$info->paid=$stmt->fetchAll(\PDO::FETCH_ASSOC);
$sql = "SELECT * FROM sdv1.credit__consumption c
WHERE c.idUser=:idUser limit 100";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('idUser', $idUser);
$stmt->execute();
$info->used=$stmt->fetchAll(\PDO::FETCH_ASSOC);
$this->wsLog('infoCredit', $idUser);
return $info;
}
/**
* Ajoute des crédits supplémentaires à un utilisateur
* @param $nbCredit
*/
public function addCredit($nbCredit)
{
$this->authenticate();
@ -53,14 +89,14 @@ class Credit extends Scores_Ws_Server
* 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)
$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);
@ -83,7 +119,7 @@ class Credit extends Scores_Ws_Server
* @param $idClient
* @param $login
* @param $nbCredit
*/
public function updateCredit($idClient, $login, $nbCredit)
{
try {
@ -104,7 +140,7 @@ class Credit extends Scores_Ws_Server
$stmt->bindValue('updated', date('YmdHis'));
$stmt->execute();
} else {
$sql = 'INSERT INTO sdv1.credit__balance(idClient, login, balance, created, updated)
$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);
@ -120,4 +156,5 @@ class Credit extends Scores_Ws_Server
}
}
}
*/
}

View File

@ -3,7 +3,36 @@ class GetCredit
{
}
class infoCredit{
/**
* Etat actuel du compte
* @var array
*/
public $balance;
/**
* 100 derniers Mouvements en entree du compte
* @var array
*/
public $paid;
/**
* 100 derniers Mouvements en sortie du compte
* @var array
*/
public $used;
}
class balance{
/**
* Date de creation
* @var date
*/
public $created;
/**
* Balance des credits
* @var int
*/
public $balance;
}
class AddCredit
{

View File

@ -19,6 +19,7 @@ return array(
'versions' => array(
'0.1' => array( 'actif' => true, 'defaut' => 'beta' ),
),
'idClient' => array(1,195),
),
'entreprise' => array(
'actif' => true,