|
@@ -11,6 +11,7 @@ use PHPExcel;
|
|
use PHPExcel_IOFactory;
|
|
use PHPExcel_IOFactory;
|
|
use statistics\refill_balance;
|
|
use statistics\refill_balance;
|
|
use statistics\stat_refill;
|
|
use statistics\stat_refill;
|
|
|
|
+use Log;
|
|
|
|
|
|
class handler
|
|
class handler
|
|
{
|
|
{
|
|
@@ -296,35 +297,26 @@ class handler
|
|
};
|
|
};
|
|
|
|
|
|
$start_time = time();
|
|
$start_time = time();
|
|
- $percentor = function ($total_stage, $cur_stage,$used_time) use ($start_time)
|
|
|
|
|
|
+ $percentor = function ($total_stage, $cur_stage) use ($start_time)
|
|
{
|
|
{
|
|
$task_id = $this->mTtaskId;
|
|
$task_id = $this->mTtaskId;
|
|
- $expected_time = 0;
|
|
|
|
- $expected_curtime = time();
|
|
|
|
- $mod_task = Model('task');
|
|
|
|
|
|
+ $total_used = time() - $start_time;
|
|
|
|
+ $remain = $total_used * ($total_stage - $cur_stage) / $cur_stage;
|
|
|
|
+ $remain = intval($remain);
|
|
|
|
|
|
- if(!empty($task_id)){
|
|
|
|
- if($cur_stage === 0) {
|
|
|
|
- $now = time();
|
|
|
|
- if($now == $expected_curtime) {
|
|
|
|
- $expected_time = 10;
|
|
|
|
- }else{
|
|
|
|
- $expected_time = ($now - $expected_curtime) * ($total_stage / $cur_stage);
|
|
|
|
- }
|
|
|
|
- $expected_time = date("Y-m-d H:i:s", ($now + $expected_time));
|
|
|
|
|
|
+ $expected_time = date("H:i:s", (time() + $remain));
|
|
|
|
|
|
- }
|
|
|
|
- $cur_stage++;
|
|
|
|
- $stage = "导出进度:{$cur_stage}/{$total_stage}, 预计完成时间:{$expected_time}";
|
|
|
|
- $mod_task->where(['task_id' => $task_id])->update(['stage' => $stage]);
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ $mod_task = Model('task');
|
|
|
|
+ $stage = "导出进度:{$cur_stage}/{$total_stage}, 预计完成时间:{$expected_time}";
|
|
|
|
+ $mod_task->where(['task_id' => $task_id])->update(['stage' => $stage]);
|
|
};
|
|
};
|
|
|
|
|
|
- $reader = $order_reader($normal_cond,$time_scope);
|
|
|
|
|
|
|
|
$stage = 0;
|
|
$stage = 0;
|
|
$execl_index = 0;
|
|
$execl_index = 0;
|
|
- $cur_start = time();
|
|
|
|
|
|
+
|
|
|
|
+ $reader = $order_reader($normal_cond,$time_scope);
|
|
foreach ($reader as $result)
|
|
foreach ($reader as $result)
|
|
{
|
|
{
|
|
[$items,$total_stage,$cur_stage] = $result;
|
|
[$items,$total_stage,$cur_stage] = $result;
|
|
@@ -333,15 +325,13 @@ class handler
|
|
$execl_writer($order,$execl_index);
|
|
$execl_writer($order,$execl_index);
|
|
$execl_index += 1;
|
|
$execl_index += 1;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ Log::record("total_stage={$total_stage} cur_stage={$cur_stage}",Log::DEBUG);
|
|
if($stage == 0) {
|
|
if($stage == 0) {
|
|
$stage = $cur_stage;
|
|
$stage = $cur_stage;
|
|
}
|
|
}
|
|
elseif($stage != $cur_stage) {
|
|
elseif($stage != $cur_stage) {
|
|
- $cur_end = time();
|
|
|
|
- $percentor($total_stage,$stage,$cur_end - $cur_start);
|
|
|
|
|
|
+ $percentor($total_stage,$stage);
|
|
$stage = $cur_stage;
|
|
$stage = $cur_stage;
|
|
- $cur_start = $cur_end;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -354,11 +344,12 @@ class handler
|
|
|
|
|
|
$file_path = $path . $filename;
|
|
$file_path = $path . $filename;
|
|
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
|
|
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
|
|
-
|
|
|
|
$objWriter->save($file_path);
|
|
$objWriter->save($file_path);
|
|
|
|
+
|
|
|
|
+
|
|
return [true, $filename];
|
|
return [true, $filename];
|
|
} catch (Exception $e) {
|
|
} catch (Exception $e) {
|
|
-
|
|
|
|
|
|
+ Log::record($e->getMessage(),Log::ERR);
|
|
return [false, false];
|
|
return [false, false];
|
|
}
|
|
}
|
|
}
|
|
}
|