| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Services;
- use App\Services\BaseService;
- use App\Models\Admin;
- class AdminService extends BaseService
- {
- const STATUS_YES = 1; // 状态正常
- const STATUS_NOT = 0; // 状态禁用
- public static $MODEL= Admin::class;
-
- /**
- * @description: 获取查询条件
- * @param {array} $search 查询内容
- * @return {array}
- */
- public static function getWhere(array $search = []): array
- {
- $where = [];
- if (isset($search['id']) && $search['id'] !== '') {
- $where[] = ['id', '=', $search['id']];
- }
- if (isset($search['account']) && $search['account'] !== '') {
- $where[] = ['account', '=', $search['account']];
- }
- if (isset($search['nickname']) && $search['nickname'] !== '') {
- $where[] = ['nickname', 'like', '%' . $search['nickname'] . '%'];
- }
- if (isset($search['status']) && $search['status'] !== '') {
- $where[] = ['status', '=', intval($search['status'])];
- }
- return $where;
- }
- /**
- * @description: 查询单条数据
- * @param array $search
- * @return
- */
- public static function findOne(array $search)
- {
- return static::model()::where(static::getWhere($search))->first();
- }
- /**
- * @description: 查询所有数据
- * @param array $search
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public static function findAll(array $search = [])
- {
- return static::model()::where(static::getWhere($search))->get();
- }
- /**
- * @description: 分页查询
- * @param array $search
- * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
- */
- public static function paginate(array $search = [])
- {
- $limit = isset($search['limit']) ? $search['limit'] : 15;
- $paginator = static::model()::where(static::getWhere($search))
- ->orderBy('updated_at', 'desc')
- ->paginate($limit);
- return ['total' => $paginator->total(), 'data' => $paginator->items()];
- }
- }
|