58 lines
2.0 KiB
PHP
58 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Exports\Sheets;
|
|
|
|
use App\Models\Order;
|
|
use App\Models\Server\MerchantUser;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
|
use Maatwebsite\Excel\Concerns\WithEvents;
|
|
use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
|
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
|
use Maatwebsite\Excel\Events\AfterSheet;
|
|
|
|
class SaasActiveUser implements FromCollection, WithTitle
|
|
{
|
|
protected $start_date, $end_date;
|
|
public function __construct($start_date, $end_date)
|
|
{
|
|
$this->start_date = $start_date;
|
|
$this->end_date = $end_date;
|
|
}
|
|
public function collection()
|
|
{
|
|
$start_date = $this->start_date;
|
|
$end_date = $this->end_date;
|
|
Log::info($start_date.'---'.$end_date);
|
|
$users = MerchantUser::with("mpUser.profileCourtship","mUserProfile")->whereBetween('authorize_at', [$start_date, $end_date])->get();
|
|
$rows = [
|
|
["ID", "姓名", "联系电话", "是否有过消费", "常住地"]
|
|
];
|
|
foreach ($users as $user) {
|
|
$has_order = $user->orders()->where("merchant_id", 491)->where("pay_status", "<>", 0)->where("price", ">", 0)->count()?"有":"无";
|
|
$mp_user = $user->mpUser;
|
|
$mp_profile = $user->mpUser?$user->mpUser->profileCourtship:null;
|
|
$merchant_profile = $user->mUserProfile;
|
|
$profile = $merchant_profile?:$mp_profile;
|
|
$province = $profile?$profile->province:"";
|
|
$city = $profile?$profile->city:"";
|
|
$nickname = $mp_user?$mp_user->nickname:$user->nickname;
|
|
$mobile = $mp_user?$mp_user->mobile:$user->mobile;
|
|
$rows[] = [$user->id, $nickname, $mobile, $has_order, $province."-".$city];
|
|
}
|
|
return collect($rows);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function title(): string
|
|
{
|
|
return 'saas用户';
|
|
}
|
|
}
|