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
197aed22
authored
Aug 30, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修复逻辑上的问题
parent
0c6a0e6d
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
43 deletions
.env
app/Http/Controllers/UserExchangesController.php
app/Models/Code.php
app/Models/IntegralBill.php
routes/web.php
storage/laravels.json
storage/laravels.pid
.env
View file @
197aed22
...
...
@@ -11,6 +11,15 @@ DB_USERNAME=ic_welfare
DB_PASSWORD=ic_welfare#zsyM
DB_PREFIX=ic_
#ic_data数据库的配置
IC_DATA_DB_HOST_R=192.168.2.232
IC_DATA_DB_HOST_W=192.168.2.232
IC_DATA_DB_PORT=3306
IC_DATA_DB_DATABASE=ic_data
IC_DATA_DB_USERNAME=ic_data
IC_DATA_DB_PASSWORD=ic_data#zsyM
IC_DATA_DB_PREFIX=ic_
CACHE_DRIVER=file
QUEUE_DRIVER=sync
...
...
app/Http/Controllers/UserExchangesController.php
View file @
197aed22
...
...
@@ -105,58 +105,64 @@ class UserExchangesController extends Controller
}
//用于抢兑换名额
public
function
create
(
Request
$request
){
$Field
=
[
'user_id'
,
'exchange_id'
];
public
function
create
(
Request
$request
)
{
$Field
=
[
'user_id'
,
'exchange_id'
];
$collert
=
$request
->
only
(
$Field
);
$Redis
=
new
RedisModel
();
//先判断客户今天是否抢到名额
$time
=
date
(
'Ymd'
);
$Pre
=
'ic_exchanges_quota_'
.
$time
;
$Record
=
$Redis
->
hget
(
$Pre
,
$collert
[
'user_id'
]);
$Pre
=
'ic_exchanges_quota_'
.
$time
;
$Record
=
$Redis
->
hget
(
$Pre
,
$collert
[
'user_id'
]);
if
(
$Record
)
return
$this
->
Export
(
ErrorCode
(
100
,
1
),
'今天已经兑换过来,请明天再来吧'
);
if
(
$Record
)
{
return
$this
->
Export
(
ErrorCode
(
100
,
1
),
'今天已经兑换过来,请明天再来吧'
);
}
//获取用户红包
$UserInfo
=
$Redis
->
hget
(
'ic_user'
,
$collert
[
'user_id'
]);
$UserInfo
=
$Redis
->
hget
(
'ic_user'
,
$collert
[
'user_id'
]);
$UserInfo
=
json_decode
(
$UserInfo
,
true
);
if
(
empty
(
$UserInfo
[
'integral'
]))
return
$this
->
Export
(
ErrorCode
(
102
,
1
)
,
'红包余额不足'
);
$UserInfo
=
json_decode
(
$UserInfo
,
true
);
if
(
empty
(
$UserInfo
[
'integral'
]))
{
return
$this
->
Export
(
ErrorCode
(
102
,
1
),
'红包余额不足'
);
}
//获取红包配置
$ic_exchange_settings
=
json_decode
(
$Redis
->
hget
(
'ic_exchange_settings'
,
$collert
[
'exchange_id'
])
,
true
);
$ic_exchange_settings
=
json_decode
(
$Redis
->
hget
(
'ic_exchange_settings'
,
$collert
[
'exchange_id'
])
,
true
);
//判断红包提现设置是否可用
if
(
!
$ic_exchange_settings
||
$ic_exchange_settings
[
'status'
]
!=
1
)
return
$this
->
Export
(
ErrorCode
(
103
,
1
)
,
'当前提现不可用'
);
if
(
!
$ic_exchange_settings
||
$ic_exchange_settings
[
'status'
]
!=
1
)
{
return
$this
->
Export
(
ErrorCode
(
103
,
1
),
'当前提现不可用'
);
}
//判断用余额
if
(
$ic_exchange_settings
[
'amount'
]
>
$UserInfo
[
'integral'
])
return
$this
->
Export
(
ErrorCode
(
102
,
1
)
,
'红包余额不足'
);
if
(
$ic_exchange_settings
[
'amount'
]
>
$UserInfo
[
'integral'
])
{
return
$this
->
Export
(
ErrorCode
(
102
,
1
),
'红包余额不足'
);
}
//消费名额
$Cahce
=
$Redis
->
rpop
(
'ic_exchange_settings_'
.
$collert
[
'exchange_id'
]);
if
(
!
$Cahce
)
return
$this
->
Export
(
ErrorCode
(
101
,
1
),
'名额被抢光了'
);
$Cahce
=
json_decode
(
$Cahce
,
true
);
$Cahce
=
$Redis
->
rpop
(
'ic_exchange_settings_'
.
$collert
[
'exchange_id'
]);
if
(
!
$Cahce
)
{
return
$this
->
Export
(
ErrorCode
(
101
,
1
),
'名额被抢光了'
);
}
$Cahce
=
json_decode
(
$Cahce
,
true
);
//记录当前消费的名额,自动过期
$Redis
->
hset
(
$Pre
,
$collert
[
'user_id'
]
,
$collert
[
'exchange_id'
]);
$Redis
->
expire
(
$Pre
,
60
*
60
*
24
);
$Redis
->
hset
(
$Pre
,
$collert
[
'user_id'
]
,
$collert
[
'exchange_id'
]);
$Redis
->
expire
(
$Pre
,
60
*
60
*
24
);
try
{
try
{
DB
::
beginTransaction
();
//扣减用户金额
$UserIntrgralModel
=
new
UserIntegral
();
$result
=
$UserIntrgralModel
->
Deduction
(
$collert
[
'user_id'
]
,
$ic_exchange_settings
[
'amount'
]);
$result
=
$UserIntrgralModel
->
Deduction
(
$collert
[
'user_id'
],
$ic_exchange_settings
[
'amount'
]);
if
(
!
$result
)
{
ErrorLog
(
ErrorCode
(
1
,
9
),
'扣减用户红包失败,用户ID:'
.
$collert
[
'user_id'
]);
throw
new
\Exception
(
'扣减用户红包失败,用户ID:'
.
$collert
[
'user_id'
]);
if
(
!
$result
)
{
ErrorLog
(
ErrorCode
(
1
,
9
),
'扣减用户红包失败,用户ID:'
.
$collert
[
'user_id'
]);
throw
new
\Exception
(
'扣减用户红包失败,用户ID:'
.
$collert
[
'user_id'
]);
}
//添加红包记录
...
...
@@ -165,13 +171,13 @@ class UserExchangesController extends Controller
'user_id'
=>
$collert
[
'user_id'
],
'type'
=>
$ic_exchange_settings
[
'type'
],
'exchange_id'
=>
$ic_exchange_settings
[
'id'
],
'amount'
=>
$ic_exchange_settings
[
'amount'
]
'amount'
=>
$ic_exchange_settings
[
'amount'
],
];
$result
=
$UserExchangeModel
->
addRecord
(
$data
);
if
(
!
$result
)
{
$Errinfo
=
'红包提现记录添加失败'
.
$collert
[
'user_id'
];
ErrorLog
(
ErrorCode
(
1
,
9
),
$Errinfo
);
if
(
!
$result
)
{
$Errinfo
=
'红包提现记录添加失败'
.
$collert
[
'user_id'
];
ErrorLog
(
ErrorCode
(
1
,
9
),
$Errinfo
);
throw
new
\Exception
(
$Errinfo
);
}
...
...
@@ -180,23 +186,25 @@ class UserExchangesController extends Controller
//扣减缓存里面的红包金额
$UserInfo
[
'integral'
]
=
$UserInfo
[
'integral'
]
-
$ic_exchange_settings
[
'amount'
];
$Redis
->
hset
(
'ic_user'
,
$UserInfo
[
'user_id'
]
,
json_encode
(
$UserInfo
));
$Redis
->
hset
(
'ic_user'
,
$UserInfo
[
'user_id'
]
,
json_encode
(
$UserInfo
));
//金额小于20元时,推送一个异步任务(用来提现或者充值),延时10秒,防止主从同步不及时
if
(
$data
[
'amount'
]
<
20
&&
$data
[
'type'
]
==
1
)
{
$Task
=
new
ExchangesTask
(
$data
,
$ic_exchange_settings
);
if
(
$data
[
'amount'
]
<
20
)
{
$Task
=
new
ExchangesTask
(
$data
,
$ic_exchange_settings
);
$Task
->
delay
(
10
);
$result
=
Task
::
deliver
(
$Task
);
if
(
!
$result
)
ErrorLog
(
ErrorCode
(
1
,
9
),
'提现任务推送失败,提现ID:'
.
$data
[
'id'
]);
if
(
!
$result
)
{
ErrorLog
(
ErrorCode
(
1
,
9
),
'提现任务推送失败,提现ID:'
.
$data
[
'id'
]);
}
}
return
$this
->
Export
(
0
,
'ok'
,[
'data'
=>
$data
[
'id'
]]);
return
$this
->
Export
(
0
,
'ok'
,
[
'data'
=>
$data
[
'id'
]]);
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
DB
::
rollBack
();
SendErrMsg
(
$e
);
return
$this
->
Export
(
ErrorCode
(
100
,
5
),
'提现失败'
);
return
$this
->
Export
(
ErrorCode
(
100
,
5
),
'提现失败'
);
}
}
}
\ No newline at end of file
app/Models/Code.php
View file @
197aed22
...
...
@@ -24,6 +24,10 @@ class Code extends Model
$exist
=
$redis
->
sismember
(
'ic_welfare_code_limit'
,
$userId
);
//如果是存在的话,代表这个人已经输入过红包码,就返回false
if
(
$exist
)
{
//需要记录一下这种奇怪的请求,因为如果兑换过一次之后,前端那边是不会有界面显示兑换的了
//所以如果出现这个已经兑换过还过来兑换的情况,可能是有人用http请求想刷红包
Log
::
error
(
"疑似刷红包码兑换,用户Id是
$userId
,红包码是
$code
"
);
return
false
;
}
else
{
//还要去判断这个code的主人今天的被兑换次数是否超过限额
...
...
app/Models/IntegralBill.php
View file @
197aed22
...
...
@@ -46,6 +46,7 @@ class IntegralBill extends Model
}
//这是一个比较重要的方法,这个方法关系着需不需要插入红包获取流水
//data里面必须有user_id,integral_id和add_time三个键值
public
function
createIntegralBill
(
$data
=
[])
{
$integralId
=
$data
[
'integral_id'
];
...
...
routes/web.php
View file @
197aed22
...
...
@@ -15,9 +15,6 @@ use App\Tasks\IntegralBillTask;
use
Hhxsv5\LaravelS\Swoole\Task\Task
;
$router
->
get
(
'/'
,
function
()
use
(
$router
)
{
$task
=
new
\App\Tasks\TestTask
();
$task
->
delay
(
30
);
$result
=
Task
::
deliver
(
$task
);
return
$router
->
app
->
version
();
});
...
...
@@ -60,6 +57,7 @@ $router->post('/exchange_settings/batchUpdateStatus', 'ExchangeSettingsControlle
//用户兑换记录
$router
->
post
(
'/user_exchanges/info'
,
'UserExchangesController@show'
);
$router
->
post
(
'/user_exchanges/add'
,
'UserExchangesController@store'
);
$router
->
post
(
'/user_exchanges/audit'
,
'UserExchangesController@audit'
);
$router
->
post
(
'/user_exchanges/list'
,
'UserExchangesController@index'
);
$router
->
post
(
'/user_exchanges/update'
,
'UserExchangesController@update'
);
...
...
storage/laravels.json
View file @
197aed22
This diff is collapsed.
Click to expand it.
storage/laravels.pid
View file @
197aed22
16308
\ No newline at end of file
2364
\ No newline at end of file
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