{
$self = new self();
$self-num = $num;
$self-rangeStart = $rangeStart;
$self-rangeEnd = $rangEnd;
$self-totalMoney = $totalMoney;
$self-builderStrategy = $builderStrategy;
$self-randFormatType = $randFormatType;
return $self;
}
}
//红包?成器接?
interface IBuilderStrategy
{
//创建红包
public function create();
//设置配置
public function setOption(OptionDTO $option);
//是否可以?成红包
public function isCanBuilder();
//?成红包函数
public function fx($x);
}
//固定等额红包策略
class EqualPackageStrategy implements IBuilderStrategy {
【微信红包java算法代码 java微信红包实现】//单个红包?额
public $oneMoney;
//数量
public $num;
public function __construct($option = null)
{
if($option instanceof OptionDTO)
{
$this-setOption($option);
}
}
public function setOption(OptionDTO $option)
{
$this-oneMoney = $option-rangeStart;
$this-num = $option-num;
}
public function create()
{
$data = https://www.04ip.com/post/array();
if(false == $this-isCanBuilder())
{
return $data;
}
$data = https://www.04ip.com/post/array();
if(false == is_int($this-num) || $this-num = 0) {
return $data;
}
for($i = 1;$i = $this-num;$i++)
{
$data[$i] = $this-fx($i);
}
return $data;
}
/**
* 等额红包的?程是?条直线
*
* @param mixed $x
* @access public
* @return void
*/
public function fx($x)
{
return $this-oneMoney;
}
/**
* 是否能固定红包
*
* @access public
* @return void
*/
public function isCanBuilder()
{
if(false == is_int($this-num) || $this-num = 0)
{
return false;
}
if(false == is_numeric($this-oneMoney) || $this-oneMoney = 0)
{
return false;
}
//单个红包?于1分
if($this-oneMoney0.01)
{
return false;
}
return true;
}
}
//随机红包策略(三?形)
class RandTrianglePackageStrategy implements IBuilderStrategy
{
//总额
public $totalMoney;
//红包数量
public $num;
//随机红包最?值
public $minMoney;
//随机红包最?值
public $maxMoney;
//修数据?式:NO_LEFT: 红包总额 = 预算总额;CAN_LEFT: 红包总额 = 预算总额public $formatType;
//预算剩余?额
public $leftMoney;
public function __construct($option = null)
{
if($option instanceof OptionDTO)
{
$this-setOption($option);
}
}
public function setOption(OptionDTO $option) {
$this-totalMoney = $option-totalMoney;
$this-num = $option-num;
$this-formatType = $option-randFormatType; $this-minMoney = $option-rangeStart;
$this-maxMoney = $option-rangeEnd;
$this-leftMoney = $this-totalMoney;
}
/**
* 创建随机红包
*
* @access public
* @return void
*/
public function create()
{
$data = https://www.04ip.com/post/array();
if(false == $this-isCanBuilder())
{
return $data;
}
$leftMoney = $this-leftMoney;
for($i = 1;$i = $this-num;$i++)
{
$data[$i] = $this-fx($i);
$leftMoney = $leftMoney - $data[$i];
}
//修数据
list($okLeftMoney,$okData) = $this-format($leftMoney,$data);
//随机排序
shuffle($okData);
$this-leftMoney = $okLeftMoney;
return $okData;
}
/**
* 是否能够发随机红包
* @access public
* @return void
*/
public function isCanBuilder()
推荐阅读
- flutter图片内存,flutter加载图片内存溢出
- 玩射击游戏伤脑子嘛,经常玩射击游戏会怎么样
- 虎牙直播如何换绑微信支付,虎牙直播更换绑定银行卡
- linux管道命令%3c linux管道命令是什么
- html5多媒体容器有哪些的简单介绍
- linux虚拟机dhcp,Linux虚拟机权限不够怎么办
- 红米7怎么连接硬盘,红米7怎么连接u盘
- c语言好用的函数分装 c语言拆分函数
- mq消息存入redis可靠性,redis消息队列可靠性