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. * * @return mixed */ 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); } }