php+jquery完成生成红包

xiaoxiao2021-02-28  111

html.

<include file="./Apps/Wap/View/default/header_common.html" /> <link rel="stylesheet" href="__ROOT__/Apps/Wap/View/default/css/message.css"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Zero Clipboard Test</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body > <div id="result"></div> 红包总额:<input type="text" id="total" placeholder="输入红包总额"><br/> 红包个数:<input type="text" id="num" placeholder="输入红包个数"><br/> <button  class="button">发红包</button> </body> <!--  详细介绍见: http://www.admin10000.com/Document/35.html --> </html> <include file="./Apps/Wap/View/default/footer.html" /> <script src="__ROOT__/Apps/Wap/View/default/js/message.js"></script> <script>       $(".button").click(function() {         if($("#total").val()==''){               msgAlert('请输入红包总额');               return;         }else if($("#num").val()==''){            msgAlert('请输入红包数量');            return;         }         var e={};         e.total=$("#total").val();         e.num=$("#num").val();         $.post(Think.U('Wap/Uber/sendPassbook'),e,function(e,s,d){           var o=WST.toJson(e);         for(var i=1;i<o.length+1;i++){         $("#result").prepend('<div>第'+i+'个红包金额为'+o[i-1].money+'</div>');         }         })       }); </script>

php.

<?php /**  * Created by PhpStorm. * User: Ferris * Date: 15/12/16 * Time: 23:18 */ namespace Wap\Action; class UberAction extends BaseAction {

public function sendPassbook(){ $total=I('total');//红包总金额 $num=I('num');// 分成n个红包,支持n人随机领取 $min=0.01;//每个人最少能收到0.01元 for ($i=0;$i<$num;$i++) {     $safe_total=($total-($num-$i)*$min);//随机安全上限 if($i!=$num-1){ $money=mt_rand($min*100,$safe_total*100)/100; $total=$total-$money; $rs[$i]['money']=$money; }else{ $rs[$i]['money']=$total; } } echo json_encode($rs,true); }

}

转载请注明原文地址: https://www.6miu.com/read-48342.html

最新回复(0)