<?php
namespace userplus;

class distribution{

	function userfenrun($productid = 0, $productmoney = 0, $userid, $proportion = 0){
		global $db;
		
		/*
		*	$productid 产品ID
		*	$productmoney 产品价格
		*	$userid 用户ID或账号
		*	$proportion 分拥比例
		*/
		if($proportion > 0){
			if($productmoney > 0){
				
				$u = $db -> select("OP_Usersource","ourphp_user","where OP_Useremail = '".$userid."'");
				if($u[0] != '')
				{
					
					$newmoney = $productmoney * $proportion / 100;
					$db -> update("ourphp_user","OP_Usermoney = OP_Usermoney + ".$newmoney ,"where OP_Useremail = '".$u[0]."'");
					$db -> insert("ourphp_usersaleinfo","
						`OP_Productid` = '".$productid."',
						`OP_Productmoney` = '".$productmoney."',
						`OP_Usermoney` = '".$newmoney."', 
						`OP_Buyuseremail` = '".$userid."',
						`OP_Incomeuseremail` = '".$u[0]."',
						`OP_Proportion` = '".$proportion."',
						`time` = '".date("Y-m-d H:i:s")."'
					","");
					return ;
					
				}else{
					return false;
				}
				
			}else{
				return false;
			}
			
		}else{
			return false;
		}

	}

}

?>