Server : nginx/1.20.1 System : Linux iZ2ze9ojcl78uluczwag69Z 4.18.0-240.22.1.el8_3.x86_64 #1 SMP Thu Apr 8 19:01:30 UTC 2021 x86_64 User : www ( 1000) PHP Version : 7.3.28 Disable Function : passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/0531yanglao.com/extend/phpTools/ |
<?php namespace phpTools; header('content-type:text/html;charset=utf-8'); /** * Class CommonTools * 公共工具类 */ class CommonTools{ /** * @desc 通过一个总金额和总个数,生成不同的红包金额,可用于微信发放红包 * @param $total [你要发的红包总额] * @param int $num [发几个],默认为10个 * @return array [生成红包金额数组] */ public static function getRedGift($total, $num = 10) { $min = 0.01; $temp = array(); $return = array(); for ($i = 1; $i < $num; ++$i) { $safe_total = ($total - ($num - $i) * $min) / ($num - $i); //红包金额的最大值 dump($safe_total); if ($safe_total < 0) break; $money = @mt_rand($min * 100, $safe_total * 100) / 100;//随机产生一个红包金额 $total = $total - $money;// 剩余红包总额 $temp[$i] = round($money, 2);//保留两位有效数字 } $temp[$i] = round($total, 2); $return['money_sum'] = $temp; $return['new_total'] = array_sum($temp); return $return; } }