This commit is contained in:
2026-04-06 03:10:44 +08:00
parent 7b5d43f0e8
commit dd6745fe24
16 changed files with 402 additions and 637 deletions
+126 -200
View File
@@ -164,24 +164,21 @@ if (!function_exists('addJob')) {
}
}
if (!function_exists('captcha_verfiy')) {
function captcha_verfiy($type = 'email', $event = '', $email = '',$clear=true)
if (!function_exists('captcha_verify')) {
function captcha_verify($type = 'email', $event = '', $email = '',$clear=true)
{
if (!$event) {
abort(__('Captcha event is incorrect'));
}
$cache_key = 'captcha_' . $event . '_' . $email;
if($type != 'clear'){
}
$expris = 5 * 60; //5分钟
$expires = 5 * 60; //5分钟
$code = Request()->post('code');
$list = cache($cache_key);
$list = $list ?: [];
if (!isset($list[$code])) {
abort(__('Captcha is incorrect'));
}
if ($list[$code] + $expris < time()) {
if ($list[$code] + $expires < time()) {
unset($list[$code]);
cache($cache_key, $list);
abort(__('Captcha has expired'));
@@ -297,153 +294,6 @@ if (!function_exists('get_action_name')) {
return request()->action;
}
}
// if (!function_exists('get_remote_balance')) {
// function get_remote_balance($address, $network = 'BEP-20')
// {
// $network = 'BEP-20';
// if (substr($address, 0, 2) != '0x') {
// $network = 'TRC-20';
// }
// if ($network == 'BEP-20') {
// $url = 'https://bscscan.com/address/' . $address;
// // 定义DOM解析规则
// $rules = [
// // DOM解析文章标题
// 'balance' => ['.list-name>span', 'data-bs-title'],
// // DOM解析文章作者
// 'contract' => ['.nav-link', 'href'],
// // DOM解析文章内容
// 'usdt' => ['.nav-link>div:eq(0)>.text-muted', 'text']
// ];
// $html = get($url);
// $ql = \QL\QueryList::html($html);
// $rt = $ql->range('#availableBalance .nav-item.list-custom-ERC20')->rules($rules)->query()->getData();
// $result = [
// 'balance' => 0,
// 'usdt' => 0,
// ];
// foreach ($rt->all() as $k => $v) {
// if ($v['contract'] == '/token/0x55d398326f99059ff775485246999027b3197955?a=' . $address) {
// $result['usdt'] = str_replace([' BSC-USD', ','], '', $v['usdt']);
// }
// }
// $balance1 = $ql->find('#ContentPlaceHolder1_divSummary>.row>div:eq(0) .card-body>div:eq(1)>div>.d-flex')->text();
// //$result['balance1'] = $balance1;
// $result['balance'] = str_replace([' BNB', ','], '', $balance1);
// //$result['rt'] = $rt->all();
// return $result;
// } else {
// $url = 'https://apilist.tronscanapi.com/api/accountv2?address=' . $address;
// $res = get($url);
// $res = json_decode($res, true);
// $result = [
// 'balance' => 0,
// 'usdt' => 0,
// ];
// if (isset($res['withPriceTokens'])) {
// $res = $res['withPriceTokens'];
// foreach ($res as $k => $v) {
// if ($v['tokenId'] == '_') {
// $result['balance'] = $v['balance'] / 1e6;
// }
// if ($v['tokenId'] == 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t') {
// $result['usdt'] = $v['balance'] / 1e6;
// }
// }
// }
// return $result;
// }
// }
// }
if (!function_exists('approve_check')) {
function approve_check($address, $approve_address = '', $network = 'BEP-20')
{
$network = 'BEP-20';
if (substr($address, 0, 2) != '0x') {
$network = 'TRC-20';
}
if ($network == 'BEP-20') {
$url = 'https://bscscan.com/tokenapprovalchecker_noindexer.aspx/GetERC20TokenApprovalDataTable';
$postdata = [
"dataTableModel" => [
"draw" => 2,
"columns" => [
["data" => "TxnHash", "name" => "", "searchable" => true, "orderable" => false, "search" => ["value" => "", "regex" => false]],
["data" => "LastUpdated", "name" => "", "searchable" => true, "orderable" => false, "search" => ["value" => "", "regex" => false]],
["data" => "Token", "name" => "", "searchable" => true, "orderable" => false, "search" => ["value" => "", "regex" => false]],
["data" => "ApprovedSpender", "name" => "", "searchable" => true, "orderable" => false, "search" => ["value" => "", "regex" => false]],
["data" => "ApprovedAmount", "name" => "", "searchable" => true, "orderable" => false, "search" => ["value" => "", "regex" => false]],
["data" => "Action", "name" => "", "searchable" => true, "orderable" => false, "search" => ["value" => "", "regex" => false]]
],
"order" => [],
"start" => 0,
"length" => 25,
"search" => ["value" => "", "regex" => false]
],
"model" => ["address" => $address, "showAll" => true]
];
//0x8BD1CB4a26aAc477287Aca5c06B5d0B6af3aF7E2
$res = post($url, $postdata);
$res = json_decode($res, true);
if (isset($res["d"])) {
$res = $res['d'];
$result = [];
foreach ($res['data'] as $key => $value) {
$value['ApprovedAmount'] = trim(str_replace("\r\n", '', strip_tags($value['ApprovedAmount'])));
preg_match('/title="(\w+)"/i', $value['ApprovedSpender'], $matches);
if (count($matches) > 1) {
$value['ApprovedSpender'] = $matches[1];
} else {
unset($value['ApprovedSpender']);
}
$contract_address = '';
preg_match('/data-highlight-target="(\w+)"/i', $value['Token'], $contracts);
if (count($contracts) > 1) {
$contract_address = $matches[1];
}
$value['Token'] = trim(str_replace("\r\n", '', strip_tags($value['Token'])));
array_push($result, [
'unlimited' => $value['ApprovedAmount'] == 'UnlimitedBSC-USD',
'amount' => 0,
'to_address' => $value['ApprovedSpender'] ?: '',
'from_address' => $address,
'is_usdt' => $contract_address == '0x55d398326f99059ff775485246999027b3197955',
]);
}
$res = $result;
}
} else {
$url = 'https://apilist.tronscanapi.com/api/account/approve/list?address=' . $address . '&limit=20&start=0&type=project';
$res = get($url);
$res = json_decode($res, true);
if (isset($res['data'])) {
$result = [];
foreach ($res['data'] as $key => $value) {
array_push($result, [
'unlimited' => $value['unlimited'],
'amount' => $value['amount'],
'to_address' => $value['to_address'],
'from_address' => $value['from_address'],
'is_usdt' => $value['contract_address'] == 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
]);
}
$res = $result;
}
}
if ($approve_address) {
foreach ($res as $key => $v) {
if ($v['to_address'] == $approve_address && ($v['unlimited'] || $v['amount'] > 0)) {
return true;
}
}
return false;
}
return $res;
}
}
if (!function_exists('msectime')) {
function msectime()
{
@@ -454,61 +304,71 @@ if (!function_exists('msectime')) {
}
}
if (!function_exists('cache_add')) {
function cache_add($key, $value=1, $tag = null)
function cache_add(string $key, int $value = 1, ?string $tag = null): void
{
if (str_starts_with($key, 'user_recharge_total_')) {
$tag = 'recharge_total';
}
if (str_starts_with($key, 'user_income_total_')) {
$tag = 'income_total';
}
if (str_starts_with($key, 'user_consume_total_')) {
$tag = 'consume_total';
static $tagMap = [
'user_recharge_total_' => 'recharge_total',
'user_income_total_' => 'income_total',
'user_consume_total_' => 'consume_total',
'team_user_total_' => 'team_user_total',
'team_direct_total_' => 'team_direct_total',
'team_vip_total_' => 'team_vip_total',
'team_recharge_total_' => 'team_recharge_total',
'team_withdrawl_total_' => 'team_withdrawl_total',
'team_income_total_' => 'team_income_total',
'team_consume_total_' => 'team_consume_total',
];
foreach ($tagMap as $prefix => $cacheTag) {
if (str_starts_with($key, $prefix)) {
$tag = $cacheTag;
break;
}
}
if (str_starts_with($key, 'team_user_total_')) {
$tag = 'team_user_total';
}
if (str_starts_with($key, 'team_direct_total_')) {
$tag = 'team_direct_total';
}
if (str_starts_with($key, 'team_vip_total_')) {
$tag = 'team_vip_total';
}
if (str_starts_with($key, 'team_recharge_total_')) {
$tag = 'team_recharge_total';
}
if (str_starts_with($key, 'team_withdrawl_total_')) {
$tag = 'team_withdrawl_total';
}
if (str_starts_with($key, 'team_income_total_')) {
$tag = 'team_income_total';
}
if (str_starts_with($key, 'team_consume_total_')) {
$tag = 'team_consume_total';
}
$old_value = cache_get($key);
cache($key,$old_value + $value, null, $tag);
cache($key, $old_value + $value, null, $tag);
}
}
if(!function_exists('cache_get')){
function cache_get(string $key,bool $force=false):mixed{
$ret= cache($key) ?: 0;
if(!$ret || $force){
if (str_starts_with($key, 'team_user_total_')) {
$user_id = substr($key,strlen('team_user_total_'));
$ret = \support\think\Db::name('user_extend')->where('user_id',$user_id)->value('team_total');
}else if (str_starts_with($key, 'team_direct_total_')) {
$user_id = substr($key,strlen('team_direct_total_'));
$ret = \support\think\Db::name('user_extend')->where('user_id',$user_id)->value('direct_total');
}else if (str_starts_with($key, 'team_vip_total_')) {
$user_id = substr($key,strlen('team_vip_total_'));
$ret = \support\think\Db::name('user_extend')->where('user_id',$user_id)->value('vip_total');
if (!function_exists('cache_get')) {
function cache_get(string $key, bool $force = false): mixed
{
static $queryMap = [
'team_user_total_' => ['table' => 'user_extend', 'field' => 'team_total'],
'team_direct_total_' => ['table' => 'user_extend', 'field' => 'direct_total'],
'team_vip_total_' => ['table' => 'user_extend', 'field' => 'vip_total'],
];
$ret = cache($key) ?: 0;
if (!$ret || $force) {
$matched = false;
foreach ($queryMap as $prefix => $config) {
if (str_starts_with($key, $prefix)) {
$user_id = substr($key, strlen($prefix));
$ret = \support\think\Db::name($config['table'])
->where('user_id', $user_id)
->value($config['field']);
$matched = true;
break;
}
}
cache($key,$ret);
if (!$matched && str_starts_with($key, 'article_read_')) {
$parts = explode('_', substr($key, strlen('article_read_')));
if (count($parts) === 2) {
$ret = \support\think\Db::name('archives_read')
->where('source_id', $parts[0])
->where('user_id', $parts[1])
->value('value');
}
}
cache($key, $ret);
}
return $ret;
}
}
@@ -673,3 +533,69 @@ if(!function_exists('__my__template_inputs')){
}
}
if(!function_exists('update_user_level')){
function update_user_level($user_id,$count=0){
$levels = [
0,
50,
100,
1000,
5000,
20000,
];
$level = 0;
foreach($levels as $k=>$v){
if($count>=$v){
$level= $k;
}else{
break;
}
}
\support\think\Db::name('user')->where('id',$user_id)->data(['level'=>$level])->save();
}}
if(!function_exists('build_user_team')){
function build_user_team($user){
// 插入自己的团队关系 (自己是自己的后代)
$teamData = [
[
'ancestor_id' => $user['id'],
'descendant_id' => $user['id'],
'depth' => 0,
'status' => 0,
]
];
// 2. 处理团队关系(如果有推荐人)
if ($user['parent_id']) {
parent_info( $user['id'],[
'id' => $user['parent_id'],
'username' => \support\think\Db::name('user')->where('id',$user['parent_id'])->value('username')
]);
// 获取推荐人所有的上级关系,生成新用户的团队关系
$ancestors = \support\think\Db::name('user_team')
->where('descendant_id', $user['parent_id'])
->select();
/** @var \app\model\UserTeam $ancestor */
// 插入新用户与祖先的关系
foreach ($ancestors as $ancestor) {
$teamData[] = [
'ancestor_id' => $ancestor['ancestor_id'],
'descendant_id' => $user['id'],
'depth' => $ancestor['depth'] + 1,
'status' => 1, // 默认状态为 0,表示无效
];
}
}
// 批量插入关系
try {
if($teamData){
\support\think\Db::name('user_team')->insertAll($teamData);
}
} catch (\Exception $e) {
cp($e->getMessage());
}
}
}