| 1234567891011121314151617181920 |
- <?php
- declare(strict_types=1);
- namespace plugin\saiadmin\app\service;
- use plugin\saiadmin\app\model\water\WaterModel;
- use plugin\saiadmin\exception\ApiException;
- final class WaterOptions
- {
- public function listing(array $input): array
- {
- $type = (string) ($input['type'] ?? 'enterprise');
- if (!in_array($type, ['enterprise', 'sku', 'package'], true)) throw new ApiException('选项类型不支持');
- $query = WaterModel::forKind($type)->where('status', 1);
- $keyword = trim((string) ($input['keyword'] ?? ''));
- if ($keyword !== '') $query->matching('name', '%' . mb_substr($keyword, 0, 120) . '%');
- $fields = $type === 'package' ? ['id', 'name', 'sku_id', 'buckets', 'price_cents'] : ['id', 'name'];
- return $query->select($fields)->orderByDesc('id')->limit(50)->get()->toArray();
- }
- }
|