krgm.so-manager-dev.com/app/Services/UserService.php

56 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 App\Services;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
/**
* 利用者取得サービス
* - 旧テーブル互換のまま、画面用の取得口を一本化する
*/
class UserService
{
/**
* ユーザーSEQで1件取得旧互換
*/
public function findBySeq(int $userSeq): ?object
{
return \App\Legacy\User::find($userSeq);
}
/**
* 画面検索条件でページング旧User::searchの最小互換
*/
public function paginate(array $inputs): LengthAwarePaginator
{
$query = \App\Legacy\User::query();
if (!empty($inputs['user_id'])) {
$query->where('user_id', 'like', '%'.$inputs['user_id'].'%');
}
if (!empty($inputs['member_id'])) {
$query->where('member_id', 'like', '%'.$inputs['member_id'].'%');
}
if (!empty($inputs['user_tag_serial'])) {
$query->where('user_tag_serial', 'like', '%'.$inputs['user_tag_serial'].'%');
}
if (!empty($inputs['user_phonetic'])) {
$query->where('user_phonetic', 'like', '%'.$inputs['user_phonetic'].'%');
}
if (!empty($inputs['phone'])) {
$phone = $inputs['phone'];
$query->where(function ($q) use ($phone) {
$q->where('user_mobile', 'like', '%'.$phone.'%')
->orWhere('user_homephone', 'like', '%'.$phone.'%');
});
}
$sort = $inputs['sort'] ?? 'user_seq';
$dir = $inputs['sort_type'] ?? 'desc';
return $query->orderBy($sort, $dir)->paginate(\App\Utils::item_per_page);
}
}