Пример #1
0
 public function split_stock($split_num, $sid)
 {
     $db = new DB();
     $db->Connect(DBHOST, DBUSER, DBPW, DBNAME);
     //系统总股仓更新
     $stock = new stock();
     $stockconfig = $stock->get_stockconfig(1);
     $allsotckcount = $stockconfig["counts"];
     $sql = "update stock set counts = {$allsotckcount}*{$split_num}  where id={$sid}";
     $db->query($sql);
     //股价更新
     $sql = "select * from stock_price where sid = {$sid}  order by id desc limit 1";
     $query = $db->query($sql);
     $result = $db->fetch_array($query);
     $now_price = $result["price"];
     $now_price_id = $result["id"];
     $split_price = $now_price / $split_num;
     $sql = "update stock_price set price = {$split_price} where id={$now_price_id}";
     $db->query($sql);
     //用户股票更新
     $sql = "select * from users where states = 1 ";
     $query = $db->query($sql);
     $count = $db->num_rows($query);
     for ($i = 0; $i < $count; $i++) {
         $row = $db->fetch_array($query);
         $uid = $row["id"];
         $old_stock = $row["stock"];
         $new_stock = $old_stock * $split_num;
         //更新user stock
         $sql = "update users set stock=" . $new_stock . " where id={$uid}";
         $db->query($sql);
     }
 }