当前位置: 首页 > 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.sadfv.cn/news/216359/

相关文章:

  • 兼职做网站的软件做网站的工具 论坛
  • 网站美工主要工作是什么网站建设服务套餐
  • 成都网站制作软件悟空crm的优势与不足
  • 电子工厂网站建设服装网站开发方案swot
  • 网站建设及使用商业十大网站
  • 网站运营方案包装设计公司 山东
  • 郑州网站建设及托管怎么做网站报价表
  • 专业建设物流行业网站wordpress 实现 功能
  • 做网站是数据库应该放在哪里管理咨询项目
  • 诚聘网站开发人员免费网站生成器
  • 教育投资网站建设方案wordpress 更换空间阿里云
  • html做网站在手机上显示易语言可以做网站吗
  • seo网站优化网站编辑招聘深圳微信建网站
  • 宁德古田建设局网站做电商有哪些网站有哪些
  • 网站后台登录地址修改口红做网站多少钱
  • 专业的网站首页建设公司wordpress大前端
  • 安龙网站建设现在由哪些网站可以做外链
  • 周口公司做网站股权分配系统建设网站
  • 网站运营与建设成品网站10款
  • 传统门户网站有哪些广西教育学会 网站建设
  • hpsocket 网站开发o2o电子商务网站建设
  • 网站设计师发展方向织梦网站修改首页图片
  • 服装网站建设基本流程电商平台项目商业计划书
  • 高企达建设有限公司网站中国招商平台
  • 顺德网站建设找顺的代理网站系统
  • 网站地图生成软件东软 网站群平台建设
  • 优质校建设专题网站做网站上传图片
  • 自己想做个网站怎么做的学生做兼职的网站
  • 企业网站推广过程虚拟云主机 wordpress
  • 岳阳网站开发收费seo博客网站