68 lines
2.2 KiB
PHP
68 lines
2.2 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;
|
|
class ReferrerInviteUsersExport implements FromCollection ,WithHeadings,WithStrictNullComparison,WithColumnFormatting,ShouldAutoSize
|
|
{
|
|
private $user_id;
|
|
public function __construct($user_id)
|
|
{
|
|
$this->user_id = $user_id;
|
|
}
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
'邀请人ID',
|
|
'被邀请人ID',
|
|
'姓名',
|
|
'电话',
|
|
'类型',
|
|
'是否认证',
|
|
'收益金额',
|
|
];
|
|
}
|
|
//设置列格式
|
|
public function columnFormats(): array
|
|
{
|
|
return [
|
|
'A' => NumberFormat::FORMAT_TEXT,
|
|
];
|
|
}
|
|
public function collection()
|
|
{
|
|
$data = ReferreAwardHistory::where('user_id', $this->user_id)->distinct('other_user_id')->select('user_id','other_user_id')->get()->toArray();
|
|
foreach ($data as $k => $v) {
|
|
$user = User::withTrashed()->where('id', $v['other_user_id'])->first();
|
|
$amount = ReferreAwardHistory::where('user_id', $this->user_id)->where('other_user_id', $v['other_user_id'])->where('is_hooked', 1)->sum('amount');
|
|
if (empty($user)) {
|
|
$data[$k]['name'] = '未知';
|
|
//行业
|
|
$data[$k]['mobile'] = '未知';
|
|
//子行业
|
|
$data[$k]['type'] = '未知';
|
|
//团契
|
|
$data[$k]['is_approved'] = '未知';
|
|
}else{
|
|
$data[$k]['name'] = $user->name;
|
|
$data[$k]['mobile'] = $user->mobile;
|
|
$data[$k]['type'] = $user->type=='single'?'单身':'介绍人';
|
|
$data[$k]['is_approved'] = $user->is_approved?'是':'否';
|
|
}
|
|
$data[$k]['amount'] = $amount;
|
|
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
}
|