Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
ic_welfare_api
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
ffd5d364
authored
Sep 04, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加红包码验证以及返回相关的信息到接口
parent
879343bf
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
2 deletions
app/Http/Controllers/CodesController.php
app/Http/Controllers/Controller.php
app/Services/InviteService.php
config/language.php
routes/web.php
app/Http/Controllers/CodesController.php
View file @
ffd5d364
...
...
@@ -4,6 +4,7 @@
namespace
App\Http\Controllers
;
use
App\Services\CodeService
;
use
Common\Model\RedisModel
;
use
Illuminate\Http\Request
;
/**
...
...
@@ -14,6 +15,8 @@ use Illuminate\Http\Request;
class
CodesController
extends
Controller
{
const
INTEGRAL_TYPE_CODE
=
3
;
/**
* 兑换红包码
* @param Request $request
...
...
@@ -25,6 +28,8 @@ class CodesController extends Controller
$code
=
$request
->
get
(
'code'
);
if
(
empty
(
$code
))
{
return
$this
->
Export
(
self
::
INVALID_PARAMETER
);
}
elseif
(
!
$this
->
checkCode
(
$code
))
{
return
$this
->
Export
(
self
::
INVALID_CODE
);
}
$data
=
[
...
...
@@ -33,10 +38,37 @@ class CodesController extends Controller
];
$result
=
$service
->
addCode
(
$data
);
if
(
$result
[
'errcode'
]
===
self
::
SUCCESS
)
{
return
$this
->
Export
(
0
,
'ok'
);
//成功之后还要返回红包码
$res
[
'data'
][
'code'
]
=
$code
;
//返回红包码能获取对应的金额
$redis
=
new
RedisModel
();
$integral
=
$redis
->
hget
(
'ic_welfare_integrals'
,
self
::
INTEGRAL_TYPE_CODE
);
$integral
=
json_decode
(
$integral
,
true
);
$amount
=
array_get
(
$integral
,
'amount'
);
$res
[
'data'
][
'amount'
]
=
$amount
;
return
$this
->
Export
(
0
,
'ok'
,
$res
);
}
else
{
return
$this
->
Export
(
self
::
EXCHANGE_CODE_FAIL
);
}
}
//检查红包码是否正确
private
function
checkCode
(
$code
)
{
//先检查是否是RDD开头
if
(
substr
(
$code
,
0
,
3
)
!==
'RDD'
)
{
return
false
;
}
//然后去redis里面取出user_id,判断是否有对应的用户
$userId
=
substr
(
$code
,
3
);
$redis
=
new
RedisModel
();
$exists
=
$redis
->
hexists
(
'ic_user'
,
$userId
);
if
(
!
$exists
)
{
return
false
;
}
return
true
;
}
}
\ No newline at end of file
app/Http/Controllers/Controller.php
View file @
ffd5d364
...
...
@@ -15,6 +15,8 @@ class Controller extends BaseController
//用户无法进行兑换,未认证
const
CAN_NOT_EXCHANGE
=
109005
;
//红包码无效
const
INVALID_CODE
=
109006
;
const
EXCHANGED_TODAY
=
109100
;
//这个是服务那边返回的错误码,代表已经超出了每日每人可领取的对应项的数额(比如每人每天只能签到一次)
...
...
app/Services/InviteService.php
View file @
ffd5d364
...
...
@@ -25,6 +25,7 @@ class InviteService extends BaseService
$result
[
'data'
]
=
array_map
(
function
(
$value
)
use
(
$userNames
,
$mobiles
)
{
$value
[
'invited_user_name'
]
=
$userNames
[
$value
[
'invited_user_id'
]];
$value
[
'invited_user_mobile'
]
=
$mobiles
[
$value
[
'invited_user_id'
]];
$value
[
'add_time'
]
=
date
(
'Y-m-d H:i'
);
return
$value
;
...
...
config/language.php
View file @
ffd5d364
...
...
@@ -13,6 +13,7 @@ return [
109003
=>
'登录失败'
,
109004
=>
'请求参数不正确'
,
109005
=>
'用户无法兑换,用户未认证'
,
109006
=>
'红包码无效'
,
109100
=>
'今天已经兑换过了,请明天再来吧'
,
109101
=>
'兑换名额被抢光了'
,
...
...
routes/web.php
View file @
ffd5d364
...
...
@@ -48,7 +48,7 @@ $router->group(['middleware' => ['web', 'login']], function () use ($router) {
$router
->
get
(
'invites/info'
,
'InvitesController@info'
);
//红包兑换
$router
->
addRoute
([
'GET'
,
'POST'
],
'codes/
exchange
'
,
'CodesController@store'
);
$router
->
addRoute
([
'GET'
,
'POST'
],
'codes/
add
'
,
'CodesController@store'
);
//好友助力
$router
->
get
(
'assists/list'
,
'AssistsController@index'
);
...
...
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