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()
{
if(false == is_int($this-num) || $this-num = 0)
{
return false;
}
if(false == is_numeric($this-totalMoney) || $this-totalMoney = 0) {
return false;
}
//均值
$avgMoney = $this-totalMoney / 1.0 / $this-num;
//均值?于最?值
if($avgMoney$this-minMoney )
{
return false;
}
return true;
}
/**
* 获取剩余?额
* @access public
public function getLeftMoney()
{
return $this-leftMoney;
}
/**
* 随机红包?成函数 。三?函数 。[(1,0.01),($num/2,$avgMoney),($num,0.01)] * @param mixed $x,1 = $x = $this-num;
* @access public
* @return void
*/
public function fx($x)
{
if(false == $this-isCanBuilder())
{
return 0;
}
if($x1 || $x$this-num)
{
return 0;
}
$x1 = 1;
$y1 = $this-minMoney;
//中间点
$x2 = ceil($this-num / 1.0 / 2);
//随机红包算法java代码我的峰值
$y2 = $this-maxMoney;
//最后点
$x3 = $this-num;
$y3 = $this-minMoney;
//当x1,x2,x3都是1的时候(竖线)
if($x1 == $x2$x2 == $x3)
{
// '/_\'三?形状的线性?程
推荐阅读
- python常用的6种数据类型,python常用的基本数据类型
- 主板机械硬盘怎么加硬盘,主板如何安装机械硬盘
- jsbutton调用action,js button onclick
- 软件毕业设计总结语,软件类毕业设计
- linux命令中的df linux命令中的选项分为
- 苹果视频怎么加密ios13,苹果视频怎么加密ios13
- 设计公司如何制作ppt,设计公司怎么设计
- 如何进虎牙直播张大仙,虎牙张大仙直播间怎么参与抽奖
- vbnet面向对象编程 net面向对象