59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Exports;
|
||
|
|
|
||
|
|
use Maatwebsite\Excel\Concerns\WithHeadings; //设置标题
|
||
|
|
use Maatwebsite\Excel\Concerns\WithStrictNullComparison; //为空时零填充
|
||
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize; //自动单元格尺寸
|
||
|
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat; //设置单元格数据格式
|
||
|
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||
|
|
use App\Models\Referre;
|
||
|
|
use App\Models\Wechat;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Models\ReferreAwardHistory;
|
||
|
|
use Illuminate\Support\Collection;
|
||
|
|
class ReferreExport implements FromCollection ,WithHeadings,WithStrictNullComparison,WithColumnFormatting,ShouldAutoSize
|
||
|
|
{
|
||
|
|
private $data;
|
||
|
|
public function __construct($data)
|
||
|
|
{
|
||
|
|
$this->data = $data;
|
||
|
|
}
|
||
|
|
public function headings(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'姓名',
|
||
|
|
'邀请人openid',
|
||
|
|
'第一周邀请人数',
|
||
|
|
'其他周邀请人数',
|
||
|
|
'总邀请人数',
|
||
|
|
'额外奖励',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
//设置列格式
|
||
|
|
public function columnFormats(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'A' => NumberFormat::FORMAT_TEXT,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
public function collection()
|
||
|
|
{
|
||
|
|
// dd($this->referres);
|
||
|
|
// $data = ReferreAwardHistory::where('user_id', $this->user_id)->distinct('other_user_id')->select('user_id','other_user_id')->get();
|
||
|
|
// $data = $this->referres;
|
||
|
|
// foreach ($data as $k => $v) {
|
||
|
|
// $data[$k]['name'] = $v['name'];
|
||
|
|
// $data[$k]['openid'] = $v['openid'];
|
||
|
|
// $data[$k]['first_week_count'] = $v['first_week_count'];
|
||
|
|
// $data[$k]['other_week_count'] = $v['other_week_count'];
|
||
|
|
// $data[$k]['bonus_count'] = $v['bonus_count'];
|
||
|
|
// $data[$k]['award'] = $v['award'];
|
||
|
|
// }
|
||
|
|
// dd($data);
|
||
|
|
$data = collect($this->data);
|
||
|
|
return $data;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|