当前位置: 首页 > news >正文

qml 网站开发秦皇岛制作网站

qml 网站开发,秦皇岛制作网站,网站制作技术培训学校,关于幼儿建设网站ppt模板下载本文主要向大家介绍了PHP语言#xff1a;实现微信红包拆分算法#xff0c;通过具体的内容向大家展示#xff0c;希望对大家学习php语言有所帮助。 修复最后一个红包输出未保留2位数 修复领取的红包金额低于最小红包限制* 红包分配算法** example* $coupon new Coupon(…本文主要向大家介绍了PHP语言实现微信红包拆分算法通过具体的内容向大家展示希望对大家学习php语言有所帮助。· 修复最后一个红包输出未保留2位数· 修复领取的红包金额低于最小红包限制* 红包分配算法** example*      $coupon new Coupon(200, 5);*      $res $coupon-handle();*      print_r($res);** author Flc 2018-04-06 20:09:53* see http://flc.ren | http://flc.io | https://github.com/flc1125*/class Coupon{/*** 红包金额** var float*/protected $amount;/*** 红包个数** var int*/protected $num;/*** 领取的红包最小金额** var float*/protected $coupon_min;/*** 红包分配结果** var array*/protected $items  [];/*** 初始化** param float $amount     红包金额(单位元)最多保留2位小数* param int   $num        红包个数* param float $coupon_min 每个至少领取的红包金额*/public function __construct($amount, $num  1, $coupon_min  0.01){$this-amount  $amount;$this-num  $num;$this-coupon_min  $coupon_min;}/*** 处理返回** return array*/public function handle(){// A. 验证if ($this-amount  $validAmount $this-coupon_min * $this-num) {throw new Exception(红包总金额必须≥.$validAmount.元);}// B. 分配红包$this-apportion();return [items  $this-items,];}/*** 分配红包*/protected function apportion(){$num  $this-num;  // 剩余可分配的红包个数$amount  $this-amount;  //剩余可领取的红包金额while ($num  1) {// 剩余一个的时候直接取剩余红包if ($num  1) {$coupon_amount  $this-decimal_number($amount);} else {$avg_amount  $this-decimal_number($amount / $num);  // 剩余的红包的平均金额$coupon_amount  $this-decimal_number($this-calcCouponAmount($avg_amount, $amount, $num));}$this-items[]  $coupon_amount; // 追加分配$amount - $coupon_amount;--$num;}shuffle($this-items);  //随机打乱}/*** 计算分配的红包金额** param float $avg_amount 每次计算的平均金额* param float $amount     剩余可领取金额* param int   $num        剩余可领取的红包个数** return float*/protected function calcCouponAmount($avg_amount, $amount, $num){// 如果平均金额小于等于最低金额则直接返回最低金额if ($avg_amount  $this-coupon_min) {return $this-coupon_min;}// 浮动计算$coupon_amount  $this-decimal_number($avg_amount * (1  $this-apportionRandRatio()));// 如果低于最低金额或超过可领取的最大金额则重新获取if ($coupon_amount  $this-coupon_min|| $coupon_amount  $this-calcCouponAmountMax($amount, $num)) {return $this-calcCouponAmount($avg_amount, $amount, $num);}return $coupon_amount;}/*** 计算分配的红包金额-可领取的最大金额** param float $amount* param int   $num*/protected function calcCouponAmountMax($amount, $num){return $this-coupon_min  $amount - $num * $this-coupon_min;}/*** 红包金额浮动比例*/protected function apportionRandRatio(){// 60%机率获取剩余平均值的大幅度红包(可能正数、可能负数)if (rand(1, 100)  60) {return rand(-70, 70) / 100; // 上下幅度70%}return rand(-30, 30) / 100; // 其他情况上下浮动30%}/*** 格式化金额保留2位** param float $amount** return float*/protected function decimal_number($amount){return sprintf(%01.2f, round($amount, 2));}}// 例子$coupon  new Coupon(200, 5, 30);$res  $coupon-handle();print_r($res);以上就介绍了PHP的相关知识希望对PHP有兴趣的朋友有所帮助。了解更多内容请关注职坐标编程语言PHP频道
http://www.yutouwan.com/news/216359/

相关文章:

  • 医疗知识普及网站开发大学生网站建设策划书范文
  • 网站项目建设人员规划三明网站建设
  • 网站建站中关键字搜索怎么弄门户网站英文
  • 全国建设项目竣工验收公示网站电商网站建设哪家公司好
  • 涉县企业做网站推广火车头wordpress教程
  • 建设注册中心网站首页wordpress打开
  • 我的网站 dedecmswordpress手机后台
  • 网站第三方微信登陆怎么做的网站建设找宙斯站长工具
  • 卡盟自助网站建设wordpress实现圈子功能
  • 移动端快速建站软件大全免费下载
  • 营销型网站应必备的七大功能wordpress登录评论
  • 企业网站建设方案教程app推广渠道商
  • 电商网站的二级菜单怎么做禾量电商小程序
  • 郑州公司网站建设哪家好网站做edi认证有用没
  • 济南城乡住房建设厅网站兰州市建设局官方网站
  • 网站如何改版做网站前景怎么样
  • 自己做网站怎么赢利企业crm销售管理系统
  • 大连网站建设讯息wordpress 搜索结果分页
  • 做网站可能存在的问题wordpress短链识别
  • 福州网站设计软件公司冠县哪做网站
  • 公司网站建设征求意见表模板设计图
  • 门户app网站建设多少钱制作一个简单的网页步骤
  • 北京市住房与城乡建设厅网站网站域名做哪个会计科目
  • 怎么开通个人网站wordpress做成仿阿里巴巴
  • 天津网站建设好公司美容加盟的网站建设
  • 网络推广怎么干杭州网站优化企业
  • 做三方网站多少钱wordpress 充值插件
  • 做网站 广州90设计怎么免费下载
  • 大连三大网络推广网站成都关键词优化排名
  • 怎么查网站权重定制网络机顶盒