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
a5739cf1
authored
Aug 26, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完善并且修复添加流水的异步任务
parent
95e814ff
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
37 deletions
app/Http/Controllers/IntegralBillsController.php
app/Models/IntegralBill.php
app/Models/UserIntegral.php
app/Tasks/IntegralBillTask.php
routes/web.php
storage/laravels.json
storage/laravels.pid
app/Http/Controllers/IntegralBillsController.php
View file @
a5739cf1
...
...
@@ -38,7 +38,7 @@ class IntegralBillsController extends Controller
* @param IntegralBill $integralBill
* @return array
*/
public
function
creat
e
(
Request
$request
,
IntegralBill
$integralBill
)
public
function
stor
e
(
Request
$request
,
IntegralBill
$integralBill
)
{
$data
=
[
'user_id'
=>
$request
->
user_id
,
...
...
app/Models/IntegralBill.php
View file @
a5739cf1
...
...
@@ -6,6 +6,8 @@ namespace App\Models;
use
App\Http\Filters\IntegralBillFilter
;
use
App\Http\Filters\QueryFilter
;
use
App\Tasks\IntegralBillTask
;
use
Hhxsv5\LaravelS\Swoole\Task\Task
;
use
http\Env\Request
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Support\Facades\DB
;
...
...
@@ -47,6 +49,15 @@ class IntegralBill extends Model
$res
=
DB
::
table
(
'integral_bills'
)
->
insert
(
$data
);
return
$res
;
// public function addIntegralBill($userId,$integralId)
// {
// $task = new IntegralBillTask($data);
// $result = Task::deliver($task);
// if (!$result) {
// return false;
// }
// }
}
//更新用户红包兑换列表
...
...
app/Models/UserIntegral.php
View file @
a5739cf1
...
...
@@ -22,6 +22,13 @@ class UserIntegral extends Model
return
$filters
->
apply
(
$query
);
}
public
function
addUserIntegral
(
$data
=
[])
{
$result
=
DB
::
table
(
'user_integrals'
)
->
insert
(
$data
);
return
$result
;
}
public
function
getUserIntegralList
(
$page
,
$pageSize
,
$filter
)
{
$settings
=
UserIntegral
::
filter
(
$filter
)
...
...
app/Tasks/IntegralBillTask.php
View file @
a5739cf1
...
...
@@ -40,31 +40,45 @@ class IntegralBillTask extends Task
throw
new
\Exception
(
"插入用户红包账单失败,用户id是
$userId
,兑换类型id是
$integralId
"
);
}
//先判断user_integrals表里面存不存在这条记录,如果不存在的话,要初始化一条记录
$userIntegral
=
new
UserIntegral
();
$data
=
(
array
)
$userIntegral
->
getUserIntegral
(
$userId
);
if
(
$data
)
{
//将用户的累计可兑换金额写进redis里面的ic_user里面去
$integral
=
new
Integral
();
$res
=
$integral
->
getIntegral
(
$integralId
);
$amount
=
$res
->
amount
;
if
(
!
$data
)
{
$data
=
[
'user_id'
=>
$userId
,
'status'
=>
1
,
'add_time'
=>
$this
->
data
[
'add_time'
],
];
$result
=
$userIntegral
->
addUserIntegral
(
$data
);
if
(
!
$result
)
{
throw
new
\Exception
(
"初始化用户红包详情失败,用户id是
$userId
"
);
}
}
//将用户的累计可兑换金额写进redis里面的ic_user里面去
$integral
=
new
Integral
();
$res
=
$integral
->
getIntegral
(
$integralId
);
if
(
!
$res
)
{
throw
new
\Exception
(
"获取红包信息失败,红包id是
$integralId
"
);
}
$amount
=
$res
->
amount
;
$redis
=
new
RedisModel
();
$user
=
json_decode
(
$redis
->
hget
(
'ic_user'
,
$userId
),
true
);
$user
[
'integral'
]
=
$data
[
'integral'
]
+
$amount
;
$result
=
$redis
->
hset
(
'ic_user'
,
$userId
,
json_encode
(
$user
));
//还要写进user_integrals数据库
if
(
$result
!==
false
)
{
$data
=
[
'integral'
=>
$data
[
'integral'
]
+
$amount
,
'update_time'
=>
time
(),
];
$result
=
$userIntegral
->
updateUserIntegralByUserId
(
$userId
,
$data
);
if
(
!
$result
)
{
throw
new
\Exception
(
"更新用户剩余积分失败,用户id是
$userId
,兑换类型id是
$integralId
"
);
}
}
else
{
throw
new
\Exception
(
"更新redis里ic_user的integral失败,用户id是
$userId
,兑换类型id是
$integralId
"
);
$redis
=
new
RedisModel
();
$user
=
json_decode
(
$redis
->
hget
(
'ic_user'
,
$userId
),
true
);
$data
=
(
array
)
$userIntegral
->
getUserIntegral
(
$userId
);
$user
[
'integral'
]
=
$data
[
'integral'
]
+
$amount
;
$result
=
$redis
->
hset
(
'ic_user'
,
$userId
,
json_encode
(
$user
));
//还要写进user_integrals数据库
if
(
$result
!==
false
)
{
$data
=
[
'integral'
=>
$data
[
'integral'
]
+
$amount
,
'update_time'
=>
time
(),
];
$result
=
$userIntegral
->
updateUserIntegralByUserId
(
$userId
,
$data
);
if
(
!
$result
)
{
throw
new
\Exception
(
"更新用户剩余积分失败,用户id是
$userId
,兑换类型id是
$integralId
"
);
}
}
else
{
throw
new
\Exception
(
"更新redis里ic_user的integral失败,用户id是
$userId
,兑换类型id是
$integralId
"
);
}
});
}
catch
(
\Exception
$e
)
{
...
...
routes/web.php
View file @
a5739cf1
...
...
@@ -19,7 +19,7 @@ $router->get('/key', function () {
return
str_random
(
32
);
});
//
积分
信息
//
红包
信息
$router
->
post
(
'/integrals/list'
,
'IntegralsController@index'
);
$router
->
post
(
'/integrals/info'
,
'IntegralsController@show'
);
$router
->
post
(
'/integrals/add'
,
'IntegralsController@create'
);
...
...
@@ -28,20 +28,13 @@ $router->post('/integrals/updateStatus', 'IntegralsController@updateStatus');
$router
->
post
(
'/integrals/delete'
,
'IntegralsController@destroy'
);
$router
->
post
(
'/integrals/batchUpdateStatus'
,
'IntegralsController@batchUpdateStatus'
);
//积分类型
$router
->
post
(
'/integral_types/list'
,
'IntegralTypesController@index'
);
$router
->
post
(
'/integral_types/add'
,
'IntegralTypesController@create'
);
$router
->
post
(
'/integral_types/update'
,
'IntegralTypesController@update'
);
$router
->
post
(
'/integral_types/delete'
,
'IntegralTypesController@destroy'
);
//用户积分账单
//用户红包流水
$router
->
post
(
'/integral_bills/list'
,
'IntegralBillsController@index'
);
$router
->
post
(
'/integral_bills/add'
,
'IntegralBillsController@
creat
e'
);
$router
->
post
(
'/integral_bills/add'
,
'IntegralBillsController@
stor
e'
);
$router
->
post
(
'/integral_bills/update'
,
'IntegralBillsController@update'
);
$router
->
post
(
'/integral_bills/delete'
,
'IntegralBillsController@destroy'
);
//用户
积分
信息
//用户
红包
信息
$router
->
post
(
'/user_integrals/info'
,
'UserIntegralsController@show'
);
$router
->
post
(
'/user_integrals/list'
,
'UserIntegralsController@index'
);
$router
->
post
(
'/user_integrals/updateStatus'
,
'UserIntegralsController@updateStatus'
);
...
...
@@ -49,8 +42,6 @@ $router->post('/user_integrals/batchUpdateStatus', 'UserIntegralsController@batc
$router
->
post
(
'/user_integrals/updateExchangedIntegral'
,
'UserIntegralsController@updateExchangedIntegral'
);
$router
->
post
(
'/user_integrals/statistics'
,
'UserIntegralsController@statistics'
);
//兑换配置
$router
->
post
(
'/exchange_settings/info'
,
'ExchangeSettingsController@show'
);
$router
->
post
(
'/exchange_settings/list'
,
'ExchangeSettingsController@index'
);
...
...
@@ -74,3 +65,4 @@ $router->post('/rob/exchange/quota', 'ExchangeController@create');
//用户签到
$router
->
post
(
'/check_in/list'
,
'CheckInController@index'
);
$router
->
post
(
'/check_in/add'
,
'CheckInController@store'
);
storage/laravels.json
View file @
a5739cf1
This diff is collapsed.
Click to expand it.
storage/laravels.pid
View file @
a5739cf1
23914
\ No newline at end of file
478
\ 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