43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Services;
|
|
|
|
use App\Models\Auth\User;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Modules\EcommerceFinance\Notifications\PinduoduoOpeningBalanceAlert;
|
|
|
|
class PinduoduoOpeningBalanceAlertNotifier
|
|
{
|
|
/**
|
|
* @param list<array{store_name:string,month:string,reason:string}> $issues
|
|
*/
|
|
public function send(array $issues): int
|
|
{
|
|
if ($issues === []) {
|
|
return 0;
|
|
}
|
|
|
|
$configuredIds = array_values(array_unique(array_filter(array_map(
|
|
static fn (mixed $value): int => (int) trim((string) $value),
|
|
explode(',', (string) config('services.jushuitan.pdd_opening_alert_user_ids', '')),
|
|
))));
|
|
$query = User::query();
|
|
if ($configuredIds !== []) {
|
|
$query->whereIn('id', $configuredIds);
|
|
}
|
|
else {
|
|
$query->whereHas('roles', static function ($roles): void {
|
|
$roles->where('name', 'super_admin');
|
|
});
|
|
}
|
|
$users = $query->get();
|
|
if ($users->isEmpty()) {
|
|
return 0;
|
|
}
|
|
|
|
Notification::send($users, new PinduoduoOpeningBalanceAlert($issues));
|
|
|
|
return $users->count();
|
|
}
|
|
}
|