得益=586+600=1186
支出=586
小梁得益=258
小梁因给258*586/1186=127.5
小李得益499+100=599
小李因给599*586/1186=296
支出=586
小梁得益=258
小梁因给258*586/1186=127.5
小李得益499+100=599
小李因给599*586/1186=296
解决方案 »
- PHP调用WebSevice,<soap:address location>中的地址指向服务器本地,如何吧地址改成ip地址然后再调用
- php后台管理验证问题
- PHP写XML时,无法向节点属性写中文值
- 下拉菜单选择提交后能否让菜单内显示所选值
- 用户已经登录,但flash 上传时,服务器提示未登录!!!!!!!!!!
- 图片验证码的问题
- 奇怪问题,我升级phpmyadmin后,如果不输入index.php,就会出现Index of /phpmyadmin,而不是进入phpmyadmin
- 问一个简单的PHP.INI中的配置问题.谢谢!
- 为什么不能连接建立下一级目录啊?
- 高手请指教!!!
- 安装一个blog时的问题(提示无法连接数据库,config.php中dbpasswd="")
- PHP select使用中的问题
呵呵,写了个程序来算累死了,可郁闷,不知道对不对,大家验证吧
根据比例算的
=========================================总现金:1085
总返券:1080
合计:2165
小米:实际消费:155.52
小梁:实际消费:111.78
小李:实际消费:218.7
小李:实际消费:318.7
=========================================
<?
class Arithmetic
{
var $arrShoppingInfo; var $cash; //支付现金
var $cashTicket; //获得购物券
var $allCash; //全部货款
var $allCashTicket; //全部返券
var $allInclusive; //货款、返券合计
var $ctPer; //返券比例 function Arithmetic($ctPer)
{
$this->arrShoppingInfo = array();
$this->ctPer = $ctPer;
}
/**
* 设置个人鞋价及获得的返券
*
* @param unknown_type string
* @param unknown_type int
*/
function SetShoppingInfo($clientName, $retailPrice)
{
$this->arrShoppingInfo["$clientName"]['retailPrice'] = $retailPrice;
$this->arrShoppingInfo["$clientName"]['cashTicket'] = $this->GetCashTicket($this->arrShoppingInfo["$clientName"]['retailPrice']);
}
/**
* 获取返券额
*
* @param int
* @return int
*/
function GetCashTicket($cash)
{
return floor($cash/100)*$this->ctPer*100;
}
/**
* 获取全部现金及返券
*
*/
function GetAllInclusive()
{
foreach ($this->arrShoppingInfo as $clientInfo)
{
$this->allCash += $clientInfo['retailPrice'];
$this->allCashTicket += $clientInfo['cashTicket'];
}
$this->allInclusive = $this->allCash + $this->allCashTicket;
}
/**
* 消费比例
*
*/
function SetShoppingPer()
{ foreach ($this->arrShoppingInfo as $clientName => $clientInfo)
{
$clientAllInclusive = $clientInfo['retailPrice'] + $clientInfo['cashTicket'];
$this->arrShoppingInfo["$clientName"]['shoppingPer'] = round($clientAllInclusive/$this->allInclusive, 2);
}
}
function GetClientShopping($cashPayment)
{
foreach ($this->arrShoppingInfo as $clientName => $clientInfo)
{
$this->arrShoppingInfo["$clientName"]['cashPayment'] = $cashPayment*$this->arrShoppingInfo["$clientName"]['shoppingPer'];
}
}
/**
* 分配剩余购物券
*
*/
function DistributeSurplus($distribute)
{
foreach ($this->arrShoppingInfo as $clientName => $clientInfo)
{
$this->arrShoppingInfo["$clientName"]['distribute'] = $distribute*$this->arrShoppingInfo["$clientName"]['shoppingPer'];
}
}
}
$Arithmetic = new Arithmetic(1.2);
//设置个人消费
$Arithmetic->SetShoppingInfo('小米', 328);
$Arithmetic->SetShoppingInfo('小梁', 258);
$Arithmetic->SetShoppingInfo('小李', 499);$Arithmetic->GetAllInclusive();
$Arithmetic->SetShoppingPer();
$Arithmetic->SetShoppingPer();//实际消费金额
$Arithmetic->GetClientShopping(586);//剩余金额分配
$Arithmetic->DistributeSurplus(100);
echo '<pre>';
echo "总现金:$Arithmetic->allCash\n";
echo "总返券:$Arithmetic->allCashTicket\n";
echo "合计:$Arithmetic->allInclusive\n";
foreach ($Arithmetic->arrShoppingInfo as $clientName => $clientInfo)
{
echo "$clientName:实际消费:".($clientInfo['cashPayment']-$clientInfo['distribute'])."\n";
}
echo "小李:实际消费:".($Arithmetic->arrShoppingInfo["小李"]['cashPayment']-$Arithmetic->arrShoppingInfo["小李"]['distribute']+100).'<br>';
print_r($Arithmetic->arrShoppingInfo);
?>
支出=586
小梁得益=258
小梁因给258*586/1186=127.5
小李得益499+100=599
小李因给599*586/1186=296
--------------------------------------
这个答案不合理:
小梁如果自己去买鞋: 付258返还240,只化了18元,买一双258的鞋。
现在同样得到一双258的鞋,却要付给小李127.5,她显然不干。
小李也是 296-101(多余的票)=195买了一双499的鞋。
自己买:499-480=19, 她也不干了
那大家干嘛不都去自己买呢
我认为应该先求出600元的购物卷需多少钱,然后反利
标价一共要花1085元 :
小梁占258/1085 ,
小米占328/1085,
小李占499/1085。实际一共花了485元 :
小梁花485*258/1085 = 115.32,
小米占485*328/1085 = 146.62,
小李占485*499/1085 = 223.06。这样就差不多了。呵呵。
不然就可以用一点点钱把店里的东西都搬回家
特别是超市,都明打着不参与活动的大告示:)