feat: 后端全量更新 - 含所有本次需求

- Contract.php: 返回合约账户余额(balance_contract)
- My.php: 地址管理增加BTC/ETH
- AppContract.php: 一键平仓(closeall)
- AppProxy.php: 代理专属注册链接 + 分级权限(L1/L2)
- site.php: 手续费减半(0.018→0.009)
- agent_permission_setup.sql: 代理权限SQL
- crypto_news_crawler.py: 新闻自动采集脚本
This commit is contained in:
li
2026-03-30 20:16:32 +08:00
commit 1b24994e74
6721 changed files with 1308571 additions and 0 deletions
+595
View File
@@ -0,0 +1,595 @@
<?php
namespace app\api\controller;
use app\common\controller\Api;
use addons\btpanel\library\Api as Btapi;
/**
* 定时任务调度器(通过宝塔面板 API 创建系统 crontab
* 所有任务均为每分钟执行一次,部分任务内部循环 60 次以实现秒级调用
*/
class Cron extends Api
{
// 无需登录
protected $noNeedLogin = ['*'];
// 无需鉴权
protected $noNeedRight = ['*'];
// 任务名称前缀(用于宝塔面板 crontab 命名)
private $name = "exchange";
// 本站 API 基础地址
private $url = "https://jyshd.pp1008.top/api";
/**
* 批量注册所有定时任务到宝塔面板
* @return string
*/
public function run()
{
// 按日结息(按用户 ID
$this->daily_interest_by_id();
// 按日结息(按最后结息时间)
$this->daily_interest_by_lasttime();
// 重启 K 线 WebSocket 服务
$this->restart_socket();
// 超级期货平仓处理
$this->close_out_processing_super_future();
// 同步 ETH/USDT 交易数据
$this->update_syncethusdt();
// 清理周期数据
$this->cleaning_cycle_data();
// 合约限仓处理
$this->contract_limit_position();
// 合约保仓处理
$this->contract_bc();
// 合约止盈止损
$this->contract_take_profit_and_stop_loss();
// 更新团队等级
$this->update_team_rank();
// 对冲盈亏计算
$this->hedging_profit_calculation();
// 同步火币价格
$this->sync_huobi_price();
// 自动取消 C2C 过期订单
$this->automatic_cancellation_of_C2C_expired_orders();
// 天使投资释放
$this->angel_investment_release();
// 同步 BTC/USDT 交易数据
$this->update_syncbtcusdt();
// 币种撮合交易
$this->currency_matching_transaction();
// 更新市场价格
$this->update_maket_price();
return 'success';
}
/**
* 按用户 ID 执行日结息
*/
public function daily_interest_by_id()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(daily_interest_by_id)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toShell',
'sBody' => '#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for (( i = 0; i < 60; i=(i+1) )); do
curl -sS --connect-timeout 10 -m 60 "' . $this->url . '/product/set_rixi_by_id"
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
sleep 1
done
exit 0',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => '',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 按最后结息时间执行日结息
*/
public function daily_interest_by_lasttime()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(daily_interest_by_lasttime)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toShell',
'sBody' => '#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for (( i = 0; i < 60; i=(i+1) )); do
curl -sS --connect-timeout 10 -m 60 "' . $this->url . '/product/set_rixi_by_lasttime"
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
sleep 1
done
exit 0',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => '',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 重启 K 线 WebSocket 服务(每 10 分钟执行一次)
*/
public function restart_socket()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(restart_socket)',
'type' => 'minute-n',
'where1' => '10',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toShell',
'sBody' => 'cd /www/wwwroot/jyshd
php NewTradeKlines.php stop
php NewTradeKlines.php start -d',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => '',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 超级期货平仓处理
*/
public function close_out_processing_super_future()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(close_out_processing_super_future)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toShell',
'sBody' => '#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for (( i = 0; i < 60; i=(i+1) )); do
curl -sS --connect-timeout 10 -m 60 "' . $this->url . '/task/pc_deal"
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
sleep 1
done
exit 0',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => '',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 同步 ETH/USDT 交易数据(火币)
*/
public function update_syncethusdt()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(update_syncethusdt)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toShell',
'sBody' => '#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for (( i = 0; i < 60; i=(i+1) )); do
curl -sS --connect-timeout 10 -m 60 "' . $this->url . '/synccoin/syncethusdt"
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
sleep 1
done
exit 0',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => '',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 清理周期数据
*/
public function cleaning_cycle_data()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(cleaning_cycle_data)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toUrl',
'sBody' => '',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => $this->url . '/task/del_hbsj',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 合约限仓处理
*/
public function contract_limit_position()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(contract_limit_position)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toShell',
'sBody' => '#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for (( i = 0; i < 60; i=(i+1) )); do
curl -sS --connect-timeout 10 -m 60 "' . $this->url . '/task/limit_comein"
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
sleep 1
done
exit 0',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => '',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 合约保仓处理
*/
public function contract_bc()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(contract_bc)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toUrl',
'sBody' => '',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => $this->url . '/task/baocang',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 合约止盈止损
*/
public function contract_take_profit_and_stop_loss()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(contract_take_profit_and_stop_loss)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toShell',
'sBody' => '#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for (( i = 0; i < 60; i=(i+1) )); do
curl -sS --connect-timeout 10 -m 60 "' . $this->url . '/task/contract_deal"
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
sleep 1
done
exit 0',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => '',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 更新团队等级
*/
public function update_team_rank()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(update_team_rank)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toUrl',
'sBody' => '',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => $this->url . '/task/level_update',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 对冲盈亏计算
*/
public function hedging_profit_calculation()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(hedging_profit_calculation)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toUrl',
'sBody' => '',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => $this->url . '/task/zhiya_js',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 同步火币价格(核心采集任务)
*/
public function sync_huobi_price()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(sync_huobi_price)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toShell',
'sBody' => '#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for (( i = 0; i < 60; i=(i+1) )); do
curl -sS --connect-timeout 10 -m 60 "' . $this->url . '/tasklh/update_coin"
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
sleep 1
done
exit 0',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => '',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 自动取消 C2C 过期订单
*/
public function automatic_cancellation_of_C2C_expired_orders()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(automatic_cancellation_of_C2C_expired_orders)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toUrl',
'sBody' => '',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => $this->url . '/task/clear_order',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 天使投资释放
*/
public function angel_investment_release()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(angel_investment_release)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toUrl',
'sBody' => '',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => $this->url . '/task/angel_sf',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 同步 BTC/USDT 交易数据(火币)
*/
public function update_syncbtcusdt()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(update_syncbtcusdt)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toShell',
'sBody' => '#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for (( i = 0; i < 60; i=(i+1) )); do
curl -sS --connect-timeout 10 -m 60 "' . $this->url . '/synccoin/syncbtcusdt"
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
sleep 1
done
exit 0',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => '',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 币种撮合交易
*/
public function currency_matching_transaction()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(currency_matching_transaction)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toShell',
'sBody' => '#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for (( i = 0; i < 60; i=(i+1) )); do
curl -sS --connect-timeout 10 -m 60 "' . $this->url . '/task/coin_deal"
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
sleep 1
done
exit 0',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => '',
];
$result = $btapi->addCrontab($params);
return $result;
}
/**
* 更新市场价格(与 sync_huobi_price 相同,重复任务)
*/
public function update_maket_price()
{
$btapi = new Btapi();
$params = [
'name' => $this->name . '(update_maket_price)',
'type' => 'minute-n',
'where1' => '1',
'hour' => '',
'minute' => '',
'week' => '',
'sType' => 'toShell',
'sBody' => '#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
for (( i = 0; i < 60; i=(i+1) )); do
curl -sS --connect-timeout 10 -m 60 "' . $this->url . '/tasklh/update_coin"
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
sleep 1
done
exit 0',
'sName' => '',
'backupTo' => 'localhost',
'save' => '',
'urladdress' => '',
];
$result = $btapi->addCrontab($params);
return $result;
}
}