本文整理汇总了PHP中Maatwebsite\Excel\Facades\Excel::batch方法的典型用法代码示例。如果您正苦于以下问题:PHP Excel::batch方法的具体用法?PHP Excel::batch怎么用?PHP Excel::batch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Maatwebsite\Excel\Facades\Excel
的用法示例。
在下文中一共展示了Excel::batch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
DB::table('locations')->truncate();
$location = [['name' => 'Myanmar', 'pcode' => 'MMR', 'type' => 'country', 'lat' => 16.799999, 'long' => 96.150002, 'mya_name' => 'မြန်မာ', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]];
Location::buildTree($location);
//$files = [
// 'locations/Myanmar/Ayeyarwady.csv'
// ];
/**
$files = 'locations/Myanmar';
$excel = Excel::batch($files, function($rows, $file) {
$this->rows[$rows->title] = $rows->each(function($row) {});
});
$nested_set = $this->locations->merge_excel_import($this->rows);
$parent = Location::where('pcode', '=', 'MMR')->first();
//dd($parent->location);
$imported = $parent->makeTree($nested_set); // => true
*
*/
$files = 'locations/Myanmar';
$excel = Excel::batch($files, function ($rows, $file) {
$i = 5000;
Excel::filter('chunk')->load($file)->chunk(5000, function ($results) use($file, &$i) {
$row = $this->locations->arrayToNestedSet('MMR', $results);
echo "{$i} rows completed\n";
return $i += 5000;
});
echo $file . "completed\n";
//$parent = Location::where('pcode', '=', 'MMR')->first();
//$imported = $parent->makeTree($nested_set_children);
});
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
}
示例2: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
global $NotFounf, $NewReimbursement, $Progress, $FolderName, $Date;
$password = $this->ask('Enter the password');
if ($password == ACCESS) {
$FolderName = $this->ask('Enter the name of the folder you want to import');
if ($this->confirm('Are you sure to import the folder ' . $FolderName . '? [y|N]') && $FolderName) {
// ini_set('upload_max_filesize', '99999M');
// ini_set('post_max_size', '99999M');
ini_set('memory_limit', '-1');
ini_set('max_execution_time', '-1');
ini_set('max_input_time', '-1');
set_time_limit('-1');
$time_start = microtime(true);
$this->info("Importing...\n");
$Progress = $this->output->createProgressBar();
$Progress->setFormat("%current%/%max% [%bar%] %percent:3s%%");
Excel::batch('public/file_to_import/' . $FolderName . '/', function ($rows, $file) {
$rows->each(function ($result) {
global $NotFounf, $NewReimbursement, $Progress, $FolderName, $Date;
// ini_set('upload_max_filesize', '9999M');
// ini_set('post_max_size', '9999M');
ini_set('memory_limit', '-1');
ini_set('max_execution_time', '-1');
ini_set('max_input_time', '-1');
set_time_limit('-1');
$month_year = Carbon::createFromDate(Util::formatYear($result->a_o), Util::zero($result->mes), 1)->toDateString();
$Date = Util::zero($result->mes) . "-" . Util::formatYear($result->a_o);
$affiliate = Affiliate::where('identity_card', '=', Util::zero($result->car))->first();
if (!$affiliate) {
$affiliate = Affiliate::where('last_name', '=', $result->pat)->where('mothers_last_name', '=', $result->mat)->where('birth_date', '=', $result->nac)->where('date_entry', '=', $result->ing)->where('identity_card', '=', Util::RepeatedIdentityCard($result->car))->first();
}
if ($affiliate) {
if (Util::decimal($result->sue) != 0) {
$reimbursement = Reimbursement::where('month_year', '=', $month_year)->where('affiliate_id', '=', $affiliate->id)->first();
if (!$reimbursement) {
$reimbursement = new Reimbursement();
$reimbursement->user_id = 1;
$reimbursement->affiliate_id = $affiliate->id;
$reimbursement->month_year = $month_year;
$reimbursement->base_wage = Util::decimal($result->sue);
$reimbursement->seniority_bonus = Util::decimal($result->cat);
$reimbursement->study_bonus = Util::decimal($result->est);
$reimbursement->position_bonus = Util::decimal($result->carg);
$reimbursement->border_bonus = Util::decimal($result->fro);
$reimbursement->east_bonus = Util::decimal($result->ori);
$reimbursement->gain = Util::decimal($result->gan);
$reimbursement->payable_liquid = Util::decimal($result->pag);
$reimbursement->quotable = (double) $reimbursement->base_wage + (double) $reimbursement->seniority_bonus + (double) $reimbursement->study_bonus + (double) $reimbursement->position_bonus + (double) $reimbursement->border_bonus + (double) $reimbursement->east_bonus;
$reimbursement->total = Util::decimal($result->mus);
$percentage = round($reimbursement->total / $reimbursement->quotable * 100, 1);
if ($percentage == 2.5) {
$reimbursement->retirement_fund = $reimbursement->total * 1.85 / $percentage;
$reimbursement->mortuary_quota = $reimbursement->total * 0.65 / $percentage;
}
$reimbursement->save();
$NewReimbursement++;
}
}
} else {
$NotFounf++;
}
$Progress->advance();
});
});
$time_end = microtime(true);
$execution_time = ($time_end - $time_start) / 60;
$NewReimbursement = $NewReimbursement ? $NewReimbursement : "0";
$NotFounf = $NotFounf ? $NotFounf : "0";
$Progress->finish();
$this->info("\n\nReport {$Date}:\n\n\n {$NewReimbursement} new reimbursements.\n\n {$NotFounf} affiliate not found .\n\n Execution time {$execution_time} [minutes].\n");
\Storage::disk('local')->put($Date . '.txt', "\n\nReport:\n\n\n {$NewReimbursement} new reimbursements.\n\n {$NotFounf} affiliate not found .\n\n Execution time {$execution_time} [minutes].\n");
}
} else {
$this->error('Incorrect password!');
}
}
示例3: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
global $NewAffi, $UpdateAffi, $NewContri, $Progress, $FolderName, $Date;
$password = $this->ask('Enter the password');
if ($password == ACCESS) {
$FolderName = $this->ask('Enter the name of the folder you want to import');
if ($this->confirm('Are you sure to import the folder "' . $FolderName . '" ? [y|N]') && $FolderName) {
$time_start = microtime(true);
$this->info("Working...\n");
$Progress = $this->output->createProgressBar();
$Progress->setFormat("%current%/%max% [%bar%] %percent:3s%%");
Excel::batch('public/file_to_import/' . $FolderName . '/', function ($rows, $file) {
$rows->each(function ($result) {
global $NewAffi, $UpdateAffi, $NewContri, $Progress, $FolderName, $Date;
ini_set('memory_limit', '-1');
ini_set('max_execution_time', '-1');
ini_set('max_input_time', '-1');
set_time_limit('-1');
if (!isset($result->car) or !isset($result->pat) or !isset($result->mat) or !isset($result->nom) or !isset($result->nom2) or !isset($result->apes) or !isset($result->eciv) or !isset($result->sex) or !isset($result->nac) or !isset($result->ing) or !isset($result->mes) or !isset($result->a_o) or !isset($result->uni) or !isset($result->desg) or !isset($result->niv) or !isset($result->gra) or !isset($result->item) or !isset($result->sue) or !isset($result->cat) or !isset($result->est) or !isset($result->carg) or !isset($result->fro) or !isset($result->ori) or !isset($result->bseg) or !isset($result->dfu) or !isset($result->nat) or !isset($result->lac) or !isset($result->pre) or !isset($result->sub) or !isset($result->gan) or !isset($result->afp) or !isset($result->pag) or !isset($result->nua) or !isset($result->mus)) {
$this->error('Missing columns in the file!');
exit;
}
switch ($FolderName) {
case 'c1':
$first_name = Util::FirstName($result->nom);
$second_name = Util::SecondName($result->nom);
$birth_date = Util::dateDDMMAA($result->nac);
$date_entry = Util::dateDDMMAA($result->ing);
break;
case 'c2':
$first_name = Util::FirstName($result->nom);
$second_name = Util::SecondName($result->nom);
$birth_date = Util::dateAAMMDD($result->nac);
$date_entry = Util::dateAAMMDD($result->ing);
break;
case 'c3':
$first_name = Util::FirstName($result->nom);
$second_name = Util::SecondName($result->nom);
$birth_date = Util::dateAADDMM($result->nac);
$date_entry = Util::dateAADDMM($result->ing);
break;
case 'c4':
$first_name = $result->nom;
$second_name = $result->nom2;
$birth_date = Util::dateAAMMDD($result->nac);
$date_entry = Util::dateAAMMDD($result->ing);
break;
case 'c5':
$first_name = $result->nom;
$second_name = $result->nom2;
$birth_date = Util::dateDDMMAA($result->nac);
$date_entry = Util::dateDDMMAA($result->ing);
break;
default:
$first_name = $result->nom;
$second_name = $result->nom2;
$birth_date = Util::date($result->nac);
$date_entry = Util::date($result->ing);
}
$Date = Util::zero($result->mes) . "-" . Util::formatYear($result->a_o);
$month_year = Carbon::createFromDate(Util::formatYear($result->a_o), Util::zero($result->mes), 1)->toDateString();
if (is_null($result->desg)) {
$result->desg = 0;
}
$breakdown_id = Breakdown::select('id')->where('code', $result->desg)->first()->id;
if ($breakdown_id == 1) {
$unit_id = Unit::select('id')->where('breakdown_id', 1)->where('code', '20190')->first()->id;
} elseif ($breakdown_id == 2) {
$unit_id = Unit::select('id')->where('breakdown_id', 2)->where('code', '20190')->first()->id;
} elseif ($breakdown_id == 3) {
$unit_id = Unit::select('id')->where('breakdown_id', 3)->where('code', '20190')->first()->id;
} else {
if (Unit::select('id')->where('breakdown_id', $breakdown_id)->where('code', $result->uni)->first()) {
$unit_id = Unit::select('id')->where('breakdown_id', $breakdown_id)->where('code', $result->uni)->first()->id;
} else {
$unit_id = Unit::select('id')->where('code', $result->uni)->first()->id;
}
}
if ($result->niv && $result->gra) {
if ($result->niv == '04' && $result->gra == '15') {
$result->niv = '03';
}
$degree_id = Degree::select('id')->where('code_level', $result->niv)->where('code_degree', $result->gra)->first()->id;
}
$category_id = Category::select('id')->where('percentage', Util::CalcCategory(Util::decimal($result->cat), Util::decimal($result->sue)))->first()->id;
$affiliate = Affiliate::where('identity_card', '=', Util::zero($result->car))->first();
if (!$affiliate) {
$affiliate = Affiliate::where('last_name', '=', $result->pat)->where('mothers_last_name', '=', $result->mat)->where('birth_date', '=', $birth_date)->where('date_entry', '=', $date_entry)->where('identity_card', '=', Util::RepeatedIdentityCard($result->car))->first();
if (!$affiliate) {
$affiliate = new Affiliate();
$affiliate->identity_card = Util::zero($result->car);
$affiliate->gender = $result->sex;
$NewAffi++;
} else {
$UpdateAffi++;
//.........这里部分代码省略.........