59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?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();
|
||
}
|
||
}
|