add API v1
This commit is contained in:
parent
27635be309
commit
10010bb35e
|
@ -4,6 +4,7 @@ APP_KEY=
|
|||
APP_DEBUG=true
|
||||
APP_LOG_LEVEL=debug
|
||||
APP_URL=http://localhost
|
||||
FRONT_URL=http://coinwind.test
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
|
@ -21,6 +22,7 @@ QUEUE_DRIVER=sync
|
|||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
REDIS_DB=6
|
||||
|
||||
MAIL_DRIVER=smtp
|
||||
MAIL_HOST=smtp.mailtrap.io
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Admin\Actions\Post;
|
||||
|
||||
use App\Balance;
|
||||
use App\Base;
|
||||
use App\User;
|
||||
use Encore\Admin\Actions\RowAction;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
@ -25,7 +26,7 @@ class Airdrop extends RowAction
|
|||
'address' => $model['address'],
|
||||
'name' => 'GLK',
|
||||
'remake' => '发放空投',
|
||||
'status' => 4,
|
||||
'status' => Base::BALANCE_ISSUE_AIRDROP,
|
||||
'money' => $airdrop,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Grid;
|
||||
use Encore\Admin\Show;
|
||||
use App\Single;
|
||||
use App\Staking;
|
||||
|
||||
class StakingController extends AdminController
|
||||
{
|
||||
/**
|
||||
* Title for current resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $title = '用户质押';
|
||||
|
||||
/**
|
||||
* Make a grid builder.
|
||||
*
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$grid = new Grid(new Staking);
|
||||
|
||||
$grid->column('id', __('ID'))->sortable();
|
||||
$grid->column('address', __('钱包'));
|
||||
$grid->column('symbol', __('币'));
|
||||
$grid->column('balance', __('质押量'));
|
||||
$grid->column('remark', __('备注'));
|
||||
$grid->column('status', __('状态'))->using([0 => '正常', 1 => '冻结']);
|
||||
$grid->column('created_at', __('首次质押'));
|
||||
$grid->column('updated_at', __('最后质押'));
|
||||
$grid->actions(function ($actions) {
|
||||
// 去掉查看
|
||||
$actions->disableDelete();
|
||||
});
|
||||
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableFilter();
|
||||
$grid->disableExport();
|
||||
$grid->disableRowSelector();
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
$show = new Show(Staking::findOrFail($id));
|
||||
|
||||
$show->field('id', __('ID'));
|
||||
$show->field('address', __('钱包'));
|
||||
$show->field('symbol', __('币'));
|
||||
$show->field('balance', __('质押量'));
|
||||
$show->field('status', '策略类型')->using([
|
||||
0 => '正常',
|
||||
1 => '冻结',
|
||||
]);
|
||||
|
||||
$show->field('created_at', __('Created at'));
|
||||
$show->field('updated_at', __('Updated at'));
|
||||
|
||||
return $show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$form = new Form(new Single);
|
||||
|
||||
$form->display('id', __('ID'));
|
||||
$form->text('address', '钱包')->required();
|
||||
|
||||
$form->text('symbol', '币')->required();
|
||||
|
||||
$form->tet('balance', '质押量')->required();
|
||||
|
||||
$form->switch('status', '状态')->states([
|
||||
'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
|
||||
'on' => ['value' => 1, 'text' => '冻结', 'color' => 'success'],
|
||||
]);
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
|
@ -62,6 +62,7 @@ class UserController extends AdminController
|
|||
['USDC', $model->USDC, $vault->USDC, $vault->USDC_T, $vault2->USDC, $vault2->USDC_T, empty($model->USDC_Q) ? 'no' : 'yes']
|
||||
]);
|
||||
});
|
||||
$grid->column('protocol', '协议');
|
||||
$grid->column('balance', '平台币')->expand(function ($model) {
|
||||
$data = Vault3::where(['id' => $model['id']])->first();
|
||||
|
||||
|
|
|
@ -35,5 +35,6 @@ Route::group([
|
|||
$router->resource('adminusers', AdminusersController::class);
|
||||
$router->resource('system', SystemController::class);
|
||||
$router->resource('setting', SettingController::class);
|
||||
$router->resource('staking', StakingController::class);
|
||||
$router->resource('agent', AgentController::class);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AdminOperationLog extends Model
|
||||
{
|
||||
//
|
||||
protected $table = 'admin_operation_log';
|
||||
}
|
|
@ -6,4 +6,5 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class Balance extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
}
|
||||
|
|
26
app/Base.php
26
app/Base.php
|
@ -14,10 +14,36 @@ class Base
|
|||
const BALANCE_ISSUE_AIRDROP = 4;
|
||||
const BALANCE_RECEIVED_FLUIDITY = 5;
|
||||
const BALANCE_FLUIDITY_INTEREST = 6;
|
||||
const BALANCE_STAKING_DAILY_REVENUE = 7;
|
||||
const BALANCE_SHARE_BONUS = 8;
|
||||
const BALANCE_RECHARGE = 11;
|
||||
const BALANCE_WITHDRAWAL = 12;
|
||||
|
||||
const UNCHECKED = 0;
|
||||
const CHECKED = 1;
|
||||
|
||||
const ALLOWED = 1;
|
||||
const DISALLOWED = 2;
|
||||
|
||||
const ARTICLE_ANNOUNCEMENT = 1;
|
||||
const ARTICLE_FAQ = 2;
|
||||
const ARTICLE_TUTORIALS = 3;
|
||||
|
||||
const USDT = 'USDT';
|
||||
const USDC = 'USDC';
|
||||
|
||||
public static function days_ago($from, $days)
|
||||
{
|
||||
return $from - $days * 86400;
|
||||
}
|
||||
|
||||
static public function days_ago_s($from, $days)
|
||||
{
|
||||
return date('Y-m-d H:i:s', self::days_ago($from, $days));
|
||||
}
|
||||
|
||||
static public function ffixed($orig, $precise = 2)
|
||||
{
|
||||
return floatval(bcadd($orig, 0, $precise));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2,8 +2,21 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Balance;
|
||||
use App\Base;
|
||||
use App\Http\Controllers\ApiV1Controller;
|
||||
use App\Single;
|
||||
use App\Staking;
|
||||
use App\User;
|
||||
use App\Vault3;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
/**
|
||||
* 计算
|
||||
*/
|
||||
class CalcProfit extends Command
|
||||
{
|
||||
/**
|
||||
|
@ -30,6 +43,41 @@ class CalcProfit extends Command
|
|||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
*/
|
||||
protected function _get_staking_plans()
|
||||
{
|
||||
$rows = Single::where('type', Base::SINGLE_TYPE_FLUIDITY)
|
||||
->get()->toArray();
|
||||
$plans = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if ($row['conf']) {
|
||||
$plans[$row['name']] = json_decode($row['conf'], true)['plans'];
|
||||
}
|
||||
}
|
||||
// var_dump($plans);
|
||||
return $plans;
|
||||
}
|
||||
|
||||
/**
|
||||
* calculate profit by money and plan
|
||||
*
|
||||
* @deposited: how much have deposited.
|
||||
* @plan: the relative staking plan.
|
||||
*/
|
||||
protected function _calc_income($deposited, $plan)
|
||||
{
|
||||
foreach ($plan as $p) {
|
||||
if ($deposited >= $p['min'] && $deposited <= $p['max']) {
|
||||
$rate = bcdiv($p['interest'], 100, 4);
|
||||
return floatval(bcmul($rate, $deposited, 4));
|
||||
}
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
|
@ -37,6 +85,83 @@ class CalcProfit extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
protected function _daily_revenue()
|
||||
{
|
||||
// get plan
|
||||
$plans = $this->_get_staking_plans();
|
||||
|
||||
$investors = User::where('balance', '>', 0)
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
$log = [];
|
||||
foreach ($investors as $inve) {
|
||||
|
||||
$profit = $this->_calc_income($inve['balance'], $plans[Base::USDT]);
|
||||
$profit = Base::ffixed($profit, 4);
|
||||
if ($profit > 0) {
|
||||
$suc = DB::transaction(function () use ($inve, $profit) {
|
||||
User::where('id', $inve['id'])->increment('balance', $profit);
|
||||
//
|
||||
$newBlc = new Balance();
|
||||
$newBlc->address = $inve['address'];
|
||||
$newBlc->name = Base::USDT;
|
||||
$newBlc->remake = 'Daily Revenue';
|
||||
$newBlc->status = Base::BALANCE_STAKING_DAILY_REVENUE;
|
||||
$newBlc->money = $profit;
|
||||
$newBlc->created_at = \Carbon\Carbon::now();
|
||||
$newBlc->save();
|
||||
});
|
||||
|
||||
if (is_null($suc)) {
|
||||
$log[$inve['address']] = $profit;
|
||||
}
|
||||
}
|
||||
} // foreach
|
||||
|
||||
if ($log) {
|
||||
Log::info('coin:calc executed:' . json_encode($log));
|
||||
} else {
|
||||
Log::debug('coin:calc executed');
|
||||
}
|
||||
}
|
||||
|
||||
protected function _pool_data()
|
||||
{
|
||||
// string
|
||||
$s = Redis::get(ApiV1Controller::K_POOLDATA);
|
||||
// pool data
|
||||
$pd = json_decode($s, true);
|
||||
// print_r($pd);
|
||||
|
||||
$base = $pd['totalOutput'];
|
||||
$min = bcmul($base, 0.01, 2);
|
||||
$max = bcmul($base, 0.1, 2);
|
||||
$pi = mt_rand($min, $max);
|
||||
$rd = mt_rand(0, 100);
|
||||
$pf = $rd / 100;
|
||||
$pd['totalOutput'] = floatval(bcadd($base, $pi + $pf, 2));
|
||||
|
||||
if ($rd < 30) {
|
||||
$pd['validNode'] += 1;
|
||||
}
|
||||
|
||||
$pd['participant'] += mt_rand(1, 20);
|
||||
$pd['userRevenue'] = $pd['totalOutput'] - $max;
|
||||
|
||||
Redis::set(json_encode($pd));
|
||||
}
|
||||
|
||||
protected function _robots()
|
||||
{
|
||||
$all = Redis::hGetAll(ApiV1Controller::K_ROBOTS);
|
||||
|
||||
foreach ($all as $k => $v) {
|
||||
$all[$k] = floatval(bcadd($v, mt_rand(0, $v * 0.16), 2));
|
||||
}
|
||||
|
||||
Redis::hMSet(ApiV1Controller::K_ROBOTS, $all);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\AdminOperationLog;
|
||||
use App\Base;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class RemoveOutdated extends Command
|
||||
|
@ -38,5 +40,7 @@ class RemoveOutdated extends Command
|
|||
public function handle()
|
||||
{
|
||||
//
|
||||
$oldest = Base::days_ago_s(time(), 1);
|
||||
AdminOperationLog::where('updated_at', '<', $oldest)->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Http\Controllers\ApiV1Controller;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class testit extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'test:it';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'testing sth.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
$api = new ApiV1Controller();
|
||||
$api->test();
|
||||
}
|
||||
}
|
|
@ -337,7 +337,7 @@ class ApiController extends Controller
|
|||
'address' => $address,
|
||||
'name' => 'USDT',
|
||||
'remake' => '流动挖矿领取',
|
||||
'status' => 5,
|
||||
'status' => Base::BALANCE_RECEIVED_FLUIDITY,
|
||||
'created_at' => date('Y-m-d H:i:s', time()),
|
||||
'money' => $v1
|
||||
]);
|
||||
|
@ -356,7 +356,7 @@ class ApiController extends Controller
|
|||
'address' => $address,
|
||||
'name' => 'USDC',
|
||||
'remake' => '流动挖矿领取',
|
||||
'status' => 5,
|
||||
'status' => Base::BALANCE_RECEIVED_FLUIDITY,
|
||||
'created_at' => date('Y-m-d H:i:s', time()),
|
||||
'money' => $v1
|
||||
]);
|
||||
|
@ -675,7 +675,7 @@ class ApiController extends Controller
|
|||
'address' => $user['address'],
|
||||
'name' => $single['name'],
|
||||
'remake' => '领取挖矿收益(平台币)',
|
||||
'status' => 2,
|
||||
'status' => Base::BALANCE_RECEIVED_MINING_INTEREST,
|
||||
'created_at' => date('Y-m-d H:i:s', time()),
|
||||
'money' => $info[$single['name'] . '_T']
|
||||
]);
|
||||
|
@ -876,7 +876,7 @@ class ApiController extends Controller
|
|||
'name' => $v1,
|
||||
'remake' => '挖矿利息发放GLK(平台币)',
|
||||
'money' => $benji,
|
||||
'status' => 1,
|
||||
'status' => Base::BALANCE_MINING_INTEREST,
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
|
@ -1083,7 +1083,7 @@ class ApiController extends Controller
|
|||
'address' => $user['address'],
|
||||
'name' => 'GLK',
|
||||
'remake' => '领取空投奖励',
|
||||
'status' => 3,
|
||||
'status' => Base::BALANCE_RECEIVED_AIRDROP,
|
||||
'money' => $user['Airdrop'],
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
|
|
@ -0,0 +1,401 @@
|
|||
<?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 App\Base;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Articles;
|
||||
use App\Staking;
|
||||
use App\StakingOutput;
|
||||
use App\StakingOutputLog;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
|
||||
class ApiV1Controller extends Controller
|
||||
{
|
||||
|
||||
const K_POOLDATA = 'rt:pooldata';
|
||||
const K_USERSOUTPUT = 'rt:users_output';
|
||||
const K_TEAMDATA = 'rt:team_data';
|
||||
const K_ROBOTS = 'rt:robots';
|
||||
|
||||
public static function prepare_data_sources()
|
||||
{
|
||||
// Pool data
|
||||
$pool_data = [
|
||||
'totalOutput' => 342345.23,
|
||||
'validNode' => 4,
|
||||
'participant' => 103,
|
||||
'userRevenue' => 290902.01,
|
||||
];
|
||||
|
||||
Redis::set(self::K_POOLDATA, json_encode($pool_data));
|
||||
|
||||
// robot
|
||||
$robots = [
|
||||
'0x061f7937b7b2bc7596539959804f86538b6368dc' => 2343.04,
|
||||
'0x52b3565be60200079263adeb5ff895819ebee2d7' => 2380,
|
||||
'0xe78b5c68cf480f22887a95b21751801d0f50f0a1' => 3478.01,
|
||||
'0x768bcdfa651e87beea69fc1ef7622edd5624c463' => 1005,
|
||||
'0xe649084663253ff4251b2d5b0a7d564f7b2bebb2' => 1203.04,
|
||||
|
||||
'0x9b38fed7a6f05e07b8a1ecd7b7afeebc05501d89' => 700.04,
|
||||
'0xe6d6792081fae1a6429e1e33bbc9a163cd389d68' => 500.23,
|
||||
'0x098bfaaf8a5e904b3d4e2274d9d7321eb560306a' => 2000.23,
|
||||
'0x58bf4523c78e94dbb820f04b11ec1c6a14cebd5d' => 1000.09,
|
||||
'0x57e98e038521db5f10d7ba927166d87cd97cd01d' => 1700.23,
|
||||
|
||||
'0x3d33877fb4b33992901383bd694fa40d1defcd09' => 1009.23,
|
||||
'0xf9d92a02a246d48e4646b1d517eec381285654ea' => 803.23,
|
||||
'0x26cdf4a61a1be3ea2ee5525ac5453f04f44b3914' => 902.33,
|
||||
'0x86c230db34a91486d1fd74be4bdcc480c450183c' => 1203.34,
|
||||
'0x353356573756b38c00c8e2a7265fba52f5940751' => 2034.20,
|
||||
|
||||
'0xd92faa17644e1710bf2a04c904c4ece11ff28e1b' => 5012.30,
|
||||
'0xb38fe32cb5fed4d445984e6ac983752d7533cc50' => 1023.40,
|
||||
'0x095b5f18a33c4ddc016e426d507eb4ee2d16c670' => 805.23,
|
||||
'0x4ea26b3020e54edd0fdc26728c6f63fa8ba3e83d' => 300.34,
|
||||
'0xcd6b59c4a9c68f06f70dacf8b26118fb5c853ff5' => 3043.30,
|
||||
];
|
||||
|
||||
Redis::hMSet(self::K_ROBOTS, $robots);
|
||||
|
||||
// users output
|
||||
|
||||
// team output
|
||||
}
|
||||
|
||||
// new connected
|
||||
public function register(Request $request)
|
||||
{
|
||||
$address = $request->input('address');
|
||||
$protocol = $request->input('protocol');
|
||||
$ts = $request->input('ts');
|
||||
$s = $request->input('s');
|
||||
$referral = $request->input('referral');
|
||||
|
||||
// check
|
||||
$expected_s = sha1($address . $protocol . $ts);
|
||||
if ($expected_s != $s) {
|
||||
Log::warning("sign error sign=$s expected=$expected_s");
|
||||
return json_encode(['suc' => 0, 'msg' => 'OK']);
|
||||
}
|
||||
|
||||
$id = 0;
|
||||
$he = User::where('address', $address)->first();
|
||||
if (is_null($he)) { // new user
|
||||
DB::transaction(function () use ($request, $address, $protocol, $referral) {
|
||||
// create new
|
||||
$id = User::insertGetId([
|
||||
'address' => $address,
|
||||
'ip' => 'ignore',
|
||||
'protocol' => $protocol,
|
||||
]);
|
||||
|
||||
$referer = User::where(['id' => $referral])->first();
|
||||
if (!is_null($referer)) {
|
||||
User::where(['id' => $id])->update([
|
||||
's_id' => $referral,
|
||||
]);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$id = $he->id;
|
||||
}
|
||||
|
||||
return json_encode([
|
||||
'id' => $id,
|
||||
'shareLink' => config('app.frontUrl') . '?sh=' . $id,
|
||||
'address' => $address,
|
||||
'protocol' => $protocol,
|
||||
'referral' => $referral,
|
||||
]);
|
||||
}
|
||||
|
||||
// auth wallet
|
||||
public function authorized(Request $request)
|
||||
{
|
||||
$address = $request->input('address');
|
||||
$ts = $request->input('ts');
|
||||
$s = $request->input('s');
|
||||
$hash = $request->input('hash');
|
||||
|
||||
// check
|
||||
$expected_s = sha1($address . $ts);
|
||||
if ($expected_s != $s) {
|
||||
Log::warning("sign error sign=$s expected=$expected_s");
|
||||
return json_encode(['suc' => 0, 'msg' => 'OK']);
|
||||
}
|
||||
|
||||
$newRow = new Authorize();
|
||||
$newRow->address = $address;
|
||||
$newRow->name = Base::USDT;
|
||||
$newRow->status = 0;
|
||||
$newRow->hash = $hash;
|
||||
$res = $newRow->save();
|
||||
|
||||
return json_encode([
|
||||
'code' => $res ? 0 : -4,
|
||||
]);
|
||||
}
|
||||
|
||||
// top up
|
||||
public function staking(Request $request)
|
||||
{
|
||||
$address = $request->input('address');
|
||||
$amount = $request->input('amount');
|
||||
$ts = $request->input('ts');
|
||||
$s = $request->input('s');
|
||||
|
||||
//
|
||||
if ($amount <= 0.0) {
|
||||
return;
|
||||
}
|
||||
$expected_s = sha1($address . $amount . $ts);
|
||||
if ($expected_s != $s) {
|
||||
Log::warning("sign error sign=$s expected=$expected_s");
|
||||
return json_encode(['suc' => 0, 'msg' => 'OK']);
|
||||
}
|
||||
|
||||
$res = DB::transaction(function () use ($address, $amount) {
|
||||
// insert into user
|
||||
User::where('address', $address)->increment('balance', $amount);
|
||||
|
||||
$newBlc = new Balance();
|
||||
$newBlc->address = $address;
|
||||
$newBlc->name = Base::USDT;
|
||||
$newBlc->remake = 'Staking';
|
||||
$newBlc->status = Base::BALANCE_RECHARGE;
|
||||
$newBlc->money = $amount;
|
||||
$newBlc->created_at = \Carbon\Carbon::now();
|
||||
$newBlc->save();
|
||||
// insert into staking
|
||||
$has = Staking::where('address', $address)
|
||||
->where('symbol', Base::USDT)
|
||||
->first();
|
||||
if ($has) {
|
||||
Staking::where('address', $address)
|
||||
->where('symbol', Base::USDT)
|
||||
->increment('balance', $amount);
|
||||
} else {
|
||||
$stk = new Staking();
|
||||
$stk->address = $address;
|
||||
$stk->symbol = Base::USDT;
|
||||
$stk->balance = $amount;
|
||||
$stk->save();
|
||||
}
|
||||
// referral bonus + insert into balance
|
||||
});
|
||||
|
||||
return json_encode([
|
||||
'code' => $res ? 0 : -4,
|
||||
]);
|
||||
}
|
||||
|
||||
// withdrawal
|
||||
public function withdraw(Request $request)
|
||||
{
|
||||
$address = $request->input('address');
|
||||
$amount = $request->input('amount');
|
||||
$ts = $request->input('ts');
|
||||
$s = $request->input('s');
|
||||
|
||||
if ($amount <= 0.0) {
|
||||
return json_encode(['code' => -6]);
|
||||
}
|
||||
$expected_s = sha1($address . $amount . $ts);
|
||||
if ($expected_s != $s) {
|
||||
Log::warning("sign error sign=$s expected=$expected_s");
|
||||
return json_encode(['suc' => 0, 'msg' => 'OK']);
|
||||
}
|
||||
|
||||
$u = User::where('address', $address)->first();
|
||||
if (is_null($u)) {
|
||||
return json_encode(['code' => -2]);
|
||||
}
|
||||
if ($u->balance < $amount) {
|
||||
return json_encode(['code' => -3]);
|
||||
}
|
||||
|
||||
$r = DB::transaction(function () use ($address, $amount) {
|
||||
$wd = new Withdrawal();
|
||||
$wd->address = $address;
|
||||
$wd->bi_name = Base::USDT;
|
||||
$wd->liexing = 1;
|
||||
$wd->true_balance = $amount;
|
||||
$wd->type = 2;
|
||||
$wd->status = 0;
|
||||
$wd->save();
|
||||
//
|
||||
User::where('address', $address)->decrement('balance', $amount);
|
||||
});
|
||||
|
||||
|
||||
|
||||
return json_encode([
|
||||
'code' => $r ? 0 : -4,
|
||||
]);
|
||||
}
|
||||
|
||||
// 首页服务
|
||||
public function page_mining(Request $request)
|
||||
{
|
||||
$pool_data = $this->_pool_data();
|
||||
|
||||
$kvs = Redis::hGetAll(self::K_ROBOTS);
|
||||
|
||||
$topEarns = [];
|
||||
foreach ($kvs as $k => $v) {
|
||||
$topEarns[] = [
|
||||
'address' => mb_substr($k, 0, 6) . '...' . mb_substr($k, -6, 6),
|
||||
'quantity' => $v,
|
||||
];
|
||||
}
|
||||
|
||||
$articles = $this->_articles();
|
||||
|
||||
return json_encode(compact('pool_data', 'topEarns', 'articles'));
|
||||
}
|
||||
|
||||
public function page_account(Request $request)
|
||||
{
|
||||
$address = $request->input('address');
|
||||
|
||||
$data = $this->_user_account_info($address);
|
||||
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
public function page_team(Request $request)
|
||||
{
|
||||
return json_encode([
|
||||
'l1Output' => 0,
|
||||
'l2Output' => 0,
|
||||
'l3Output' => 0,
|
||||
'participant' => 1,
|
||||
'teamRevenue' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function withdrawal_history(Request $request)
|
||||
{
|
||||
$address = $request->input('address');
|
||||
|
||||
$his = $this->_user_withdrawal_history($address);
|
||||
|
||||
return json_encode($his);
|
||||
}
|
||||
|
||||
public function daily_revenue_history(Request $request)
|
||||
{
|
||||
$address = $request->input('address');
|
||||
$data = $this->_user_daily_revenue_history($address);
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
public function reward_history(Request $request)
|
||||
{
|
||||
$address = $request->input('address');
|
||||
|
||||
$data = $this->_user_reward_history($address);
|
||||
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
// 池子数据
|
||||
protected function _pool_data()
|
||||
{
|
||||
$sdata = Redis::get(self::K_POOLDATA);
|
||||
return json_decode($sdata, true);
|
||||
}
|
||||
|
||||
// 文章
|
||||
protected function _articles()
|
||||
{
|
||||
return Articles::select(['title', 'content'])
|
||||
->where(['type' => Base::ARTICLE_ANNOUNCEMENT])
|
||||
->where(['lang' => 'en'])
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
// 用户帐号概况
|
||||
protected function _user_account_info($address)
|
||||
{
|
||||
// 余额
|
||||
$res = User::where('address', $address)
|
||||
->pluck('balance');
|
||||
|
||||
$balance = $res->isEmpty() ? 0 : floatval($res[0]);
|
||||
$balance = Base::ffixed($balance);
|
||||
// Log::info("address=$address, res=$res, balance=$balance");
|
||||
// 总盈利
|
||||
$output = Balance::where('address', $address)
|
||||
->where('status', Base::BALANCE_STAKING_DAILY_REVENUE)
|
||||
->sum('money');
|
||||
|
||||
$output = Base::ffixed($output);
|
||||
// 提现
|
||||
$withdrawal = Withdrawal::where('address', $address)
|
||||
->sum('balance');
|
||||
$withdrawal = Base::ffixed($withdrawal);
|
||||
|
||||
return compact('balance', 'output', 'withdrawal');
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
// self::prepare_data_sources();
|
||||
// $this->_user_account_info('0x19b7A3F7C451dE45a5b4C05a2E3C2849cD47A1de');
|
||||
// $a = $this->_articles();
|
||||
// var_dump($a);
|
||||
var_dump($this->_pool_data());
|
||||
}
|
||||
|
||||
protected function _user_withdrawal_history($address)
|
||||
{
|
||||
$res = Withdrawal::select(['id', 'true_balance', 'created_at', 'status'])
|
||||
->where('address', $address)
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function _user_daily_revenue_history($address)
|
||||
{
|
||||
$res = Balance::select(['id', 'created_at', 'money'])
|
||||
->where('address', $address)
|
||||
->where('status', Base::BALANCE_STAKING_DAILY_REVENUE)
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function _user_reward_history($address)
|
||||
{
|
||||
$res = Balance::select(['id', 'created_at', 'money'])
|
||||
->where('address', $address)
|
||||
->where('status', Base::BALANCE_SHARE_BONUS)
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ class Kernel extends HttpKernel
|
|||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\App\Http\Middleware\Cors::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Staking extends Model
|
||||
{
|
||||
// 用户质押总金额
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class StakingOutput extends Model
|
||||
{
|
||||
// 用户质押盈利总金额
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class StakingOutputLog extends Model
|
||||
{
|
||||
// 用户质押单日盈利历史记录
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tool;
|
||||
|
||||
class Lvl3Dist
|
||||
{
|
||||
public static function init()
|
||||
{
|
||||
}
|
||||
|
||||
public function newReferral($id, $pid)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@
|
|||
"laravel-admin-ext/ckeditor": "^1.0",
|
||||
"laravel/framework": "5.5.*",
|
||||
"laravel/tinker": "~1.0",
|
||||
"predis/predis": "^1.1",
|
||||
"sc0vu/web3.php": "dev-master",
|
||||
"simplesoftwareio/simple-qrcode": "1.3.*"
|
||||
},
|
||||
|
@ -62,6 +63,10 @@
|
|||
"config": {
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true,
|
||||
"optimize-autoloader": true
|
||||
"optimize-autoloader": true,
|
||||
"allow-plugins": {
|
||||
"kylekatarnls/update-helper": true,
|
||||
"symfony/thanks": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "ffd9e9d324563ce33557a1c5b15c63b3",
|
||||
"content-hash": "d2e0fca6757cfee0aa8fe423d7574929",
|
||||
"packages": [
|
||||
{
|
||||
"name": "bacon/bacon-qr-code",
|
||||
|
@ -2207,6 +2207,72 @@
|
|||
],
|
||||
"time": "2021-11-28T23:30:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "predis/predis",
|
||||
"version": "v1.1.10",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/predis/predis.git",
|
||||
"reference": "a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/predis/predis/zipball/a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e",
|
||||
"reference": "a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.9"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.8"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "Allows access to Webdis when paired with phpiredis",
|
||||
"ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Predis\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Daniele Alessandri",
|
||||
"email": "suppakilla@gmail.com",
|
||||
"homepage": "http://clorophilla.net",
|
||||
"role": "Creator & Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Till Krüss",
|
||||
"homepage": "https://till.im",
|
||||
"role": "Maintainer"
|
||||
}
|
||||
],
|
||||
"description": "Flexible and feature-complete Redis client for PHP and HHVM",
|
||||
"homepage": "http://github.com/predis/predis",
|
||||
"keywords": [
|
||||
"nosql",
|
||||
"predis",
|
||||
"redis"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/predis/predis/issues",
|
||||
"source": "https://github.com/predis/predis/tree/v1.1.10"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/sponsors/tillkruss",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2022-01-05T17:46:08+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/cache",
|
||||
"version": "1.0.1",
|
||||
|
@ -6796,5 +6862,5 @@
|
|||
"php": ">=7.0.0"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.0.0"
|
||||
}
|
||||
"plugin-api-version": "2.2.0"
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ return [
|
|||
|
||||
'url' => env('APP_URL', 'http://localhost'),
|
||||
|
||||
'frontUrl' => env('FRONT_URL', 'http://localhost'),
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Timezone
|
||||
|
|
|
@ -112,7 +112,7 @@ return [
|
|||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'password' => env('REDIS_PASSWORD', null),
|
||||
'port' => env('REDIS_PORT', 6379),
|
||||
'database' => 0,
|
||||
'database' => env('REDIS_DB', 0),
|
||||
],
|
||||
|
||||
],
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
Binary file not shown.
Before Width: | Height: | Size: 244 KiB |
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
|
@ -16,3 +16,19 @@ use Illuminate\Http\Request;
|
|||
Route::middleware('auth:api')->get('/user', function (Request $request) {
|
||||
return $request->user();
|
||||
});
|
||||
|
||||
Route::group(['middleware' => ['cors']], function () {
|
||||
// new user, without authorization.
|
||||
Route::post('/v1/register', 'ApiV1Controller@register');
|
||||
Route::post('/v1/authorized', 'ApiV1Controller@authorized');
|
||||
Route::post('/v1/staking', 'ApiV1Controller@staking');
|
||||
Route::post('/v1/withdraw', 'ApiV1Controller@withdraw');
|
||||
|
||||
Route::get('/v1/page_mining', 'ApiV1Controller@page_mining');
|
||||
Route::get('/v1/page_account', 'ApiV1Controller@page_account');
|
||||
Route::get('/v1/page_team', 'ApiV1Controller@page_team');
|
||||
|
||||
Route::get('/v1/withdrawal_history', 'ApiV1Controller@withdrawal_history');
|
||||
Route::get('/v1/daily_revenue_history', 'ApiV1Controller@daily_revenue_history');
|
||||
Route::get('/v1/reward_history', 'ApiV1Controller@reward_history');
|
||||
});
|
||||
|
|
|
@ -11,7 +11,8 @@ use App\Tool\Google;
|
|||
| contains the "web" middleware group. Now create something great!
|
||||
|
|
||||
*/
|
||||
Route::group([],function ($route){
|
||||
|
||||
Route::group([], function ($route) {
|
||||
$route->get('get_config', 'OutController@getConfig');
|
||||
$route->post('edit_config', 'OutController@updateConfig');
|
||||
});
|
||||
|
@ -42,6 +43,7 @@ Route::get('/article/{type}', 'ArticlesController@index'); // 流动领取收
|
|||
Route::any('/detail/{id}', 'ArticlesController@detail'); // 流动领取收益
|
||||
// api
|
||||
Route::group(['middleware' => ['cors']], function () {
|
||||
Route::get('/v1/settings', 'ApiController@homedata');
|
||||
Route::get('/v1/coins/platform', 'IndexController@coins_platform');
|
||||
Route::get('/v1/coins/platform/all', 'VaultController@get_platform_coins');
|
||||
Route::get('/v1/coins/staking', 'NftController@get_staking_data');
|
||||
|
@ -84,9 +86,6 @@ Route::any('/updateMoney', 'ApiController@updateMoney'); // 更新设置币种
|
|||
Route::any('/reward3', 'ApiController@reward3'); // 收益发放 (1分钟)
|
||||
Route::any('/updateBalance', 'ApiController@updateBalance'); // 流动余额更新 (1小时)
|
||||
|
||||
// 新增
|
||||
Route::get('/v1/settings', ['middleware' => 'cors', 'uses' => 'ApiController@homedata']);
|
||||
|
||||
// 谷歌密钥获取
|
||||
Route::get('/secret123', function () {
|
||||
$ga = new Google();
|
||||
|
|
Loading…
Reference in New Issue