wesmiler 2 years ago
parent
commit
6ce933c322

+ 1 - 1
app/Console/Commands/SocketServer.php

@@ -27,7 +27,7 @@ class SocketServer extends Command
      *
      * @var string
      */
-    protected $description = 'websocket server run';
+    protected $description = 'Chat server run';
 
     protected $logger = null;
 

+ 2 - 28
app/Console/Commands/SwooleTask.php

@@ -2,11 +2,8 @@
 
 namespace App\Console\Commands;
 
-use App\Services\Api\BonusService;
 use App\Services\RedisService;
 use Illuminate\Console\Command;
-use App\Services\Hapi\IssueService;
-use App\Services\Hapi\LotteryService;
 use Illuminate\Support\Facades\DB;
 
 class SwooleTask extends Command
@@ -14,7 +11,7 @@ class SwooleTask extends Command
 
     protected $serv;
     protected $host = '127.0.0.1';
-    protected $port = 6621;
+    protected $port = 6622;
     // 进程名称
     protected $taskName = 'swooleTask';
     // PID路径
@@ -227,29 +224,7 @@ class SwooleTask extends Command
             file_put_contents($this->options['log_file'],"Task {$date}:清空日志\n");
         }
 
-       \swoole_timer_tick(10000, function ($timer) use ($serv, &$time) { // 启用定时器,每10秒执行一次
-            $date = date('Y-m-d H:i:s');
-            if($time>3600 && file_exists($this->options['log_file'])){
-                $time = 0;
-                file_put_contents($this->options['log_file'],"Task {$date}:清空日志\n");
-            }
-            $time++;
-            if(!RedisService::get('caches:task:lock:wallet_loaded')){
-                $taskData = [
-                    'taskName' => 'listenWallet',
-                    'name' => "平台钱包地址监控",
-                    'date' => date('Y-m-d'),
-                ];
-                $res = $serv->task($taskData);
-                RedisService::set('caches:task:lock:wallet_loaded', true, rand(3,5));
-                echo "[Task listenWallet {$date}] 平台钱包地址监控处理完成:{$res}\n";
-            }else{
-                echo "[Task listenWallet {$date}] 间隔时间调用\n";
-            }
-
-        });
-
-        \swoole_timer_tick(180000, function ($timer) use ($serv, &$time) { // 启用定时器,每120秒执行一次
+        \swoole_timer_tick(300000, function ($timer) use ($serv, &$time) { // 启用定时器,每300秒执行一次
             $date = date('Y-m-d H:i:s');
             if($time>3600 && file_exists($this->options['log_file'])){
                 $time = 0;
@@ -318,7 +293,6 @@ class SwooleTask extends Command
                 }
                 break;
             case 'bgmMusic':
-
                 break;
         }
 

+ 338 - 0
app/Console/Commands/WalletTask.php

@@ -0,0 +1,338 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Services\RedisService;
+use App\Services\WalletService;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\DB;
+
+class WalletTask extends Command
+{
+
+    protected $serv;
+    protected $host = '127.0.0.1';
+    protected $port = 6626;
+    // 进程名称
+    protected $taskName = 'walletTask';
+    // PID路径
+    protected $pidPath = '/storage/wallet.pid';
+    // task
+    protected $onlyReloadTaskWorker = false;
+    // 设置运行时参数
+    protected $options = [
+        'worker_num' => 8, //worker进程数,一般设置为CPU数的1-4倍
+        'daemonize' => true, //启用守护进程
+        'log_file' => '/storage/logs/wallet-task.log', //指定swoole错误日志文件
+        'log_level' => 0, //日志级别 范围是0-5,0-DEBUG,1-TRACE,2-INFO,3-NOTICE,4-WARNING,5-ERROR
+        'dispatch_mode' => 1, //数据包分发策略,1-轮询模式
+        'task_worker_num' => 6, //task进程的数量
+        'task_ipc_mode' => 3, //使用消息队列通信,并设置为争抢模式
+    ];
+
+
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'wallet:task {op}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Wallet task server description';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * 入口
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        ini_set("default_socket_timeout", -1);
+        // 项目根目录
+        defined('ROOT_PATH') or define('ROOT_PATH', base_path());
+
+        // 文件上传目录
+        defined('ATTACHMENT_PATH') or define('ATTACHMENT_PATH', base_path('public/uploads'));
+
+        // 图片上传目录
+        defined('IMG_PATH') or define('IMG_PATH', base_path('public/uploads/images'));
+
+        // 临时存放目录
+        defined('UPLOAD_TEMP_PATH') or define('UPLOAD_TEMP_PATH', ATTACHMENT_PATH . "/temp");
+
+        // 定义普通图片域名
+        defined('IMG_URL') or define('IMG_URL', env('IMG_URL'));
+
+        // 数据表前缀
+        defined('DB_PREFIX') or define('DB_PREFIX', DB::connection()->getTablePrefix());
+
+        $this->options['log_file'] = base_path() . $this->options['log_file'];
+        $this->pidPath = base_path() . $this->pidPath;
+        $op = $this->argument('op');
+        switch ($op) {
+            case 'status': // 状态
+                $res = $this->status();
+                echo $res ? $res : 0;
+                break;
+            case 'start': // 运行
+                return $this->start();
+                break;
+            case 'reload': // 平滑重启
+                return $this->reload();
+                break;
+            case 'stop': // 停止运行
+                return $this->stop();
+                break;
+            default:
+                exit("{$op} command does not exist");
+                break;
+        }
+    }
+
+    /**
+     * 启动
+     */
+    public function start()
+    {
+        date_default_timezone_set('PRC');
+        // 构建Server对象,监听对应地址
+        $this->serv = new \Swoole\Server($this->host, $this->port);
+        $this->serv->set($this->options);
+
+        // 注册事件
+        $this->serv->on('start', [$this, 'onStart']);
+        $this->serv->on('receive', [$this, 'onReceive']);
+        $this->serv->on('task', [$this, 'onTask']);
+        $this->serv->on('finish', [$this, 'onFinish']);
+
+        // Run worker
+        echo "wallet start...\n";
+        $this->serv->start();
+
+    }
+
+    // 安全重启
+    public function reload()
+    {
+
+        $pids = file_exists($this->pidPath) ? file_get_contents($this->pidPath) : '';
+        $pids = $pids ? explode("\n", $pids) : [];
+        $masterPid = isset($pids[0]) ? $pids[0] : '';
+        $managePid = isset($pids[1]) ? $pids[1] : '';
+        if (empty($masterPid)) {
+            return false;
+        }
+
+        if (!$this->status($masterPid)) {
+            return false;
+        }
+
+        \Swoole\Process::kill($managePid, SIGUSR1);
+
+        echo "wallet reload...\n";
+    }
+
+    /**
+     * 停止
+     * @param bool $smooth
+     * @return bool
+     */
+    public function stop($smooth = false)
+    {
+        $pids = file_exists($this->pidPath) ? file_get_contents($this->pidPath) : '';
+        $pids = $pids ? explode("\n", $pids) : [];
+        $masterPid = isset($pids[0]) ? $pids[0] : '';
+        $managePid = isset($pids[1]) ? $pids[1] : '';
+        if (empty($masterPid)) {
+            return false;
+        }
+
+        if (!$this->status($masterPid)) {
+            return false;
+        }
+
+        if ($smooth) {
+            \Swoole\Process::kill($masterPid, SIGTERM);
+            try {
+                while (true) {
+                    \Swoole\Process::kill($masterPid, 0);
+                }
+            } catch (\Exception $exception) {
+
+            }
+        } else {
+            \Swoole\Process::kill($masterPid, SIGKILL);
+        }
+
+        if($managePid){
+            \Swoole\Process::kill($managePid, SIGKILL);
+        }
+
+        // 直接杀
+        if(function_exists('exec')){
+            exec('pkill -9 php artisan wallet:task start');
+        }
+
+        @unlink($this->pidPath);
+        echo "wallet stop...\n";
+    }
+
+    /**
+     * 状态
+     * @return mixed
+     */
+    public function status($masterPid = 0)
+    {
+        $res = false;
+        if (empty($masterPid) && file_exists($this->pidPath)) {
+            $pids = file_get_contents($this->pidPath);
+            $pids = $pids ? explode("\n", $pids) : [];
+            $masterPid = isset($pids[0]) ? $pids[0] : '';
+        }
+
+        if ($masterPid) {
+            $res = \Swoole\Process::kill($masterPid, 0);
+        }
+        return $res;
+    }
+
+    public function onStart($serv)
+    {
+        if (!is_dir(dirname($this->pidPath))) {
+            @mkdir(dirname($this->pidPath), true, 755);
+        }
+
+        //记录进程id,脚本实现自动重启
+        $pid = "{$serv->master_pid}\n{$serv->manager_pid}";
+        file_put_contents($this->pidPath, $pid);
+
+        // 定时任务
+        $time = 0;
+        $date = date('Y-m-d H:i:s');
+        if(file_exists($this->options['log_file'])){
+            $time = 0;
+            file_put_contents($this->options['log_file'],"Task {$date}:清空日志\n");
+        }
+
+       \swoole_timer_tick(20000, function ($timer) use ($serv, &$time) { // 启用定时器,每20秒执行一次
+            $date = date('Y-m-d H:i:s');
+            if($time>7200 && file_exists($this->options['log_file'])){
+                $time = 0;
+                file_put_contents($this->options['log_file'],"Task {$date}:清空日志\n");
+            }
+            $time++;
+            $wallets = WalletService::make()->getWalletList();
+            if($wallets){
+                if(!RedisService::get('caches:task:lock:wallet_loaded')){
+                    foreach ($wallets as $item){
+                        $taskData = [
+                            'taskName' => 'listenWallet',
+                            'name' => "平台钱包地址监控",
+                            'params' => $item,
+                            'date' => date('Y-m-d'),
+                        ];
+                        $res = $serv->task($taskData);
+                    }
+                    RedisService::set('caches:task:lock:wallet_loaded', true, rand(3,5));
+                    echo "[Task listenWallet {$date}] 平台钱包地址监控调用完成:{$res}\n";
+                }else{
+                    echo "[Task listenWallet {$date}] 间隔时间调用\n";
+                }
+            }else{
+                echo "[Task listenWallet {$date}] 钱包地址未配置\n";
+            }
+
+
+        });
+
+    }
+
+    //监听连接进入事件
+    public function onConnect($serv, $fd, $from_id)
+    {
+        $serv->send($fd, "Success {$fd}!");
+    }
+
+    // 监听数据接收事件
+    public function onReceive(\Swoole\Server $serv, $fd, $from_id, $data)
+    {
+        echo "Get Message From Client {$fd}:{$data}\n";
+        $res['result'] = 'success';
+        $serv->send($fd, json_encode($res)); // 同步返回消息给客户端
+        $serv->task($data);  // 执行异步任务
+    }
+
+    /**
+     * @param \Swoole\Server $serv
+     * @param $task_id
+     * @param $from_id
+     * @param $data
+     * @return false|string
+     */
+    public function onTask(\Swoole\Server $serv, $task_id, $from_id, $data)
+    {
+
+        $date = date('Y-m-d H:i:s');
+        $taskName = isset($data['taskName']) ? $data['taskName'] : '';
+        $params = isset($data['params']) ? $data['params'] : [];
+        switch ($taskName) {
+            case 'listenWallet': // 钱包监控
+                $address = isset($params['address'])? $params['address'] : '';
+                $type = isset($params['type'])? $params['type'] : 1;
+                if(empty($address)){
+                    echo "[Task {$taskName} {$date}] address 地址参数错误\n";
+                    return false;
+                }
+
+                // 调用处理
+                if($res = WalletService::make()->listenTrcWallet($address, $type)){
+                    $success = isset($res['success'])? $res['success'] : 0;
+                    $total = isset($res['total'])? $res['total'] : 0;
+                    echo "[Task {$taskName} {$date}] 钱包地址监控处理结果:".($total? "监控{$total}条记录,成功处理{$success}条":'success')."\n";
+                }else{
+                    $error = WalletService::make()->getError();
+                    $error = $error? lang($error) : 'failed';
+                    echo "[Task {$taskName} {$date}] 钱包地址监控处理结果:{$error}\n";
+                }
+                break;
+        }
+
+        return "[Task {$taskName} {$date}] 暂无任务处理\n";
+    }
+
+
+    /**
+     * @param $serv swoole_server swoole_server对象
+     * @param $task_id int 任务id
+     * @param $data string 任务返回的数据
+     */
+    public function onFinish(\Swoole\Server $serv, $task_id, $data)
+    {
+        //
+        echo "任务处理完成...\n";
+    }
+
+
+    // 监听连接关闭事件
+    public function onClose($serv, $fd, $from_id)
+    {
+        echo "Client {$fd} close connection\n";
+        $serv->close();
+    }
+}

+ 11 - 33
app/Http/Controllers/Api/v1/MusicController.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api\v1;
 use App\Http\Controllers\Api\webApp;
 use App\Http\Validator\LiveValidator;
 use App\Services\LiveService;
+use App\Services\MusicService;
 
 /**
  * 在线直播
@@ -11,54 +12,31 @@ use App\Services\LiveService;
  */
 class MusicController extends webApp
 {
-
     /**
-     * 获取流地址
+     * 音乐列表
      * @return array
      */
-    public function getUrl()
+    public function index()
     {
-        $urls = LiveService::make()->getLiveUrl($this->userId);
-        return message(1010, true, $urls);
+        $params = request()->post();
+        $pageSize = request()->post('pageSize',20);
+        $datas = MusicService::make()->getDataList($params, $pageSize);
+        return message(1010, true, $datas);
     }
 
     /**
-     * 直播详情
+     * 音乐详情
      * @param LiveValidator $validator
      * @return array
      */
-    public function getInfo(LiveValidator $validator)
+    public function getInfo()
     {
         $params = request()->all();
-        $params = $validator->check($params, 'info');
-        if (!is_array($params)) {
-            return message($params, false);
-        }
-
-        if(!$info = LiveService::make()->getInfo($params['id'], $this->userId)){
-            return message(LiveService::make()->getError(),false);
+        if(!$info = MusicService::make()->getInfo($params['hash'])){
+            return message(MusicService::make()->getError(),false);
         }else{
             return message(1010,true, $info);
         }
     }
 
-    /**
-     * 创建直播间(开启直播)
-     * @return array
-     */
-    public function create(LiveValidator $validator)
-    {
-
-        $params = request()->all();
-        $params = $validator->check($params, 'create');
-        if (!is_array($params)) {
-            return message($params, false);
-        }
-
-        if(!$result = LiveService::make()->create($this->userId, $params)){
-            return message(LiveService::make()->getError(),false);
-        }else{
-            return message(LiveService::make()->getError(),true, $result);
-        }
-    }
 }

+ 3 - 3
app/Models/BalanceLogModel.php

@@ -32,10 +32,10 @@ class BalanceLogModel extends BaseModel
      */
     public static function checkExists($hash)
     {
-        $cacheKey = "caches:wallet:checkLog:{$hash}";
+        $cacheKey = "caches:wallet:balanceLog:{$hash}";
         $check = RedisService::get($cacheKey);
-        if($check){
-            return true;
+        if(RedisService::exists($cacheKey)){
+            return $check;
         }
 
         $info = BalanceLogModel::where(['hash'=> $hash,'mark'=>1])->first();

+ 1 - 1
app/Providers/RouteServiceProvider.php

@@ -57,7 +57,7 @@ class RouteServiceProvider extends ServiceProvider
     protected function configureRateLimiting()
     {
         RateLimiter::for('api', function (Request $request) {
-            return Limit::perMinute(env('API_RATE_LIMIT',120))->by(optional($request->user())->id ?: $request->ip());
+            return Limit::perMinute(env('API_RATE_LIMIT',150))->by(optional($request->user())->id ?: $request->ip());
         });
     }
 }

+ 23 - 4
app/Services/MusicService.php

@@ -84,6 +84,16 @@ class MusicService extends BaseService
             $len = rand(0, count($kws) - 1);
             $kw = isset($kws[$len]) ? $kws[$len] : '抖音bgm';
         }
+
+        // 取表数据
+        $datas = $this->getTableList(['kw'=> $kw], $page, $pageSize);
+        $total = isset($datas['total'])? $datas['total'] : 0;
+        $list = isset($datas['list'])? $datas['list'] : [];
+        if($total>= $pageSize){
+            return ['list'=> $list, 'kw'=> $kw,'total'=> $total];
+        }
+
+        // 取网络数据
         $url = sprintf(self::$apiUrls['search'], $kw, $page, $pageSize);
         $result = httpRequest($url, '', 'get', '', 5);
         RedisService::set($cacheKey . '_temp', ['kw' => $kw, 'result' => $result, 'date' => date('Y-m-d H:i:s')], 3600);
@@ -112,8 +122,14 @@ class MusicService extends BaseService
      * @param $pageSize
      * @return array
      */
-    public function getTableList($params, $pageSize)
+    public function getTableList($params, $page=1, $pageSize=20)
     {
+        $cacheKey = "caches:music:{$page}_{$pageSize}_".md5(json_encode($params));
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
         $list = $this->model->where(['status' => 1, 'mark' => 1])
             ->where(function ($query) use ($params) {
                 $kw = isset($params['kw']) ? trim($params['kw']) : '';
@@ -132,11 +148,14 @@ class MusicService extends BaseService
                 $item['time_text'] = $item['time'] ? date('i:s', $item['time']) : '00:00';
             }
         }
-        return [
+        $datas = [
             'pageSize' => $pageSize,
             'total' => isset($list['total']) ? $list['total'] : 0,
             'list' => isset($list['data']) ? $list['data'] : []
         ];
+
+        RedisService::set($cacheKey, $datas, rand(30, 60));
+        return $datas;
     }
 
     /**
@@ -171,12 +190,12 @@ class MusicService extends BaseService
                 'url' => $url,
             ];
 
-            RedisService::rPush('pools:music', $hash, $info);
-            RedisService::set($cacheKey, $info, 600);
+            RedisService::set($cacheKey, $info, 3600);
         }
 
         return $info;
     }
 
 
+
 }

+ 40 - 10
app/Services/WalletService.php

@@ -479,7 +479,7 @@ class WalletService extends BaseService
             $url = sprintf($this->apiUrls['transactions'], $address, $limit, $accountType==2? 'false': 'true', $accountType==2?'true':'false');
             $result = curl_get($this->config['tron_api_url'] . $url, [], $headers, 5);
             $result = $result ? json_decode($result, true) : [];
-            $datas = isset($result['data']) ? $result['data'] : [];
+            $datas = isset($result['data']) && is_array($result['data'])? $result['data'] : [];
             $status = isset($result['success']) ? $result['success'] : '';
             RedisService::set("caches:wallets:listen_{$address}", ['url' => $this->config['tron_api_url'] . $url, 'result' => $result], 7200);
             if ($status != true || empty($datas)) {
@@ -492,6 +492,7 @@ class WalletService extends BaseService
             $coinInMin = $coinInMin > 0 ? $coinInMin : 0;
             $cacheKey = "caches:wallet:listen:{$address}_{$accountType}:";
             $dateTime = date('Y-m-d H:i:s');
+            $success = 0;
             if ($datas) {
                 foreach ($datas as $v) {
                     $amount = isset($v['value']) ? intval($v['value']) : 0;
@@ -501,7 +502,7 @@ class WalletService extends BaseService
                     $ownerAddress = isset($v['from']) ? $v['from'] : '';
                     $toAddress = isset($v['to']) ? $v['to'] : '';
                     if($amount < $coinInMin) {
-                        echo "【{$dateTime} wallet】账户[{$ownerAddress}]到钱包[{$toAddress}]记录[{$txid}]金额较小不处理\n";
+                        echo "【{$dateTime} wallet】账户[{$ownerAddress}]到钱包[{$toAddress}]记录[{$txid}]金额[{$amount}],金额较小不处理\n";
                         RedisService::set($cacheKey."{$txid}:error", ['error'=>'金额较小不处理','data'=> $v], 7200);
                         continue;
                     }
@@ -509,8 +510,8 @@ class WalletService extends BaseService
                     // 充值处理
                     if($toAddress == $address && $ownerAddress && $accountType != 2){
                         if (BalanceLogModel::checkExists($txid)) {
-                            echo "【{$dateTime} recharge】账户[{$ownerAddress}]充值到钱包[{$address}]记录[{$txid}]金额[{$amount}]已处理\n";
-                            RedisService::set($cacheKey."{$txid}:error", ['error'=>'记录已处理','data'=> $v], 7200);
+                            echo "【{$dateTime} recharge】账户[{$ownerAddress}]充值到钱包[{$address}]记录[{$txid}]金额[{$amount}]交易已处理\n";
+                            RedisService::set($cacheKey."{$txid}:error", ['error'=>'交易已处理过','data'=> $v], 7200);
                             continue;
                         }
 
@@ -524,7 +525,7 @@ class WalletService extends BaseService
                         $userId = isset($memberInfo['id'])? intval($memberInfo['id']) : 0;
                         if(empty($memberInfo)){
                             echo "【{$dateTime} recharge】账户[{$ownerAddress}]充值到钱包[{$address}]记录[{$txid}]金额[{$amount}]未绑定用户\n";
-                            RedisService::set($cacheKey."{$txid}:error", ['error'=>'用户不存在','data'=> $v], 7200);
+                            RedisService::set($cacheKey."{$txid}:error", ['error'=>'未绑定用户','data'=> $v], 7200);
                             continue;
                         }
 
@@ -639,20 +640,46 @@ class WalletService extends BaseService
                         EmailService::make()->sendUserEmail($userId, $message, $coinName.'充值到账通知',3);
                         RedisService::set($cacheKey."{$txid}:success", ['error'=>'处理成功','log'=>$data,'member'=> $memberInfo,'data'=> $v], 7200);
                         echo "【{$dateTime} recharge】账户[{$ownerAddress}]充值到钱包[{$address}]记录[{$txid}]金额[{$amount}]充值成功\n";
+                        RedisService::clear("caches:wallet:balanceLog:{$txid}");
+                        $success++;
                     }
                     // 提现处理
                     else if($ownerAddress == $address && $toAddress && $accountType == 2){
+                        // 处理锁跳过
+                        if(RedisService::get($cacheKey."{$txid}:lock")){
+                            echo "【{$dateTime} withdraw】提现记录[{$txid}]金额[{$amount}]间隔时间不处理\n";
+                            RedisService::set($cacheKey."{$txid}:error", ['error'=>'间隔时间内不处理','data'=> $v], 600);
+                            continue;
+                        }
+
                         $info = BalanceLogModel::checkExists($txid);
                         $logId = isset($info['id'])?  $info['id'] : 0;
                         $userId = isset($info['user_id'])?  $info['user_id'] : 0;
                         $money = isset($info['money'])?  $info['money'] : 0;
                         $actualMoney = isset($info['actual_money'])?  $info['actual_money'] : 0;
                         $coinType = isset($info['coin_type'])?  $info['coin_type'] : 1;
+                        $payStatus = isset($info['pay_status'])?  $info['pay_status'] : 0;
+                        $status = isset($info['status'])?  $info['status'] : 0;
                         $trcUrl = isset($info['trc_url'])?  trim($info['trc_url']) : '';
                         $walletUrl = isset($info['wallet_url'])?  trim($info['wallet_url']) : '';
                         if (empty($info) || $logId<=0 || $userId<=0) {
-                            echo "【{$dateTime} withdraw】账户[{$toAddress}]从[{$address}]提现记录[{$txid}]金额[{$amount}]不存在\n";
+                            echo "【{$dateTime} withdraw】账户[{$toAddress}]从[{$address}]提现记录[{$txid}]金额[{$amount}]提现记录不存在\n";
                             RedisService::set($cacheKey."{$txid}:error", ['error'=>'提现记录不存在','data'=> $v], 7200);
+                            RedisService::set($cacheKey."{$txid}:lock", ['error'=>'提现记录不存在','data'=> $v], rand(30,60));
+                            continue;
+                        }
+
+                        if($status != 2){
+                            echo "【{$dateTime} withdraw】账户[{$toAddress}]从[{$address}]提现记录[{$txid}]金额[{$amount}]提现记录未审核\n";
+                            RedisService::set($cacheKey."{$txid}:error", ['error'=>'提现记录未审核','data'=> $v], 7200);
+                            RedisService::set($cacheKey."{$txid}:lock", ['error'=>'提现记录未审核','data'=> $v], rand(30,60));
+                            continue;
+                        }
+
+                        if($payStatus == 20){
+                            echo "【{$dateTime} withdraw】账户[{$toAddress}]从[{$address}]提现记录[{$txid}]金额[{$amount}]提现记录已打款\n";
+                            RedisService::set($cacheKey."{$txid}:error", ['error'=>'提现记录已打款','data'=> $v], 7200);
+                            RedisService::set($cacheKey."{$txid}:lock", ['error'=>'提现记录已打款','data'=> $v], rand(30,60));
                             continue;
                         }
 
@@ -666,12 +693,13 @@ class WalletService extends BaseService
                         if(abs($actualMoney - $amount) > 1){
                             echo "【{$dateTime} withdraw】账户[{$toAddress}]从[{$address}]提现记录[{$txid}]金额[{$amount}],提现金额与交易金额不匹配\n";
                             RedisService::set($cacheKey."{$txid}:error", ['error'=>'提现金额与交易金额不匹配','info'=>$info,'data'=> $v], 7200);
+                            RedisService::set($cacheKey."{$txid}:lock", ['error'=>'提现金额与交易金额不匹配','data'=> $v], rand(30,60));
                             continue;
                         }
 
                         // 更新状态
                         DB::beginTransaction();
-                        if(!BalanceLogModel::where(['id'=> $logId])->update(['status'=> 2, 'update_time'=>time()])){
+                        if(!BalanceLogModel::where(['id'=> $logId])->update(['pay_status'=> 20,'pay_at'=>$dateTime, 'update_time'=>time()])){
                             DB::rollBack();
                             echo "【{$dateTime} withdraw】账户[{$toAddress}]从[{$address}]提现记录[{$txid}]金额[{$amount}],提现状态更新失败\n";
                             RedisService::set($cacheKey."{$txid}:error", ['error'=>'提现状态更新失败','info'=>$info,'data'=> $v], 7200);
@@ -712,10 +740,12 @@ class WalletService extends BaseService
                         DB::commit();
                         $accounts = [1=>'USDT',2=>'星豆',3=>'C2C额度',4=>'佣金',5=>'商户余额'];
                         $coinName = isset($accounts[$coinType])? $accounts[$coinType] : '余额';
-                        $message = "您在 {$dateTime} (UTC+8) 从星链平台{$coinName}账户提现{$amount}成功,明细如下:<br>提现账户:{$trcUrl}<br>提现数量:{$money}<br>到账:{$total} USDT<br>单号:{$orderNo}<br>交易单号:{$txid} <a href='https://tronscan.org/#/transaction/{$txid}'>查看交易详情</a>";
+                        $message = "您在 {$dateTime} (UTC+8) 从星链平台{$coinName}账户提现{$amount}成功,明细如下:<br>提现账户:{$trcUrl}<br>提现数量:{$money}<br>到账:{$amount} USDT<br>单号:{$orderNo}<br>交易单号:{$txid} <a href='https://tronscan.org/#/transaction/{$txid}'>查看交易详情</a>";
                         EmailService::make()->sendUserEmail($userId, $message, $coinName.'提现到账通知', 3);
-                        RedisService::set($cacheKey."{$txid}:success", ['error'=>'处理成功','log'=>$info,'member'=> $memberInfo,'data'=> $v], 7200);
+                        RedisService::set($cacheKey."{$txid}:success", ['error'=>'处理成功','log'=>$log,'info'=>$info,'data'=> $v], 7200);
                         echo "【{$dateTime} withdraw】账户[{$toAddress}]从[{$address}]提现记录[{$txid}]金额[{$amount}],提现成功\n";
+                        RedisService::clear("caches:wallet:balanceLog:{$txid}");
+                        $success++;
                     }
 
                     // 处理交易记录
@@ -736,7 +766,7 @@ class WalletService extends BaseService
             }
 
             $this->error = 1010;
-            return $result;
+            return ['success'=> $success, 'total'=> count($datas)];
         } catch (\Exception $exception) {
             $message = $exception->getMessage();
             $this->error = $message;

+ 2 - 0
resources/lang/zh-cn/api.php

@@ -79,6 +79,8 @@ return [
     '2041'=> '开播成功',
     '2042'=> '开播失败',
 
+    '2207'=> '没有获取到数据',
+
     
     '我正在直播,快来看看吧'=>'我正在直播,快来看看吧',