This commit is contained in:
2022-05-04 15:41:02 +08:00
commit c76a1850a1
766 changed files with 201246 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Admin\Actions;
use App\Models\Vote;
use Encore\Admin\Actions\Action;
use Illuminate\Http\Request;
use PhpOffice\PhpWord\TemplateProcessor;
class ExportDeng extends Action
{
public $name = '批量导入';
protected $vote;
protected $selector = '.export-deng';
public function handle(Request $request)
{
$templateProcessor = new TemplateProcessor(storage_path('app/public/DENG_E.docx'));
$vote1 = Vote::find(1);
$templateProcessor->setValue('TOTAL1', $vote1->logs()->distinct('user_id')->count());
foreach ($vote1->items as $item) {
$templateProcessor->setValue('ITEM_' . $item->id, $item->logs()->sum('result'));
}
$vote3 = Vote::find(3);
$templateProcessor->setValue('TOTAL3', $vote1->logs()->distinct('user_id')->count());
foreach ($vote3->items as $item) {
$templateProcessor->setValue('ITEM_' . $item->id, $item->logs()->sum('result'));
}
$save = 'denge_1.docx';
$templateProcessor->saveAs(storage_path('app/public/' . $save));
return $this->response()->success('倒出成功')->download('/storage/' . $save);
}
public function html()
{
return <<<HTML
<a class="btn btn-sm btn-info export-deng"><i class="fa fa-upload"></i> 等额数据倒出</a>
HTML;
}
}