CaiWuXiTong/modules/EcommerceFinance/Repositories/StoreViolationRuleRepository.php

59 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Modules\EcommerceFinance\Repositories;
use Illuminate\Database\Connection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* 店铺违规信息预警:违规字典(store_violation_rules,business_mirror)。
*/
class StoreViolationRuleRepository
{
public const TABLE = 'store_violation_rules';
private Connection $connection;
public function __construct()
{
$this->connection = DB::connection((string) config('upstream_mirrors.connection', 'business_mirror'));
}
public function available(): bool
{
return Schema::connection($this->connection->getName())->hasTable(self::TABLE);
}
/** @return list<array<string,mixed>> 启用中的规则,按 sort、id 升序 */
public function activeRules(): array
{
if (! $this->available()) {
return [];
}
return $this->connection->table(self::TABLE)
->where('enabled', true)
->orderBy('sort')
->orderBy('id')
->get()
->map(static fn (object $row): array => (array) $row)
->all();
}
/** @return list<array<string,mixed>> 全部规则(后台维护用),按 sort、id 升序 */
public function all(): array
{
if (! $this->available()) {
return [];
}
return $this->connection->table(self::TABLE)
->orderBy('sort')
->orderBy('id')
->get()
->map(static fn (object $row): array => (array) $row)
->all();
}
}