|
|
@@ -0,0 +1,560 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Console\Commands;
|
|
|
+
|
|
|
+use App\Services\Api\FinanceService;
|
|
|
+use App\Services\Api\MemberService;
|
|
|
+use App\Services\Api\PledgeOrderService;
|
|
|
+use App\Services\Api\PriceLogService;
|
|
|
+use App\Services\RedisService;
|
|
|
+use Illuminate\Console\Command;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
+class SwooleTask extends Command
|
|
|
+{
|
|
|
+
|
|
|
+ protected $serv;
|
|
|
+ protected $host = '127.0.0.1';
|
|
|
+ protected $port = 6630;
|
|
|
+ // 进程名称
|
|
|
+ protected $taskName = 'swooleTask';
|
|
|
+ // PID路径
|
|
|
+ protected $pidPath = '/storage/swoole.pid';
|
|
|
+ // task
|
|
|
+ protected $onlyReloadTaskWorker = false;
|
|
|
+ // 设置运行时参数
|
|
|
+ protected $options = [
|
|
|
+ 'worker_num' => 8, //worker进程数,一般设置为CPU数的1-4倍
|
|
|
+ 'daemonize' => true, //启用守护进程
|
|
|
+ 'log_file' => '/storage/logs/swoole-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 = 'swoole:task {op}';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The console command description.
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $description = 'Swoole 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 "swoole 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 "swoole 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 直接杀
|
|
|
+ $stoSh = base_path() . '/crontab/swooleTaskStop.sh';
|
|
|
+ if (file_exists($stoSh) && function_exists('exec')) {
|
|
|
+ exec("{$stoSh}");
|
|
|
+ }
|
|
|
+
|
|
|
+ @unlink($this->pidPath);
|
|
|
+ echo "swoole 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");
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO 更新SBT每日价格
|
|
|
+ \swoole_timer_tick(180000, function ($timer) use ($serv, &$time) { // 启用定时器,每3分钟执行一次
|
|
|
+ $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:sbt_loaded')) {
|
|
|
+ $taskData = [
|
|
|
+ 'taskName' => 'UpdateSbtPrice',
|
|
|
+ 'name' => "更新SBT每日价格",
|
|
|
+ 'date' => date('Y-m-d'),
|
|
|
+ ];
|
|
|
+ $res = $serv->task($taskData);
|
|
|
+ RedisService::set('caches:task:lock:sbt_loaded', true, rand(3, 5));
|
|
|
+ echo "[Task UpdateSbtPrice {$date}] 更新SBT每日价格:{$res}\n";
|
|
|
+ } else {
|
|
|
+ echo "[Task UpdateSbtPrice {$date}] 间隔时间调用\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ // TODO 自动质押监控
|
|
|
+ \swoole_timer_tick(60000, function ($timer) use ($serv, &$time) { // 启用定时器,每1分钟执行一次
|
|
|
+ $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++;
|
|
|
+ $userList = MemberService::make()->pledgeUserList();
|
|
|
+ if ($userList) {
|
|
|
+ if (!RedisService::get('caches:task:lock:pledge_loaded')) {
|
|
|
+ foreach ($userList as $item) {
|
|
|
+ $userId = $item['id'];
|
|
|
+ if ($userId) {
|
|
|
+ $taskData = [
|
|
|
+ 'taskName' => 'PledgeAutoTrade',
|
|
|
+ 'name' => "自动质押交易",
|
|
|
+ 'params' => $item,
|
|
|
+ 'date' => date('Y-m-d'),
|
|
|
+ ];
|
|
|
+ $res = $serv->task($taskData);
|
|
|
+ echo "[Task PledgeAutoTrade {$date}] 用户[{$userId}]自动质押交易结果:{$res}\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RedisService::set('caches:task:lock:pledge_loaded', true, rand(5, 10));
|
|
|
+ } else {
|
|
|
+ echo "[Task PledgeAutoTrade {$date}] 间隔时间调用\n";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ echo "[Task PledgeAutoTrade {$date}] 暂无可自动质押交易用户\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ // TODO 检测质押订单退本,到期退本后(USDT余额足够)自动质押
|
|
|
+ \swoole_timer_tick(180000, function ($timer) use ($serv, &$time) { // 启用定时器,每3分钟执行一次
|
|
|
+ $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++;
|
|
|
+ $userList = PledgeOrderService::make()->getRefundOrderList();
|
|
|
+ if ($userList) {
|
|
|
+ if (!RedisService::get('caches:task:lock:plende_refund_loaded')) {
|
|
|
+ foreach ($userList as $item) {
|
|
|
+ $orderId = $item['id'];
|
|
|
+ $userId = $item['user_id'];
|
|
|
+ $orderNo = $item['order_no'];
|
|
|
+ if ($orderId) {
|
|
|
+ $taskData = [
|
|
|
+ 'taskName' => 'PledgeRefund',
|
|
|
+ 'name' => "质押订单自动退本",
|
|
|
+ 'params'=> $item,
|
|
|
+ 'date' => date('Y-m-d'),
|
|
|
+ ];
|
|
|
+ $res = $serv->task($taskData);
|
|
|
+ echo "[Task PledgeRefund {$date}] 用户[{$userId}]质押订单[{$orderNo}]到期退本:{$res}\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ RedisService::set('caches:task:lock:pledge_settle_loaded', true, rand(3, 5));
|
|
|
+ }else{
|
|
|
+ echo "[Task PledgeRefund {$date}] 质押订单到期退本调用间隔\n";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ echo "[Task PledgeRefund {$date}] 间隔时间调用\n";
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // TODO 质押订单到期结算收益,同时发放奖励(质押收益、推荐奖、管理奖、平级奖-基于管理奖)
|
|
|
+ \swoole_timer_tick(120000, function ($timer) use ($serv, &$time) { // 启用定时器,每120秒执行一次
|
|
|
+ $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++;
|
|
|
+ $userList = PledgeOrderService::make()->getSettleOrderList();
|
|
|
+ if ($userList) {
|
|
|
+ if (!RedisService::get('caches:task:lock:pledge_settle_loaded')) {
|
|
|
+ foreach ($userList as $item) {
|
|
|
+ $orderId = $item['id'];
|
|
|
+ $userId = $item['user_id'];
|
|
|
+ $orderNo = $item['order_no'];
|
|
|
+ if ($orderId) {
|
|
|
+ $taskData = [
|
|
|
+ 'taskName' => 'PledgeSettle',
|
|
|
+ 'name' => "质押订单到期结算",
|
|
|
+ 'params'=> $item,
|
|
|
+ 'date' => date('Y-m-d'),
|
|
|
+ ];
|
|
|
+ $res = $serv->task($taskData);
|
|
|
+ echo "[Task PledgeSettle {$date}] 用户[{$userId}]质押订单[{$orderNo}]到期结算:{$res}\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ RedisService::set('caches:task:lock:pledge_settle_loaded', true, rand(3, 5));
|
|
|
+ }else{
|
|
|
+ echo "[Task PledgeSettle {$date}] 质押订单到期结算调用间隔\n";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ echo "[Task PledgeSettle {$date}] 间隔时间调用\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ // TODO 更新用户等级
|
|
|
+ \swoole_timer_tick(60000, function ($timer) use ($serv, &$time) { // 启用定时器,每5分钟执行一次
|
|
|
+ $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++;
|
|
|
+ $userList = MemberService::make()->getUpgradeUserList();
|
|
|
+ if ($userList) {
|
|
|
+ if (!RedisService::get('caches:task:lock:upgrade_loaded')) {
|
|
|
+ foreach ($userList as $item) {
|
|
|
+ $userId = $item['id'];
|
|
|
+ if ($userId) {
|
|
|
+ $taskData = [
|
|
|
+ 'taskName' => 'UpgradeUpdate',
|
|
|
+ 'name' => "用户等级更新",
|
|
|
+ 'params' => $item,
|
|
|
+ 'date' => date('Y-m-d'),
|
|
|
+ ];
|
|
|
+ $taskId = $serv->task($taskData);
|
|
|
+ echo "[Task UpgradeUpdate-{$taskId} {$date}] 用户[{$userId}]用户等级更新处理\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RedisService::set('caches:task:lock:upgrade_loaded', true, rand(5, 10));
|
|
|
+ } else {
|
|
|
+ echo "[Task UpgradeUpdate {$date}] 间隔时间调用\n";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ echo "[Task UpgradeUpdate {$date}] 暂无需要更新等级用户\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ // 开发者维护收益结算
|
|
|
+ \swoole_timer_tick(180000, function ($timer) use ($serv, &$time) { // 启用定时器,每3分钟执行一次
|
|
|
+ $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++;
|
|
|
+ $userList = MemberService::make()->getDeveloperList();
|
|
|
+ if ($userList) {
|
|
|
+ if (!RedisService::get('caches:task:lock:developer_loaded')) {
|
|
|
+ foreach ($userList as $item) {
|
|
|
+ $id = $item['id'];
|
|
|
+ $walletUrl = $item['wallet_url'];
|
|
|
+ if ($walletUrl) {
|
|
|
+ $taskData = [
|
|
|
+ 'taskName' => 'DeveloperSettle',
|
|
|
+ 'name' => "开发者维护收益结算",
|
|
|
+ 'params' => $item,
|
|
|
+ 'date' => date('Y-m-d'),
|
|
|
+ ];
|
|
|
+ $taskId = $serv->task($taskData);
|
|
|
+ echo "[Task DeveloperSettle-{$taskId} {$date}] 开发者[{$id}]用户维护收益结算处理\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RedisService::set('caches:task:lock:developer_loaded', true, rand(5, 10));
|
|
|
+ } else {
|
|
|
+ echo "[Task DeveloperSettle {$date}] 间隔时间调用\n";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ echo "[Task DeveloperSettle {$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'] : [];
|
|
|
+ try {
|
|
|
+ switch ($taskName) {
|
|
|
+ case 'UpdateSbtPrice': // 更新SBT每日价格
|
|
|
+ // 时间限制
|
|
|
+ if (date('H:i') >= '06:00') {
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 不在运行时间段内\n";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用处理
|
|
|
+ if ($res = PriceLogService::make()->updateSbtPrice()) {
|
|
|
+ $res = is_array($res) && $res ? json_encode($res, 256) : '处理成功';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 更新SBT每日价格:{$res}\n";
|
|
|
+ } else {
|
|
|
+ $error = PriceLogService::make()->getError();
|
|
|
+ $error = $error ? lang($error) : '处理失败';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 更新SBT每日价格:{$error}\n";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'PledgeAutoTrade': // 自动质押处理
|
|
|
+ // 调用处理
|
|
|
+ $userId = isset($params['id'])? $params['id'] : 0;
|
|
|
+ if ($res = PledgeOrderService::make()->autoMakeOrder($params)) {
|
|
|
+ $res = is_array($res) && $res ? json_encode($res, 256) : '处理成功';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 用户[{$userId}]自动质押交易处理结果:{$res}\n";
|
|
|
+ } else {
|
|
|
+ $error = PledgeOrderService::make()->getError();
|
|
|
+ $error = $error ? lang($error) : '处理失败';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 用户[{$userId}]自动质押交易处理结果:{$error}\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 'PledgeRefund': // 质押订单退本,退本后自动再质押处理
|
|
|
+ // 调用处理
|
|
|
+ $userId = isset($params['user_id'])? $params['user_id'] : 0;
|
|
|
+ $orderId = isset($params['id'])? $params['id'] : 0;
|
|
|
+ $orderNo = isset($params['order_no'])? $params['order_no'] : '';
|
|
|
+ if ($res = PledgeOrderService::make()->refund($orderId,$orderNo, $userId)) {
|
|
|
+ $res = is_array($res) && $res ? json_encode($res, 256) : '处理成功';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 用户[{$userId}]质押订单[{$orderNo}]退本处理成功:{$res}\n";
|
|
|
+ } else {
|
|
|
+ $error = PledgeOrderService::make()->getError();
|
|
|
+ $error = $error ? lang($error) : '处理失败';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 用户[{$userId}]质押订单[{$orderNo}]退本处理失败:{$error}\n";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'PledgeSettle': // 质押订单到期结算,和收益、奖励结算
|
|
|
+ // 调用处理
|
|
|
+ $userId = isset($params['user_id'])? $params['user_id'] : 0;
|
|
|
+ $orderId = isset($params['id'])? $params['id'] : 0;
|
|
|
+ $orderNo = isset($params['order_no'])? $params['order_no'] : '';
|
|
|
+ if ($res = PledgeOrderService::make()->orderSettle($orderId,$orderNo,$userId)) {
|
|
|
+ $res = is_array($res) && $res ? json_encode($res, 256) : '处理成功';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 用户[{$userId}]质押订单[{$orderNo}]收益结算成功:{$res}\n";
|
|
|
+ } else {
|
|
|
+ $error = PledgeOrderService::make()->getError();
|
|
|
+ $error = $error ? lang($error) : '处理失败';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 用户[{$userId}]质押订单[{$orderNo}]收益结算失败:{$error}\n";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'UpgradeUpdate': // 用户等级更新
|
|
|
+ // 调用处理
|
|
|
+ $userId = isset($params['id'])? $params['id'] : 0;
|
|
|
+ if ($res = MemberService::make()->upgradeUpdate($userId)) {
|
|
|
+ $res = is_array($res) && $res ? json_encode($res, 256) : '处理成功';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 用户[{$userId}]等级更新处理结果:{$res}\n";
|
|
|
+ } else {
|
|
|
+ $error = MemberService::make()->getError();
|
|
|
+ $error = $error ? lang($error) : '处理失败';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 用户[{$userId}]等级更新处理结果:{$error}\n";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'DeveloperSettle': // 维护收益结算
|
|
|
+ // 调用处理
|
|
|
+ $id = isset($params['id'])? $params['id'] : 0;
|
|
|
+ $walletUrl = isset($params['wallet_url'])? $params['wallet_url'] : '';
|
|
|
+ if ($res = FinanceService::make()->developerSettle($id, $walletUrl)) {
|
|
|
+ $res = is_array($res) && $res ? json_encode($res, 256) : '处理成功';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 开发者[{$id}]维护收益结算处理结果:{$res}\n";
|
|
|
+ } else {
|
|
|
+ $error = MemberService::make()->getError();
|
|
|
+ $error = $error ? lang($error) : '处理失败';
|
|
|
+ echo "[Task {$taskName}-{$task_id} {$date}] 开发者[{$id}]维护收益结算处理结果:{$error}\n";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ return $exception->getMessage();
|
|
|
+ }
|
|
|
+
|
|
|
+ return '暂无任务处理';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $serv swoole_server swoole_server对象
|
|
|
+ * @param $task_id int 任务id
|
|
|
+ * @param $data string 任务返回的数据
|
|
|
+ */
|
|
|
+ public function onFinish(\Swoole\Server $serv, $task_id, $data)
|
|
|
+ {
|
|
|
+ //
|
|
|
+ echo "任务[{$task_id}]处理完成...\n";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 监听连接关闭事件
|
|
|
+ public function onClose($serv, $fd, $from_id)
|
|
|
+ {
|
|
|
+ echo "Client {$fd} close connection\n";
|
|
|
+ $serv->close();
|
|
|
+ }
|
|
|
+}
|