BTCoinmt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

110 lines
3.0 KiB

<?php
/*
* @Descripttion:
* @version:
* @Author: GuaPi
* @Date: 2021-07-29 10:40:49
* @LastEditors: GuaPi
* @LastEditTime: 2021-08-09 17:45:52
*/
namespace App\Admin\Actions\Grid;
use App\Models\UserWallet;
use App\Models\WalletCollection;
use App\Services\CoinService\GethService;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Traits\HasPermissions;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class ETHCollect extends RowAction
{
/**
* @return string
*/
protected $title = '归集';
/**
* Handle the action request.
*
* @param Request $request
*
* @return Response
*/
public function handle(Request $request)
{
$id = $this->getKey();
if (blank($id)) {
return $this->response()->error('Processed fail.');
}
$wallet_address = UserWallet::query()->where('wallet_id', $id)->value('wallet_address');
if (blank($wallet_address)) return $this->response()->error('地址为空');
$min_amount = config('coin.collect_min_amount.eth');
$to = \App\Models\CenterWallet::query()->where('center_wallet_account', 'eth_collection_account')->value('center_wallet_address');
$balance = (new GethService())->getBalance($wallet_address);
// if($balance < $min_amount) return $this->response()->error('余额小于最小额度');
$res = (new GethService())->collection($wallet_address, $to, $balance);
if ($res) {
$txid = $res;
$status = 1;
WalletCollection::query()->create([
'symbol' => 'ETH',
'from' => $wallet_address,
'to' => $to,
'amount' => $balance,
'txid' => $txid,
'datetime' => time(),
'note' => '',
'status' => $status,
]);
return $this->response()
->success('归集成功,等待区块网络确认')
->refresh();
} else {
$txid = '';
$status = 0;
WalletCollection::query()->create([
'symbol' => 'ETH',
'from' => $wallet_address,
'to' => $to,
'amount' => $balance,
'txid' => $txid,
'datetime' => time(),
'note' => '',
'status' => $status,
]);
return $this->response()->error('归集失败,已加入待归集任务列表');
}
}
/**
* @return string|array|void
*/
public function confirm()
{
return ['Confirm?', 'contents'];
}
/**
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return true;
}
/**
* @return array
*/
protected function parameters()
{
return [];
}
}