|
|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use App\Models\Config;
|
|
|
use App\Services\BaseService;
|
|
|
use App\Models\Wallet;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
@@ -16,14 +17,14 @@ use App\Services\BalanceLogService;
|
|
|
|
|
|
/**
|
|
|
* 用户虚拟币钱包
|
|
|
-*/
|
|
|
-class WalletService extends BaseService
|
|
|
+ */
|
|
|
+class WalletService extends BaseService
|
|
|
{
|
|
|
/**
|
|
|
* @description: 模型
|
|
|
* @return {string}
|
|
|
- */
|
|
|
- public static function model() :string
|
|
|
+ */
|
|
|
+ public static function model(): string
|
|
|
{
|
|
|
return Wallet::class;
|
|
|
}
|
|
|
@@ -31,8 +32,8 @@ class WalletService extends BaseService
|
|
|
/**
|
|
|
* @description: 枚举
|
|
|
* @return {*}
|
|
|
- */
|
|
|
- public static function enum() :string
|
|
|
+ */
|
|
|
+ public static function enum(): string
|
|
|
{
|
|
|
return '';
|
|
|
}
|
|
|
@@ -41,29 +42,29 @@ class WalletService extends BaseService
|
|
|
* @description: 获取查询条件
|
|
|
* @param {array} $search 查询内容
|
|
|
* @return {array}
|
|
|
- */
|
|
|
- public static function getWhere(array $search = []) :array
|
|
|
+ */
|
|
|
+ public static function getWhere(array $search = []): array
|
|
|
{
|
|
|
$where = [];
|
|
|
- if(isset($search['coin']) && !empty($search['coin'])){
|
|
|
+ if (isset($search['coin']) && !empty($search['coin'])) {
|
|
|
$where[] = ['coin', '=', $search['coin']];
|
|
|
}
|
|
|
- if(isset($search['net']) && !empty($search['net'])){
|
|
|
+ if (isset($search['net']) && !empty($search['net'])) {
|
|
|
$where[] = ['net', '=', $search['net']];
|
|
|
}
|
|
|
- if(isset($search['address']) && !empty($search['address'])){
|
|
|
+ if (isset($search['address']) && !empty($search['address'])) {
|
|
|
$where[] = ['address', '=', $search['address']];
|
|
|
}
|
|
|
- if(isset($search['id']) && !empty($search['id'])){
|
|
|
+ if (isset($search['id']) && !empty($search['id'])) {
|
|
|
$where[] = ['id', '=', $search['id']];
|
|
|
}
|
|
|
- if(isset($search['member_id']) && !empty($search['member_id'])){
|
|
|
+ if (isset($search['member_id']) && !empty($search['member_id'])) {
|
|
|
$where[] = ['member_id', '=', $search['member_id']];
|
|
|
}
|
|
|
return $where;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* @description: 查询单条数据
|
|
|
* @param array $search
|
|
|
* @return \App\Models\Coin|null
|
|
|
@@ -90,7 +91,7 @@ class WalletService extends BaseService
|
|
|
*/
|
|
|
public static function paginate(array $search = [])
|
|
|
{
|
|
|
- $limit = isset($search['limit'])?$search['limit']:15;
|
|
|
+ $limit = isset($search['limit']) ? $search['limit'] : 15;
|
|
|
$paginator = self::model()::where(self::getWhere($search))->paginate($limit);
|
|
|
return ['total' => $paginator->total(), 'data' => $paginator->items()];
|
|
|
}
|
|
|
@@ -99,7 +100,7 @@ class WalletService extends BaseService
|
|
|
* @description: 为用户创建虚拟钱包
|
|
|
* @param {int} $memberId 用户ID
|
|
|
* @return {*}
|
|
|
- */
|
|
|
+ */
|
|
|
public static function createVirtualWallets(int $memberId)
|
|
|
{
|
|
|
$coins = CoinService::findAll(['coin' => 'USDT']);
|
|
|
@@ -107,9 +108,9 @@ class WalletService extends BaseService
|
|
|
$users = UserService::findOne(['member_id' => $memberId]);
|
|
|
|
|
|
|
|
|
- $walletsData = $coins->map(function($coin) use ($memberId,$users) {
|
|
|
+ $walletsData = $coins->map(function ($coin) use ($memberId, $users) {
|
|
|
|
|
|
- switch($coin->coin){
|
|
|
+ switch ($coin->coin) {
|
|
|
case 'USDT':
|
|
|
$trons = TronHelper::createAddress($memberId);
|
|
|
break;
|
|
|
@@ -122,40 +123,40 @@ class WalletService extends BaseService
|
|
|
'member_id' => $memberId,
|
|
|
'coin' => $coin->coin,
|
|
|
'net' => $coin->net,
|
|
|
- 'address' => $trons['address']??'',
|
|
|
- 'private_key' => $trons['private_key']??'',
|
|
|
+ 'address' => $trons['address'] ?? '',
|
|
|
+ 'private_key' => $trons['private_key'] ?? '',
|
|
|
'available_balance' => 0,
|
|
|
'frozen_balance' => 0
|
|
|
];
|
|
|
|
|
|
})->toArray();
|
|
|
-
|
|
|
+
|
|
|
// 批量创建钱包以提高性能
|
|
|
self::model()::insert($walletsData);
|
|
|
|
|
|
return self::findAll(['member_id' => $memberId]);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @description: 获取用户的钱包
|
|
|
- * @param {int} $memberId
|
|
|
+ * @param {int} $memberId
|
|
|
* @return {*}
|
|
|
- */
|
|
|
+ */
|
|
|
public static function getUserWallet(int $memberId)
|
|
|
{
|
|
|
$wallets = self::findAll(['member_id' => $memberId]);
|
|
|
|
|
|
- if($wallets->isEmpty()){
|
|
|
+ if ($wallets->isEmpty()) {
|
|
|
$wallets = self::createVirtualWallets($memberId);
|
|
|
}
|
|
|
|
|
|
- $wallets->map(function($wallet) {
|
|
|
- $wallet->available_balance = removeZero($wallet->available_balance);
|
|
|
- $wallet->frozen_balance = removeZero($wallet->frozen_balance);
|
|
|
- // $wallet->total_balance = $wallet->available_balance + $wallet->frozen_balance;
|
|
|
- return $wallet;
|
|
|
- });
|
|
|
+ $wallets->map(function ($wallet) {
|
|
|
+ $wallet->available_balance = removeZero($wallet->available_balance);
|
|
|
+ $wallet->frozen_balance = removeZero($wallet->frozen_balance);
|
|
|
+ // $wallet->total_balance = $wallet->available_balance + $wallet->frozen_balance;
|
|
|
+ return $wallet;
|
|
|
+ });
|
|
|
return $wallets;
|
|
|
}
|
|
|
|
|
|
@@ -163,14 +164,14 @@ class WalletService extends BaseService
|
|
|
* @description: 获取用户充值钱包地址
|
|
|
* @param {*} $memberId
|
|
|
* @return {*}
|
|
|
- */
|
|
|
+ */
|
|
|
public static function getRechargeImageAddress($memberId)
|
|
|
{
|
|
|
self::getUserWallet($memberId);
|
|
|
|
|
|
$info = self::findOne(['member_id' => $memberId]);
|
|
|
$path = self::rechargeQrCodeExists($info->address);
|
|
|
- if(empty($path)){
|
|
|
+ if (empty($path)) {
|
|
|
$path = self::createRechargeQrCode($info->address);
|
|
|
}
|
|
|
|
|
|
@@ -188,11 +189,11 @@ class WalletService extends BaseService
|
|
|
* @description: 获取平台充值钱包地址
|
|
|
* @param {*} $address
|
|
|
* @return {*}
|
|
|
- */
|
|
|
+ */
|
|
|
public static function getPlatformImageAddress($address)
|
|
|
{
|
|
|
- $path = self::rechargeQrCodeExists($address);
|
|
|
- if(empty($path)){
|
|
|
+ $path = self::rechargeQrCodeExists($address);
|
|
|
+ if (empty($path)) {
|
|
|
$path = self::createRechargeQrCode($address);
|
|
|
}
|
|
|
|
|
|
@@ -211,8 +212,8 @@ class WalletService extends BaseService
|
|
|
* @param {*} $memberId
|
|
|
* @param {*} $amount
|
|
|
* @return {*}
|
|
|
- */
|
|
|
- public static function updateBalance($memberId , $amount)
|
|
|
+ */
|
|
|
+ public static function updateBalance($memberId, $amount)
|
|
|
{
|
|
|
$data = [];
|
|
|
$self = self::findOne(['member_id' => $memberId]);
|
|
|
@@ -222,7 +223,7 @@ class WalletService extends BaseService
|
|
|
$self->save();
|
|
|
return $data;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @description: 获取用户余额
|
|
|
* @param {int} $memberId 用户ID
|
|
|
@@ -250,15 +251,21 @@ class WalletService extends BaseService
|
|
|
['text' => '➕ 提现', 'callback_data' => "withdraw@@apply"],
|
|
|
['text' => '🧾 提现账单', 'callback_data' => "withdraw@@bill"]
|
|
|
],
|
|
|
- [
|
|
|
+
|
|
|
+
|
|
|
+ ];
|
|
|
+ $three_payment_switch = Config::where('field', 'three_payment_switch')->first()->val;
|
|
|
+ if ($three_payment_switch == 1) {
|
|
|
+ $keyboard[] = [
|
|
|
['text' => '➕ 钱宝提现', 'callback_data' => "withdraw@@qb_apply"],
|
|
|
// ['text' => '🧾 提现账单', 'callback_data' => "withdraw@@bill"]
|
|
|
- ],
|
|
|
- [
|
|
|
- ['text' => '💵今日汇率💰', 'callback_data' => "todayExchangeRate@@rate"]
|
|
|
- ]
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $keyboard[] = [
|
|
|
+ ['text' => '💵今日汇率💰', 'callback_data' => "todayExchangeRate@@rate"]
|
|
|
];
|
|
|
|
|
|
+
|
|
|
return [
|
|
|
'chat_id' => $memberId,
|
|
|
'text' => $text,
|
|
|
@@ -266,5 +273,5 @@ class WalletService extends BaseService
|
|
|
'protect_content' => true
|
|
|
];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|