67 lines
2.0 KiB
PHP
67 lines
2.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Exports;
|
||
|
|
|
||
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||
|
|
use Maatwebsite\Excel\Concerns\WithHeadings; //设置标题
|
||
|
|
|
||
|
|
use App\Models\MakerScoreLog;
|
||
|
|
use App\Models\User;
|
||
|
|
class LiveMakerCoinLog implements FromCollection,WithHeadings
|
||
|
|
{
|
||
|
|
protected $start_time;
|
||
|
|
protected $end_time;
|
||
|
|
protected $time_arr;
|
||
|
|
public function headings(): array
|
||
|
|
{
|
||
|
|
$start_time = request()->input('start_time');
|
||
|
|
$end_time = request()->input('end_time');
|
||
|
|
//开始时间 周日0点
|
||
|
|
$this->start_time = $start_time?:date('Y-m-d', strtotime('-2 sunday', time()));
|
||
|
|
//结束时间 周六23:59:59
|
||
|
|
$this->end_time = $end_time?:date('Y-m-d' , strtotime('-1 Saturday', time()));
|
||
|
|
$this->time_arr = \CommonUtilsService::daliy($start_time, $end_time);
|
||
|
|
$array = ['id','昵称', '真实姓名'];
|
||
|
|
foreach ($this->time_arr as $time) {
|
||
|
|
$array[] = $time;
|
||
|
|
}
|
||
|
|
$array[] = '剩余福币';
|
||
|
|
return $array;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return \Illuminate\Support\Collection
|
||
|
|
*/
|
||
|
|
public function collection()
|
||
|
|
{
|
||
|
|
|
||
|
|
$data = [];
|
||
|
|
$user_ids = MakerScoreLog::whereBetween('start_time', [$this->start_time, $this->end_time])->distinct()->pluck('user_id');
|
||
|
|
|
||
|
|
foreach ($user_ids as $user_id) {
|
||
|
|
$user = User::find($user_id);
|
||
|
|
if (empty($user)) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
$arr['id'] = $user->id;
|
||
|
|
$arr['nickname'] = $user->nickname;
|
||
|
|
$arr['name'] = $user->name;
|
||
|
|
$logs = MakerScoreLog::with('user.coin')->where('user_id', $user_id)->get();
|
||
|
|
foreach ($this->time_arr as $key=>$time) {
|
||
|
|
foreach ($logs as $log) {
|
||
|
|
if ($log->start_time == $time.' 00:00:00') {
|
||
|
|
$arr['coin-'.+ $key] = $log->score;
|
||
|
|
break;
|
||
|
|
}else{
|
||
|
|
$arr['coin-'.+ $key] = '0';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//剩余福币
|
||
|
|
$arr['remain_amount'] = $user->coin->remain_amount?:'0';
|
||
|
|
$data[]=$arr;
|
||
|
|
}
|
||
|
|
return collect($data);
|
||
|
|
}
|
||
|
|
}
|