Commit 238877ed by 杨树贤

兑换审核添加通知

parent 638ac5f3
......@@ -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)
......
<?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);
}
}
}
4199
\ No newline at end of file
19158
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment