Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
ic_server_welfare
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
da603647
authored
Aug 16, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加查询过滤器
parent
0078b858
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
3 deletions
app/Http/Controllers/IntegralsController.php
app/Http/Filters/IntegralFilter.php
app/Http/Filters/UserIntegralFilter.php
app/Models/Integral.php
app/Http/Controllers/IntegralsController.php
View file @
da603647
...
...
@@ -4,6 +4,7 @@
namespace
App\Http\Controllers
;
use
App\Http\Filters\IntegralFilter
;
use
App\Models\Integral
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\DB
;
...
...
@@ -17,11 +18,15 @@ class IntegralsController extends Controller
return
$this
->
Export
(
0
,
'ok'
,
[
'data'
=>
$integral
]);
}
public
function
index
(
Request
$request
)
public
function
index
(
Request
$request
,
IntegralFilter
$filter
)
{
$page
=
$request
->
has
(
'page'
)
?
$request
->
page
:
1
;
$page_size
=
$request
->
has
(
'page_size'
)
?
$request
->
page_size
:
10
;
$integrals
=
Integral
::
with
(
'integralType:id,name'
)
->
page
(
$request
->
page
,
$request
->
page_size
)
->
orderBy
(
'id'
,
'desc'
)
->
filter
(
$filter
)
->
page
(
$page
,
$page_size
)
->
orderBy
(
'id'
,
'desc'
)
->
get
()
->
toArray
();
$count
=
Integral
::
count
();
...
...
app/Http/Filters/IntegralFilter.php
View file @
da603647
...
...
@@ -7,4 +7,13 @@ namespace App\Http\Filters;
class
IntegralFilter
extends
QueryFilter
{
public
function
name
(
$name
)
{
return
$this
->
builder
->
where
(
'name'
,
'like'
,
"%
{
$name
}
%"
);
}
public
function
exchange_status
(
$status
=
0
)
{
return
$this
->
builder
->
where
(
'status'
,
'='
,
$status
);
}
}
\ No newline at end of file
app/Http/Filters/UserIntegralFilter.php
0 → 100644
View file @
da603647
<?php
namespace
App\Http\Filters
;
class
UserIntegralFilter
extends
QueryFilter
{
public
function
user_id
(
$user_id
=
0
)
{
return
$this
->
builder
->
where
(
'user_id'
,
'='
,
$user_id
);
}
public
function
exchange_status
(
$exchangeStatus
=
0
)
{
return
$this
->
builder
->
where
(
'exchange_status'
,
'='
,
$exchangeStatus
);
}
}
\ No newline at end of file
app/Models/Integral.php
View file @
da603647
...
...
@@ -4,6 +4,7 @@
namespace
App\Models
;
use
App\Http\Filters\QueryFilter
;
use
Illuminate\Database\Eloquent\Model
;
class
Integral
extends
Model
...
...
@@ -17,6 +18,11 @@ class Integral extends Model
return
$query
->
offset
((
$page
-
1
)
*
$pageSize
)
->
limit
(
$pageSize
);
}
public
function
scopeFilter
(
$query
,
QueryFilter
$filters
)
{
return
$filters
->
apply
(
$query
);
}
public
function
integralType
()
{
return
$this
->
belongsTo
(
IntegralType
::
class
,
'integral_type_id'
,
'id'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment