您的位置:首页 > 移动开发 > 微信开发

微信红包发红包

2015-02-27 14:39 253 查看
<p>

x元钱分n个红包,要求每个红包钱数大于0;每个红包钱数尽量不同;最大红包钱少于x/4;以上为基本要求,附加要求:如果钱数尾数不为4或7,尾数为8越多越好!有兴趣的同事将编好的程序微信给我!有红包奖励!</p>

红包个数:<input type="text" name="count"/>

  总金额:<input type="text" name="money"/>

<button id="gomoney">发红包</button>

<table id="peopleL">

</table>

<script type="text/javascript" src="./jquery-1.8.2.min.js"></script>

<script type="text/javascript">

//author:wangmao

$("#gomoney").click(function(){
var hcount=$("input[name='count']").val();
var hmoney=$("input[name='money']").val();
if(undefined!=hcount&&undefined!=hmoney){
hcount=parseInt(hcount);
hmoney=parseFloat(hmoney);
var peopleList=new Array();
if(hcount>=1&&hmoney>(hcount*0.1)){
var newcount=hcount;
for(var i=0;i<hcount;i++){
if(1==hcount||(i+1)==hcount){
peopleList[i]=hmoney.toFixed(1);
}else{
if(hcount>1){

var num=Math.random()*(hmoney/4-(0.1*newcount));
var newmoney =num.toFixed(1);
if(newmoney==0){
newmoney=0.1;

}
var nmoney=newmoney+"";

//获取随机钱数小数点前几位
var qnumber=nmoney.split(".")[0];
//如果整数列长度2位数,则使其尾数为8
if(qnumber.length>=2){
var numberlist=new Array();
for(var p=0;p<qnumber.length;p++){
var snumber=((8*getnumber(qnumber.length-p))-(parseInt(qnumber.substring(p,p+1)))*(getnumber(qnumber.length-p)));

newmoney=(parseFloat(newmoney+snumber));

}
}
var h1number=parseFloat(0.8-(parseInt(nmoney.split(".")[1])*0.1));
if((hmoney/newcount)>h1number){
newmoney=(parseFloat(newmoney+h1number));
}
var o1money=newmoney+"";
newmoney=parseFloat(o1money.substring(0,(o1money.split(".")[0].length+2)));
peopleList[i]=newmoney;
newcount=newcount-1;
hmoney=hmoney-newmoney;
}
}
}
$("#peopleL").children().remove();
for(var pobj=0;pobj<peopleList.length;pobj++){
$("#peopleL").append("<tr><td>第"+(pobj+1)+"个红包</td><td>金额为"+peopleList[pobj]+"</td></tr>");
}

 }else{
alert("输入有误")

 }

}else{
alert("输入有误")

}

})

function getnumber(number){

var newnumber="1";

for(var i=1;i<parseInt(number);i++){
newnumber+="0"

}

return parseInt(newnumber);

}

</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  微信红包 发红包