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
238877ed
authored
Sep 10, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
兑换审核添加通知
parent
638ac5f3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
2 deletions
app/Models/UserExchange.php
app/Tasks/SendNoticeTask.php
storage/laravels.json
storage/laravels.pid
app/Models/UserExchange.php
View file @
238877ed
...
...
@@ -5,7 +5,9 @@ namespace App\Models;
use
App\Http\Controllers\ExchangesTask
;
use
App\Tasks\SendNoticeTask
;
use
App\Http\Filters\QueryFilter
;
use
Hhxsv5\LaravelS\Swoole\Task\Task
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Log
;
...
...
@@ -89,8 +91,11 @@ class UserExchange extends Model
->
update
(
$data
);
if
(
!
$result
)
{
return
false
;
}
else
{
}
}
//无论是审核通过还是拒绝都要去通知用户
$this
->
sendNotice
(
$data
[
'user_id'
],
$data
[
'status'
],
$data
[
'audit_reason'
]);
return
true
;
});
...
...
@@ -99,15 +104,40 @@ class UserExchange extends Model
}
//批量拒绝用户的兑换
public
function
batchAuditRejectUserExchange
(
$ids
=
[],
$data
=
[])
{
$res
=
DB
::
table
(
'user_exchanges'
)
->
whereIn
(
'id'
,
$ids
)
->
update
(
$data
);
if
(
$res
)
{
//去通知所有被拒绝兑换的用户
//先找出所有需要被通知的user_id
$userIds
=
DB
::
table
(
'user_exchanges'
)
->
whereIn
(
'id'
,
$ids
)
->
pluck
(
'user_id'
)
->
toArray
();
foreach
(
$userIds
as
$userId
)
{
$this
->
sendNotice
(
$userId
,
-
1
,
$data
[
'audit_reason'
]);
}
}
return
$res
;
}
//审核兑换成功或者失败要触发用户通知
public
function
sendNotice
(
$userId
,
$status
,
$auditReason
)
{
$keyword
=
''
;
if
(
$status
==
1
)
{
$keyword
=
'IC_User_Exchange_Success'
;
}
elseif
(
$status
==
-
1
)
{
$keyword
=
'IC_User_Exchange_Fail'
;
}
$data
[
'audit_reason'
]
=
$auditReason
;
$task
=
new
SendNoticeTask
(
$keyword
,
$data
,
$userId
);
Task
::
deliver
(
$task
);
}
public
function
getUserExchange
(
$id
)
{
$result
=
DB
::
table
(
'user_exchanges'
)
->
where
(
'id'
,
$id
)
...
...
app/Tasks/SendNoticeTask.php
0 → 100644
View file @
238877ed
<?php
namespace
App\Tasks
;
use
Hhxsv5\LaravelS\Swoole\Task\Task
;
use
Illuminate\Support\Facades\Log
;
class
SendNoticeTask
extends
Task
{
private
$data
;
private
$PushTask
=
false
;
private
$TaskNum
;
public
function
__construct
(
$keyword
,
$data
,
$toUser
,
$TaskNum
=
1
,
$is_ignore
=
0
)
{
if
(
is_array
(
$data
))
{
$data
=
json_encode
(
$data
);
}
$this
->
data
=
[
'data'
=>
$data
,
'touser'
=>
$toUser
,
'is_ignore'
=>
$is_ignore
,
'keyword'
=>
$keyword
];
$this
->
TaskNum
=
$TaskNum
;
}
// 处理任务的逻辑,运行在Task进程中,不能投递任务
public
function
handle
()
{
// return true;
$time
=
date
(
'H'
);
if
(
20
<
$time
||
$time
<
9
)
{
//不发通知时段处理
return
true
;
}
try
{
$Url
=
config
(
'website.IC_AUTH_API'
)
.
'/hprose/HttpSendMsg'
;
$res
=
json_decode
(
reportCurl
(
$Url
,
$this
->
data
,
true
,
[
'MsgToken:fg368hjk4567wtbk8'
]),
true
);
if
(
!
isset
(
$res
[
'errcode'
])
||
$res
[
'errcode'
]
!==
0
)
{
ErrorLog
(
ErrorCode
(
001
,
9
),
'消息系统消息发送失败'
);
$this
->
PushTask
=
true
;
}
return
true
;
}
catch
(
\Exception
$e
)
{
SendErrMsg
(
$e
);
ErrorLog
(
ErrorCode
(
001
,
9
),
'消息发送出现致命错误'
);
$this
->
PushTask
=
true
;
//重试任务
}
}
public
function
finish
()
{
//消息推送失败,任务重试,第一次为4分钟后,第二次为10分钟后,第三次为18分钟后
if
(
$this
->
PushTask
===
true
&&
$this
->
TaskNum
<
4
)
{
$this
->
TaskNum
++
;
$task
=
new
SendNoticeTask
(
$this
->
data
[
'keyword'
],
$this
->
data
[
'data'
],
$this
->
data
[
'touser'
],
$this
->
TaskNum
,
$this
->
data
[
'is_ignore'
]
);
$task
->
delay
(
60
*
2
*
$this
->
TaskNum
);
Task
::
deliver
(
$task
);
}
}
}
storage/laravels.json
View file @
238877ed
This diff is collapsed.
Click to expand it.
storage/laravels.pid
View file @
238877ed
4199
\ No newline at end of file
19158
\ 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