39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Actions\Post;
|
|
|
|
use App\Single;
|
|
use App\User;
|
|
use Encore\Admin\Actions\RowAction;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Replicate extends RowAction
|
|
{
|
|
public $name = '更新余额';
|
|
|
|
public function handle(Model $model)
|
|
{
|
|
$data = file_get_contents('https://eth.tokenview.com/api/eth/address/tokenbalance/' . strtolower($model->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' => $model->address])->update([
|
|
$l['name'] => $v['balance'] / pow(10, $v['tokenInfo']['d'])
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
return $this->response()->error('暂无数据')->refresh();
|
|
}
|
|
|
|
return $this->response()->success('更新成功')->refresh();
|
|
}
|
|
}
|