public function user_upgrade_stand() { $users = new users(); $bizset = new bizset(); $award = new award(); $bizsetinfo = $bizset->get_bizset_bykey("STANDARD"); //达标业绩个数 $standardcount = $bizsetinfo["bizvalue"]; //根据等级获取达标金额 $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE2"); $standard_price2 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE3"); $standard_price3 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE4"); $standard_price4 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE5"); $standard_price5 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE6"); $standard_price6 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE7"); $standard_price7 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE8"); $standard_price8 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE9"); $standard_price9 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE10"); $standard_price10 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE11"); $standard_price11 = $bizsetinfo["bizvalue"]; $db = new DB(); $db->Connect(DBHOST, DBUSER, DBPW, DBNAME); $sql = "select * from users where states = 1 and id !=100000 "; $query = $db->query($sql); $count = $db->num_rows($query); for ($i = 0; $i < $count; $i++) { $row = $db->fetch_array($query); $uid = $row["id"]; $productcount = $row["standardlevel"]; //团队达标级别 //获取达标个数 if ($uid > 0) { $pidcount = $users->get_usercount_bypid($uid); } else { $pidcount = 0; } if ($pidcount == $standardcount) { //判断三个市场是否都达标 获取达标系数 $sql_standard = "select * from users where states = 1 and pid = " . $uid; $query_standard = $db->query($sql_standard); for ($i = 1; $i <= 3; $i++) { $row_standard = $db->fetch_array($query_standard); $uid_standard = $row_standard["id"]; $usersids = $users->getrecursiveallusersid($uid_standard); $usersids = substr($usersids, 0, strlen($usersids) - 1); if (strlen($usersids) <= 0) { $usersids = "0"; } if ($usersids != "0") { //获取该区团队业绩 $sql = "select abs(sum(amount)) as price from income where types='BUYSTOCK' and userid in ({$usersids}) "; $query_s = $db->query($sql); $result = $db->fetch_array($query_s); $sumamount = $result["price"]; $str = "sumamount" . $i; ${$str} = $sumamount; } } //echo $sumamount1."-".$sumamount2."-".$sumamount3;exit; if ($sumamount1 == "") { $sumamount1 = 0; } if ($sumamount2 == "") { $sumamount2 = 0; } if ($sumamount3 == "") { $sumamount3 = 0; } //根据3个市场的累计业绩 判断等级 $standard_sumamount = self::getMinNum($sumamount1, $sumamount2, $sumamount3); if ($standard_sumamount >= $standard_price11) { $sql = "update users set standardlevel = 11 where id=" . $uid . ""; $db->query($sql); } else { if ($standard_sumamount >= $standard_price10) { $sql = "update users set standardlevel = 10 where id=" . $uid . ""; $db->query($sql); } else { if ($standard_sumamount >= $standard_price9) { $sql = "update users set standardlevel = 9 where id=" . $uid . ""; $db->query($sql); } else { if ($standard_sumamount >= $standard_price8) { $sql = "update users set standardlevel = 8 where id=" . $uid . ""; $db->query($sql); } else { if ($standard_sumamount >= $standard_price7) { $sql = "update users set standardlevel = 7 where id=" . $uid . ""; $db->query($sql); } else { if ($standard_sumamount >= $standard_price6) { $sql = "update users set standardlevel = 6 where id=" . $uid . ""; $db->query($sql); } else { if ($standard_sumamount >= $standard_price5) { $sql = "update users set standardlevel = 5 where id=" . $uid . ""; $db->query($sql); } else { if ($standard_sumamount >= $standard_price4) { $sql = "update users set standardlevel = 4 where id=" . $uid . ""; $db->query($sql); } else { if ($standard_sumamount >= $standard_price3) { $sql = "update users set standardlevel = 3 where id=" . $uid . ""; $db->query($sql); } else { if ($standard_sumamount >= $standard_price2) { $sql = "update users set standardlevel = 2 where id=" . $uid . ""; $db->query($sql); } } } } } } } } } } } } }
public function standard_settle($db, $standardcount) { $users = new users(); $bizset = new bizset(); $award = new award(); //获取最新结算号 $settle_no = self::get_settle_no(); //获取最新股价 $stockinfo = new stock(); $new_price = $stockinfo->get_newprice(1); //根据等级获取达标金额 $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE2"); $standard_price2 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE3"); $standard_price3 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE4"); $standard_price4 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE5"); $standard_price5 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE6"); $standard_price6 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE7"); $standard_price7 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE8"); $standard_price8 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE9"); $standard_price9 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE10"); $standard_price10 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PRICE11"); $standard_price11 = $bizsetinfo["bizvalue"]; //根据等级获取达标分红比例 $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PERCENT2"); $standard_percent2 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PERCENT3"); $standard_percent3 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PERCENT4"); $standard_percent4 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PERCENT5"); $standard_percent5 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PERCENT6"); $standard_percent6 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PERCENT7"); $standard_percent7 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PERCENT8"); $standard_percent8 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PERCENT9"); $standard_percent9 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PERCENT10"); $standard_percent10 = $bizsetinfo["bizvalue"]; $bizsetinfo = $bizset->get_bizset_bykey("STANDARD_PERCENT11"); $standard_percent11 = $bizsetinfo["bizvalue"]; //遍历users $query = $db->query("select * from users where states = 1"); $count = $db->num_rows($query); for ($i = 0; $i < $count; $i++) { $row = $db->fetch_array($query); $uid = $row["id"]; $usersinfo = $users->get_user_byid($uid); $stock = $usersinfo["stock"]; //用户投资额 //$user_stock_price = $stock*$new_price; //获取达标个数 $pidcount = $users->get_usercount_bypid($uid); if ($pidcount == $standardcount) { //判断三个市场是否都达标 获取达标系数 $sql_standard = "select * from users where states = 1 and pid = " . $uid; $query_standard = $db->query($sql_standard); for ($i = 0; $i < $standardcount; $i++) { $row_standard = $db->fetch_array($query_standard); $uid_standard = $row_standard["id"]; $usersids = $users->getrecursiveallusersid($uid_standard); $usersids = substr($usersids, 0, strlen($usersids) - 1); if (strlen($usersids) <= 0) { $usersids = "0"; } if ($usersids != "0") { //$sql = "select sum(stock) as price from users where id in ($usersids) "; //获取投资者投资额 $sql = "select abs(sum(amount)) as price from income where types='BUYSTOCK' and userid = {$uid}"; $query_s = $db->query($sql); $result = $db->fetch_array($query_s); $sumamount = $result["price"]; //用户投资额 //$sumamount = $sumamount*$new_price; //达标分红比例 if ($sumamount >= $standard_price11) { $percent = $standard_percent11; $standard_amout = $standard_price11; } else { if ($sumamount >= $standard_price10) { $percent = $standard_percent10; $standard_amout = $standard_price10; } else { if ($sumamount >= $standard_price9) { $percent = $standard_percent9; $standard_amout = $standard_price9; } else { if ($sumamount >= $standard_price8) { $percent = $standard_percent8; $standard_amout = $standard_price8; } else { if ($sumamount >= $standard_price7) { $percent = $standard_percent7; $standard_amout = $standard_price7; } else { if ($sumamount >= $standard_price6) { $percent = $standard_percent6; $standard_amout = $standard_price6; } else { if ($sumamount >= $standard_price5) { $percent = $standard_percent5; $standard_amout = $standard_price5; } else { if ($sumamount >= $standard_price4) { $percent = $standard_percent4; $standard_amout = $standard_price4; } else { if ($sumamount >= $standard_price3) { $percent = $standard_percent3; $standard_amout = $standard_price3; } else { if ($sumamount >= $standard_price2) { $percent = $standard_percent2; $standard_amout = $standard_price2; } else { $percent = 0; break; } } } } } } } } } } } } //根据分红比例加权分红 $usersids_all = $users->getrecursiveallusersid($uid); $usersids_all = substr($usersids_all, 0, strlen($usersids_all) - 1); if (strlen($usersids_all) <= 0) { $usersids_all = "0"; } if ($usersids_all != "0" && $percent > 0) { self::award_standard_settle($db, $uid, $usersids_all, $percent, $settle_no, $standard_amout); } } //更新结算状态变成已结算,并将结算期号增加到income表 $sql = "update income set settlementno = '" . $settle_no . "' where (settlementno is null or settlementno='') and userid ={$uid} "; $db->query($sql); } //将本次结算设置为已结算 $sql = "update settlement set states = 1 where numbers = '" . $settle_no . "'"; $db->query($sql); }