1 回答
TA贡献1893条经验 获得超10个赞
这是基于您显示的第二个代码。if()一个问题是,您总是将这一天推迟,并且您应该只在当天容量已满的第一部分执行此操作。
为了方便起见,我还在循环中预先检索了所有日期和容量,并将它们存储在以日期为键的数组中。
$today=date('Y-m-d');
$pln_qry=mysql_query("select *
from tbl_mfg_schedule
where ms_date > '".$today."'
order by ms_date") or die(mysql_error());
// Load list of days and production
$plnList = [];
while ( $pln_data=mysql_fetch_array($pln_qry) ) {
$plnList [ $pln_data['ms_date'] ] = $pln_data['ms_po_sqft'];
}
$current = reset($priorityArraySum);
$output = [];
$day = date('Y-m-d');
// Set max from production plan
$max = $plnList[ $day ];
//$max = 1700;
$dailyLeft = $max;
while (true) {
//echo $dailyLeft."</br>";
if ( $current >= $dailyLeft ) {
//$day=date('Y-m-d', strtotime($day. ' + 1 days'));
$output[] = ["priority" => key($priorityArraySum),
"amount" => $dailyLeft,
"day" => $day
];
$day=date('Y-m-d', strtotime($day. ' + 1 days'));
$current -= $dailyLeft;
// Move onto the next days capacity, if no specific value assume
// same as last ( ?? $max)
$max = $plnList[ $day ] ?? $max;
$dailyLeft = $max;
}
else {
$output[] = ["priority" => key($priorityArraySum),
"amount" => $current,
"day" => $day
];
$dailyLeft -= $current;
if ( ($current = next($priorityArraySum)) === false ) {
break;
}
}
}
echo '<pre/>';
print_r($output);
echo '<pre/>';
使用一些虚拟测试数据(请注意,缺少日期,因此假设它将与...2020-08-14相同2020-08-13
$priorityArraySum = [2000, 200, 6000, 1200];
$plnList = [ '2020-08-10' => 1700,
'2020-08-11' => 1700,
'2020-08-12' => 0,
'2020-08-13' => 500,
'2020-08-15' => 1700];
它产生...
<pre/>Array
(
[0] => Array
(
[priority] => 0
[amount] => 1700
[day] => 2020-08-10
)
[1] => Array
(
[priority] => 0
[amount] => 300
[day] => 2020-08-11
)
[2] => Array
(
[priority] => 1
[amount] => 200
[day] => 2020-08-11
)
[3] => Array
(
[priority] => 2
[amount] => 1200
[day] => 2020-08-11
)
[4] => Array
(
[priority] => 2
[amount] => 0
[day] => 2020-08-12
)
[5] => Array
(
[priority] => 2
[amount] => 500
[day] => 2020-08-13
)
[6] => Array
(
[priority] => 2
[amount] => 500
[day] => 2020-08-14
)
[7] => Array
(
[priority] => 2
[amount] => 1700
[day] => 2020-08-15
)
[8] => Array
(
[priority] => 2
[amount] => 1700
[day] => 2020-08-16
)
[9] => Array
(
[priority] => 2
[amount] => 400
[day] => 2020-08-17
)
[10] => Array
(
[priority] => 3
[amount] => 1200
[day] => 2020-08-17
)
)
- 1 回答
- 0 关注
- 73 浏览
添加回答
举报