Modukle achat operationnel

This commit is contained in:
Claire DELBOS 2017-02-28 16:50:00 +01:00
parent e7551303b8
commit d9e9c1d92d

View File

@ -81,9 +81,17 @@ class Credit extends Scores_Ws_Server
{
$PayCreditResult=new PayCredit();
$this->authenticate();
$ir=(array)json_decode($ligneCredit);
$tab=explode('ww',$ir['idCmd']);
$verifid=$tab[0];
$idUser = $this->User->id;
if($idUser!=$verifid){
$PayCreditResult->message='Bad data format';
$PayCreditResult->result=false;
return $PayCreditResult;
}
$PayCreditResult->ligneCredit=$ligneCredit;
$PayCreditResult->message='';
$ir=(array)json_decode($ligneCredit);
if(empty($ir) || !isset($ir['idCmd'])){
$PayCreditResult->message='Bad data format';
$PayCreditResult->result=false;
@ -95,12 +103,52 @@ class Credit extends Scores_Ws_Server
$stmt->bindValue('idCmd', $ir['idCmd']);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$r = $this->conn->update('sdv1.credit__paid', $ir,'idCmd='.$ir['idCmd=']);
$row=$stmt->fetch(\PDO::FETCH_ASSOC);
$transaction=(array)json_decode($row['transaction']);
$transaction[]=(array)json_decode($ir['transaction']);
$ir['transaction']=json_encode($transaction);
$r = $this->conn->update('sdv1.credit__paid', $ir,array('idCmd' => $ir['idCmd']));
}else{
$r = $this->conn->insert('sdv1.credit__paid', $ir);
}
if($ir['valid']==1){
$sql = "SELECT nbCredit FROM sdv1.credit__paid c
WHERE c.idCmd=:idCmd";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('idCmd', $ir['idCmd']);
$stmt->execute();
$payrow=$stmt->fetch(\PDO::FETCH_ASSOC);
$sql = "SELECT balance FROM sdv1.credit__balance c
WHERE c.idUser=:idUser";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('idUser', $idUser);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$brow=$stmt->fetch(\PDO::FETCH_ASSOC);
$balance=$brow['balance']+$payrow['nbCredit'];
$data=array(
'idUser' => $idUser,
'login' => $this->User->login,
'balance' => $balance,
'updated' => Date('Y-m-d H:i:s')
);
$r = $this->conn->update('sdv1.credit__balance', $data,array('idUser' => $idUser));
}else{
$balance=$payrow['nbCredit'];
$data=array(
'idUser' => $idUser,
'login' => $this->User->identity->username,
'balance' => $balance,
'created' => Date('Y-m-d H:i:s')
);
$r = $this->conn->insert('sdv1.credit__balance', $ir);
}
}
$PayCreditResult->result=true;
$this->wsLog('payCredit', $idUser);
$this->wsLog('payCredit', $ir['idCmd']);
return $PayCreditResult;
}