Esempio n. 1
0
 /**
  * Acheter ou sélectionner un objet.
  * 
  * @param int $obj_id
  * @param int $obj_credit
  * @param String $trace
  * @param int $operator_id
  * @return int $state
  */
 public function select($obj_id, $obj_credit, $trace, $operator_id)
 {
     $Object = new Object($obj_id);
     if (isset($this->SelectObject) and $this->SelectObject->getType() == 'promotion' and $obj_credit == 0) {
         //on conserve la promo dans SelectObject et on incrémente la step
         $this->promo_step++;
     } else {
         if ($Object->getType() == 'promotion') {
             //on isset SelectIbject et on met la step à 1
             $this->SelectObject = $Object;
             $this->promo_step = 1;
         } else {
             if ($Object->getType() == 'category') {
                 $this->SelectObject = $Object;
             } else {
                 unset($this->SelectObject);
             }
         }
     }
     if ($Object->getType() == 'product' or $Object->getType() == 'promotion') {
         //on vérifie le prix
         if ($obj_credit == 0 and isset($this->SelectObject) or Price::checkPrice($this->Buyer, $this->Point, $Object, $obj_credit) == 1) {
             //on vérifie que le Buyer a l'argent
             if ($this->Buyer->getCredit() >= $obj_credit) {
                 if ($Object->decStock()) {
                     //on décrémente le stock
                     //on encaisse
                     if ($obj_credit == 0) {
                         //promo... on décaisse juste le produit
                         $trace .= " via BUY";
                         $this->db->query("INSERT INTO t_purchase_pur (pur_date, pur_type, obj_id, pur_price, usr_id_buyer, usr_id_seller, poi_id, fun_id, pur_ip) VALUES (NOW(), '%s', '%u', '0', '%u', '%u', '%u', '%u', '%s')", array($Object->getType(), $Object->getId(), $this->Buyer->getId(), $operator_id, $this->Point->getId(), $Object->getFunId(), $trace));
                         $purchase_id = $this->db->insertId();
                         $this->Buyer->addToCart($Object, 0, $purchase_id);
                         return 1;
                     } else {
                         if ($this->Buyer->decCredit($obj_credit) == 1) {
                             //on enregistre
                             $trace .= " via BUY";
                             $this->db->query("INSERT INTO t_purchase_pur (pur_date, pur_type, obj_id, pur_price, usr_id_buyer, usr_id_seller, poi_id, fun_id, pur_ip) VALUES (NOW(), '%s', '%u', '%u', '%u', '%u', '%u', '%u', '%s')", array($Object->getType(), $Object->getId(), $obj_credit, $this->Buyer->getId(), $operator_id, $this->Point->getId(), $Object->getFunId(), $trace));
                             $purchase_id = $this->db->insertId();
                             $this->Buyer->addToCart($Object, $obj_credit, $purchase_id);
                             return 1;
                         } else {
                             return 400;
                         }
                     }
                 } else {
                     return 400;
                 }
             } else {
                 //on annule l'éventuelle promo
                 unset($this->SelectObject);
                 return 462;
             }
         } else {
             return 402;
         }
     } else {
         return 1;
     }
 }
Esempio n. 2
0
<?php

set_include_path(dirname(_FILE_) . '/../');
require_once 'class/Point.class.php';
require_once 'class/User.class.php';
require_once 'class/Proposition.class.php';
require_once 'class/Object.class.php';
require_once 'class/Price.class.php';
//Pour créer une proposition, on a besoin d'un user et d'un point
$User = new User('6362', 2, '', 1);
echo $User->getId();
$Point = new Point(2);
echo $Point->getId();
echo '<h2>Création</h2>';
$Proposition = new Proposition($User, $Point);
echo $Proposition->getUser()->getFirstname();
echo $Proposition->getPoint()->getName();
$Propo =& $Proposition->getObjectList();
echo '<pre>';
echo $Propo[0]->getName();
echo '</pre>';
$Object = new Object(2);
echo Price::checkPrice($User, $Point, $Object, 150);
echo Price::checkPrice($User, $Point, $Object, 50);