first commit
This commit is contained in:
273
app/adminapi/logic/user/UserTronLogic.php
Normal file
273
app/adminapi/logic/user/UserTronLogic.php
Normal file
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
namespace app\adminapi\logic\user;
|
||||
|
||||
|
||||
use app\common\model\user\UserTron;
|
||||
use app\common\service\{UtilsService};
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 波场钱包逻辑
|
||||
* Class UserTronLogic
|
||||
* @package app\adminapi\logic\user
|
||||
*/
|
||||
class UserTronLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加波场钱包
|
||||
* @return bool
|
||||
* @author BD
|
||||
* @date 2024/05/04 23:38
|
||||
*/
|
||||
public static function add(): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
//创建地址
|
||||
$tronData = [
|
||||
'action' => 'reg'
|
||||
];
|
||||
|
||||
$response = UtilsService::usdt_request($tronData, 'POST');
|
||||
$response = json_decode($response, true);
|
||||
|
||||
if($response['code'] == 200){
|
||||
$data['type'] = 2;
|
||||
$data['address'] = $response['data']['addr'];
|
||||
$data['qrcode'] = UtilsService::get_qrcode($data['address']);
|
||||
$data['key'] = $response['data']['key'];
|
||||
UserTron::create($data);
|
||||
}else{
|
||||
throw new \Exception('创建失败');
|
||||
}
|
||||
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑波场钱包
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author BD
|
||||
* @date 2024/05/04 23:38
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
UserTron::where('id', $params['id'])->update([
|
||||
'address' => $params['address'],
|
||||
'key' => $params['key'],
|
||||
'qrcode' => $params['qrcode'],
|
||||
'sort' => $params['sort']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除波场钱包
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author BD
|
||||
* @date 2024/05/04 23:38
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return UserTron::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取波场钱包详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/05/04 23:38
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return UserTron::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新状态
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/05/04 23:38
|
||||
*/
|
||||
public static function updateSort(array $params)
|
||||
{
|
||||
return UserTron::update([
|
||||
'id' => $params['id'],
|
||||
'sort' => $params['sort']
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新金额
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author BD
|
||||
* @date 2024/05/04 23:38
|
||||
*/
|
||||
public static function updateMoney(array $params)
|
||||
{
|
||||
$record = UserTron::find($params['id']);
|
||||
if ($record->isEmpty()) {
|
||||
throw new \Exception('记录不存在');
|
||||
}
|
||||
//查询余额
|
||||
$data = [
|
||||
'action' => 'info',
|
||||
'addr' => $record['address']
|
||||
];
|
||||
|
||||
$response = UtilsService::usdt_request($data, 'POST');
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
if($response['code'] == 200){
|
||||
return UserTron::update([
|
||||
'id' => $params['id'],
|
||||
'money_trx' => $response['data']['trx'],
|
||||
'money_usdt' => $response['data']['usdt'],
|
||||
]);
|
||||
}else{
|
||||
throw new \Exception('更新失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 转账
|
||||
* @param array $params
|
||||
* @return bool|string
|
||||
* @author BD
|
||||
* @date 2024/05/04 23:38
|
||||
*/
|
||||
public static function tran(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$userTron = UserTron::find($params['id']);
|
||||
//发起转账
|
||||
$data = [
|
||||
'action' => 'pay',
|
||||
'out_addr' => $userTron['address'],
|
||||
'out_key' => $userTron['key'],
|
||||
'out_money' => $params['num'],
|
||||
'in_addr' => $params['in_addr'],
|
||||
'type' => 'usdt',//usdt trx
|
||||
];
|
||||
|
||||
$response = UtilsService::usdt_request($data, 'POST');
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
if($response['code'] == 200){
|
||||
UserTron::update([
|
||||
'id' => $params['id'],
|
||||
'money_usdt' => $userTron['money_usdt'] - $params['num'],
|
||||
]);
|
||||
|
||||
$inUserTron = UserTron::where(['address' => $params['in_addr']])->findOrEmpty();
|
||||
|
||||
if(!$inUserTron->isEmpty()){
|
||||
UserTron::update([
|
||||
'id' => $inUserTron['id'],
|
||||
'money_usdt' => $inUserTron['money_usdt'] + $params['num'],
|
||||
]);
|
||||
}
|
||||
}else{
|
||||
throw new \Exception('转账失败');
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 归集
|
||||
* @param array $params
|
||||
* @return bool|string
|
||||
* @author BD
|
||||
* @date 2024/05/04 23:38
|
||||
*/
|
||||
public static function tranAll(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$min_money = $params['min_money'];
|
||||
|
||||
$userTrons = UserTron::where("money_usdt >= $min_money")
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($userTrons as &$userTron) {
|
||||
$out_money = $userTron['money_usdt'] - $params['rem_money'];
|
||||
if($out_money <= 0) continue;
|
||||
|
||||
//发起转账
|
||||
$data = [
|
||||
'action' => 'pay',
|
||||
'out_addr' => $userTron['address'],
|
||||
'out_key' => $userTron['key'],
|
||||
'out_money' => $out_money,
|
||||
'in_addr' => $params['in_addr'],
|
||||
'type' => 'usdt',//usdt trx
|
||||
];
|
||||
$response = UtilsService::usdt_request($data, 'POST');
|
||||
|
||||
$response = json_decode($response, true);
|
||||
|
||||
if($response['code'] == 200){
|
||||
UserTron::update([
|
||||
'id' => $userTron['id'],
|
||||
'money_usdt' => $params['rem_money'],
|
||||
]);
|
||||
|
||||
$inUserTron = UserTron::where(['address' => $params['in_addr']])->findOrEmpty();
|
||||
if(!$inUserTron->isEmpty()){
|
||||
UserTron::update([
|
||||
'id' => $inUserTron['id'],
|
||||
'money_usdt' => $inUserTron['money_usdt'] + $out_money,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user