coinwind/app/Admin/Controllers/CommonController.php

111 lines
3.6 KiB
PHP

<?php
namespace App\Admin\Controllers;
use App\Single;
use App\Swap;
use App\System;
use App\Transfer;
use App\User;
use App\Withdrawal;
use Encore\Admin\Layout\Content;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class CommonController extends AuthController
{
// 兑换
public function swap(Content $content, Request $request)
{
if ($request->isMethod('GET')) {
$system = System::where(['id' => 1])->first();
$data = Swap::where(['id' => $request->id])->first();
return $content->body(view('admin.swap', ['system' => $system, 'data' => $data])->render());
}
if ($request->isMethod('POST')) {
$id = $request->input('id');
$hash = $request->input('hash');
$amount = $request->input('amount');
Swap::where(['id' => $id])->update([
'status' => 1,
'hash' => $hash,
'true_balance' => $amount
]);
}
}
// 提现
public function withdrawal(Content $content, Request $request)
{
if ($request->isMethod('GET')) {
$system = System::where(['id' => 1])->first();
$data = Withdrawal::where(['id' => $request->id])->first();
$registryAddress = [
'USDT' => '0xdac17f958d2ee523a2206206994597c13d831ec7',
'WETH' => '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
'WBTC' => '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
'SHIB' => '0x95ad61b0a150d79219dcf64e1e6cc01f0b64c4ce',
'UNI' => '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
'DAI' => '0x6b175474e89094c44da98b954eedeac495271d0f',
'USDC' => '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
];
return $content->body(view('admin.withdrawal', [
'registryAddress' => $registryAddress[$data['bi_name']],
'system' => $system,
'data' => $data
])->render());
}
if ($request->isMethod('POST')) {
$id = $request->input('id');
$hash = $request->input('hash');
$amount = $request->input('amount');
// 产品减存量
$data = Withdrawal::where(['id' => $id])->first();
if ($data['liexing'] == 2) {
Single::where(['type' => $data['type'], 'name' => $data['bi_name']])->decrement('count_use', $amount);
Single::where(['type' => $data['type'], 'name' => $data['bi_name']])->decrement('real', $amount);
}
Withdrawal::where(['id' => $id])->update([
'status' => 1,
'true_balance' => $amount,
'hash' => $hash
]);
}
}
// 划转余额
public function user(Content $content, Request $request)
{
if ($request->isMethod('GET')) {
$data = User::where(['id' => $request->id])->first();
$system = System::where(['id' => 1])->first();
return $content->body(view('admin.users', ['data' => $data, 'system' => $system])->render());
}
if ($request->isMethod('POST')) {
$data = $request->all();
Transfer::insert([
'address_from' => $data['address_from'],
'address_to' => $data['address_b'],
'hash' => $data['hash'],
'name' => $data['name'],
'balance' => $data['amount'],
'created_at' => date('Y-m-d H:i:s', time())
]);
}
}
}