當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Stock::addToMarket方法代碼示例

本文整理匯總了PHP中Stock::addToMarket方法的典型用法代碼示例。如果您正苦於以下問題:PHP Stock::addToMarket方法的具體用法?PHP Stock::addToMarket怎麽用?PHP Stock::addToMarket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Stock的用法示例。


在下文中一共展示了Stock::addToMarket方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: add_new

 public static function add_new($c_name, $info, $ini_s_price, $thres_stock_val = 20, $total_stocks = 1000000)
 {
     $database = new Database();
     $c_name = $database->escape_value($c_name);
     $info = $database->escape_value($info);
     $ini_s_price = $database->escape_value($ini_s_price);
     $thres_stock_val = (int) $thres_stock_val;
     $total_stocks = (int) $total_stocks;
     $query = "INSERT INTO " . self::$table . " (c_name,info,ini_s_price,thres_stock_val,total_stocks,day_open_price,prev_day_close_price,bought_stocks) ";
     $query .= " VALUES ('{$c_name}','{$info}',{$ini_s_price},{$thres_stock_val},{$total_stocks},{$ini_s_price},0,0)";
     $insert = $database->query($query);
     if ($insert) {
         $query = "SELECT id FROM " . self::$table;
         $query .= " WHERE c_name = '" . $c_name . "' LIMIT 1";
         $find = $database->query($query);
         if ($find) {
             $sc_id = $database->fetch_array($find);
             $sc_id = $sc_id['id'];
             if (Stock::addToMarket($sc_id, $ini_s_price)) {
                 if (StockHistory::add($sc_id, $ini_s_price)) {
                     if (StockControl::add($sc_id)) {
                         return true;
                     } else {
                         Log::add("Failed to add to StockControl - {$sc_id}", LOG_MANUAL);
                         return false;
                     }
                 } else {
                     Log::add("Failed to add to StockHistory,StockControl - {$sc_id}", LOG_MANUAL);
                     return false;
                 }
             } else {
                 Log::add("Failed to add to StockMarket,StockHistory,StockControl - {$sc_id}", LOG_MANUAL);
                 return false;
             }
         } else {
             Log::add("Failed to find new stockCompany record (add in StockMarket,StockHistory,StockControl)-{$sc_id} ", LOG_MANUAL);
         }
     } else {
         return false;
     }
 }
開發者ID:ciplpj,項目名稱:vsm,代碼行數:41,代碼來源:StockCompany.class.php

示例2: stockUpdate

 public function stockUpdate()
 {
     $stock_control = new StockControl($this->sc_id);
     $cur_price = Stock::getCurPrice($this->sc_id);
     if ($stock_control->getOverride() == -1) {
         $val = mt_rand(-abs($stock_control->low), -abs($stock_control->high));
         $new_val = $cur_price + $val;
         /*
          * Check if over_value as been reached or not! if it has
          * then terminate the control function
          */
         if ($stock_control->over_value >= $new_val) {
             $stock_control->setOverride(0);
             $stock_control->writeControl();
             Stock::addToMarket($this->sc_id, $new_val);
             return true;
         }
         if ($this->threshold < $new_val) {
             Stock::addToMarket($this->sc_id, $new_val);
             return true;
         } else {
             /*
              * Reached ground value so turn overide off now!
              */
             $stock_control->setOverride(0);
             $stock_control->writeControl();
             $val = mt_rand(0, abs(2 * $stock_control->high));
             $new_val = $cur_price + $val;
             Stock::addToMarket($this->sc_id, $new_val);
             return true;
         }
     } elseif ($stock_control->getOverride() == 1) {
         $val = mt_rand(abs($stock_control->low), abs($stock_control->high));
         $new_val = $cur_price + $val;
         /*
          * Check if over_value as been reached or not! if it has
          * then terminate the control function
          */
         if ($stock_control->over_value <= $new_val) {
             $stock_control->setOverride(0);
             $stock_control->writeControl();
             Stock::addToMarket($this->sc_id, $new_val);
             return true;
         }
         Stock::addToMarket($this->sc_id, $new_val);
         return true;
     } else {
         $news = News::getNewsForStock($this->sc_id);
         if (is_array($news) && !empty($news)) {
             $new = array_shift($news);
             if ($new['p_change'] > 0) {
                 if ($new['price_value'] > $cur_price) {
                     $val_diff = $new['price_value'] - $cur_price;
                     if ($val_diff > 400) {
                         $reduce = (int) $val_diff / mt_rand(40, 80);
                         $new_val = $cur_price + $reduce;
                         Stock::addToMarket($this->sc_id, $new_val);
                         return true;
                     } elseif ($val_diff > 200) {
                         $reduce = (int) $val_diff / mt_rand(20, 40);
                         $new_val = $cur_price + $reduce;
                         Stock::addToMarket($this->sc_id, $new_val);
                         return true;
                     } elseif ($val_diff > 100) {
                         $reduce = (int) $val_diff / mt_rand(10, 20);
                         $new_val = $cur_price + $reduce;
                         Stock::addToMarket($this->sc_id, $new_val);
                         return true;
                     } else {
                         $reduce = mt_rand(0, 3);
                         $new_val = $cur_price + $reduce;
                         Stock::addToMarket($this->sc_id, $new_val);
                         return true;
                     }
                 } else {
                     News::newsDone($new['id']);
                 }
             } else {
                 //Negative price changee in news
                 if ($new['price_value'] < $cur_price) {
                     $val_diff = $cur_price - $new['price_value'];
                     if ($val_diff > 400) {
                         $reduce = (int) $val_diff / mt_rand(40, 80);
                         $new_val = $cur_price - $reduce;
                         Stock::addToMarket($this->sc_id, $new_val);
                         return true;
                     } elseif ($val_diff > 200) {
                         $reduce = (int) $val_diff / mt_rand(20, 40);
                         $new_val = $cur_price - $reduce;
                         Stock::addToMarket($this->sc_id, $new_val);
                         return true;
                     } elseif ($val_diff > 100) {
                         $reduce = (int) $val_diff / mt_rand(10, 20);
                         $new_val = $cur_price - $reduce;
                         Stock::addToMarket($this->sc_id, $new_val);
                         return true;
                     } else {
                         $reduce = mt_rand(0, 3);
                         $new_val = $cur_price - $reduce;
                         /*
//.........這裏部分代碼省略.........
開發者ID:ciplpj,項目名稱:vsm,代碼行數:101,代碼來源:Stock.class.php


注:本文中的Stock::addToMarket方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。