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
34ff923f
authored
Aug 21, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
审核通过后需要对剩余金额进行更新以及批量审核
parent
9b167fca
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
8 deletions
app/Http/Controllers/UserExchangesController.php
app/Models/UserExchange.php
routes/web.php
app/Http/Controllers/UserExchangesController.php
View file @
34ff923f
...
...
@@ -24,7 +24,7 @@ class UserExchangesController extends Controller
public
function
show
(
Request
$request
)
{
$id
=
$request
->
id
;
$userExchange
=
UserExchange
::
w
here
(
'user_
id'
,
$id
)
->
first
()
->
toArray
();
$userExchange
=
UserExchange
::
w
ith
(
'exchange_setting'
)
->
where
(
'
id'
,
$id
)
->
first
()
->
toArray
();
return
$this
->
Export
(
0
,
'ok'
,
[
'data'
=>
$userExchange
]);
}
...
...
@@ -40,7 +40,8 @@ class UserExchangesController extends Controller
$page
=
$request
->
has
(
'page'
)
?
$request
->
page
:
1
;
$pageSize
=
$request
->
has
(
'page_size'
)
?
$request
->
page_size
:
10
;
$userExchanges
=
UserExchange
::
filter
(
$filter
)
->
page
(
$page
,
$pageSize
)
$userExchanges
=
UserExchange
::
with
([
'exchange_setting'
,
'user_integral'
])
->
filter
(
$filter
)
->
page
(
$page
,
$pageSize
)
->
orderBy
(
'id'
,
'desc'
)
->
get
()
->
toArray
();
$count
=
UserExchange
::
filter
(
$filter
)
->
count
();
...
...
@@ -66,22 +67,52 @@ class UserExchangesController extends Controller
}
}
/**
* 审核用户的兑换
* @param Request $request
* @param UserExchange $userExchange
* @return array
*/
public
function
audit
(
Request
$request
,
UserExchange
$userExchange
)
{
$data
=
[
'audit_reason'
=>
$request
->
audit_reason
,
'audit_time'
=>
time
(),
'update_time'
=>
time
(),
'audit_id'
=>
$request
->
audit_id
,
'user_id'
=>
$request
->
user_id
,
'audit_email'
=>
$request
->
audit_email
,
'status'
=>
$request
->
status
,
];
$res
=
$userExchange
->
auditUserExchange
(
$request
->
id
,
$request
->
exchange_amount
,
$data
);
if
(
$res
)
{
return
$this
->
Export
(
0
,
'ok'
);
}
else
{
return
$this
->
Export
(
033
,
'审核用户兑换失败'
);
}
}
/**
* 批量审核
* @param Request $request
* @return array
*/
public
function
batch
UpdateStatus
(
Request
$request
)
public
function
batch
AuditReject
(
Request
$request
,
UserExchange
$userExchange
)
{
$ids
=
$request
->
ids
;
if
(
!
is_array
(
$ids
))
{
return
Log
::
Info
(
'批量修改参数不是数组'
);
}
$status
=
$request
->
status
;
$res
=
DB
::
table
(
'user_exchanges'
)
->
whereIn
(
'id'
,
$ids
)
->
update
([
'status'
=>
(
int
)
$status
,
'update_time'
=>
time
()]);
$data
=
[
'status'
=>
(
int
)
$request
->
status
,
'audit_reason'
=>
$request
->
audit_reason
,
'audit_id'
=>
$request
->
audit_id
,
'audit_email'
=>
$request
->
audit_email
,
'update_time'
=>
time
(),
];
$res
=
$userExchange
->
batchAuditRejectUserExchange
(
$ids
,
$data
);
if
(
$res
)
{
return
$this
->
Export
(
0
,
'ok'
);
}
else
{
...
...
app/Models/UserExchange.php
View file @
34ff923f
...
...
@@ -6,6 +6,7 @@ namespace App\Models;
use
App\Http\Filters\QueryFilter
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Support\Facades\DB
;
class
UserExchange
extends
Model
{
...
...
@@ -20,4 +21,59 @@ class UserExchange extends Model
{
return
$filters
->
apply
(
$query
);
}
public
function
exchange_setting
()
{
return
$this
->
hasOne
(
ExchangeSetting
::
class
,
'id'
,
'exchange_id'
);
}
public
function
user_integral
()
{
return
$this
->
belongsTo
(
UserIntegral
::
class
,
'user_id'
,
'user_id'
);
}
//审核用户的兑换
public
function
auditUserExchange
(
$id
,
$exchangedAmount
,
$data
=
[])
{
$result
=
DB
::
transaction
(
function
()
use
(
$id
,
$exchangedAmount
,
$data
)
{
//先去修改审核状态等信息
$result
=
DB
::
table
(
'user_exchanges'
)
->
where
(
'id'
,
$id
)
->
update
(
$data
);
if
(
!
$result
)
{
return
false
;
}
//兑换审核通过后,需要对用户剩余的红包金额进行对应的减少
$result
=
DB
::
table
(
'user_integrals'
)
->
where
(
'user_id'
,
$data
[
'user_id'
])
->
decrement
(
'integral'
,
$exchangedAmount
);
if
(
!
$result
)
{
return
false
;
}
//同时用户积分详情的更新时间
$result
=
DB
::
table
(
'user_integrals'
)
->
where
(
'user_id'
,
$data
[
'user_id'
])
->
update
([
'update_time'
=>
$data
[
'update_time'
]]);
if
(
!
$result
)
{
return
false
;
}
return
true
;
});
if
(
!
$result
)
{
return
false
;
}
return
true
;
}
public
function
batchAuditRejectUserExchange
(
$ids
=
[],
$data
=
[])
{
$res
=
DB
::
table
(
'user_exchanges'
)
->
whereIn
(
'id'
,
$ids
)
->
update
(
$data
);
return
$res
;
}
}
\ No newline at end of file
routes/web.php
View file @
34ff923f
...
...
@@ -60,9 +60,10 @@ $router->post('/exchange_settings/batchUpdateStatus', 'ExchangeSettingsControlle
//用户兑换记录
$router
->
post
(
'/user_exchanges/info'
,
'UserExchangesController@show'
);
$router
->
post
(
'/user_exchanges/audit'
,
'UserExchangesController@audit'
);
$router
->
post
(
'/user_exchanges/list'
,
'UserExchangesController@index'
);
$router
->
post
(
'/user_exchanges/update'
,
'UserExchangesController@update'
);
$router
->
post
(
'/user_exchanges/batch
UpdateStatus'
,
'UserExchangesController@batchUpdateStatus
'
);
$router
->
post
(
'/user_exchanges/batch
AuditReject'
,
'UserExchangesController@batchAuditReject
'
);
//抢兑换名额
$router
->
post
(
'/rob/exchange/quota'
,
'ExchangeController@create'
);
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