- 论坛徽章:
- 0
|
刚写的代码,供参考,欢迎讨论。
<?php
class Paydate_Calculator
{
/** This function determines the first available due date following the funding of a loan.
* The paydate will be at least 10 days in the future from the $fund_day. The
* due_date will fall on a day that is a paydate based on their paydate model
* specified by '$pay_span' unless the date must be adjusted forward to miss a
* weekend or backward to miss a holiday
* Holiday adjustment takes precedence over Weekend.
*
* @param unix_timestamp $fund_day The day the loan was funded.
* @param array $holiday_array An array of unix timestamp's containing
* holidays.
* @param string $pay_span A string representing the frequency at which the
* customer is paid. (weekly,bi-weekly,monthly)
* @param unix_timestamp $pay_day A timestamp containing one of the
* customers paydays
* @param bool $direct_deposit A boolean determining whether or not the
* customer receives their paycheck via direct deposit.
* @return unix_timestamp A unix timestamp representing the determined due
* date.
*/
//$fund_day:可以理解为账单日
//$pay_day:可以理解为上次还款日
//$due_day:需要返回的本次还款日
//这几个定义可参考信用卡的每次最低还款规则
//所有参数中的unix timestamp 都默认为00:00:00时刻的值
public function Calculate_Due_Date($fund_day, $holiday_array, $pay_span, $pay_day, $direct_deposit)
{
if ($pay_span == 'bi-weekly')
{
$span_str = "+2 week";
}
else if ($pay_span == 'monthly')
{
$span_str = "+1 month";
}
else // default: $pay_span = 'weekly'
{
$span_str = "+1 week";
}
$due_day = strtotime($span_str, $pay_day); //根据上次还款日和还款间隔得出本次还款日
if (!$direct_deposit)
{
$due_day = strtotime("+1 day", $due_day);
}
$day_type = '';
while (1)
{//循环,根据非周末和非假期规则得出正确的本次还款日
if ($day_type == "weekend")
{
$due_day = strtotime("+1 day", $due_day);
}
else if ($day_type == "holiday")
{
$due_day = strtotime("-1 day", $due_day);
}
$day_type = '';
if (in_array(date("D", $due_day), array("Sat", "Sun")))
{
$day_type = "weekend";
}
else if (in_array($due_day, $holiday_array))
{
$day_type = "holiday";
}
else
{
break;
}
}
//判断本次还款日是否在账单日的十日后
$check_day = strtotime("+10 day", $fund_day);
if ($due_day < $check_day)
{//否,重复整个过程,但传递参数中的上次还款日替换为本次得到的还款日.
$pay_day = $due_day; //这里应该是$pay_day = strtotime($span_str, $pay_day);吗?
$due_day = $this->Calculate_Due_Date($fund_day, $holiday_array, $pay_span, $pay_day, $direct_deposit);
}
return $due_day;
}
}
?> |
[ 本帖最后由 wszhl 于 2008-9-11 11:05 编辑 ] |
|