예제 #1
0
파일: Redeem.class.php 프로젝트: ciplpj/vsm
 public function redeem($sh_id)
 {
     global $database;
     global $session;
     $holder = new StockHolder($sh_id);
     if ($this->qty > 0) {
         if ($holder->cur_amt > $this->price) {
             $date = Database::date();
             $query = "INSERT INTO " . self::$table_ru . " (sh_id,p_id,date)";
             $query .= " VALUES ({$sh_id},{$this->id},'{$date}')";
             $run = $database->query($query);
             if ($run) {
                 $holder->amtUpdate($holder->cur_amt - $this->price);
                 $holder->redeemed();
                 $this->reduce_qty(1);
                 return true;
             } else {
                 $session->message('Your Request Couldn\'t Be Processed At This Moment Please Try Again');
                 return false;
             }
         } else {
             $session->message('You Dont Have Enough Virtual Money To Buy This Product');
             return false;
         }
     }
 }
예제 #2
0
파일: Stock.class.php 프로젝트: ciplpj/vsm
 public function sell($sh_id, $qty = 0)
 {
     global $session;
     $database = new Database();
     $sh_id = $database->escape_value($sh_id);
     $qty = (int) $qty;
     if ($this->isFound()) {
         $StockCompany = new StockCompany($this->sc_id);
         /*
         Check if the user has the stock or not
         */
         $holder_stocks = new HolderStocks($sh_id);
         $holder = new StockHolder($sh_id);
         if ($holder_stocks->isFound()) {
             if ($holder_stocks->hasStock($this->sc_id)) {
                 $index = array_search($this->sc_id, array_column($holder_stocks->holder_stocks, 'sc_id'));
                 $qty_having = $holder_stocks->holder_stocks[$index]['s_qty'];
                 if ($qty <= $qty_having) {
                     $stock_cur_price = Stock::getCurPrice($this->sc_id);
                     //This removes stocks from holder's list
                     $holder_stocks->removeStock($this->sc_id, $qty, $stock_cur_price);
                     //Updates the price of the holder
                     $holder->amtUpdate($holder->cur_amt + $stock_cur_price * $qty);
                     return true;
                 } else {
                     $session->message("You Dont have {$qty} stocks of {$StockCompany->c_name} to sell, You only have {$qty_having} stocks");
                     return false;
                 }
             } else {
                 $session->message("You Dont have {$StockCompany->c_name} stocks to sell");
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }