| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace App\Module\AppGame\Service;
- use App\Module\Fund\Enums\FUND_TYPE;
- use App\Module\Fund\Service\User;
- use App\Module\Ulogic\Model\WalletAddress;
- class WalletService
- {
- // 账户统计
- public static function stats($userId)
- {
- $fundIds = [FUND_TYPE::FUND1->value(), FUND_TYPE::USD->value(), FUND_TYPE::BNB->value()];
- $data = User::getAllAccount($userId, $fundIds);
- $data = array_column($data, 'balance', 'fund_id');
- $address = WalletAddress::getInfoByCondition('user_id', $userId);
- // 老用户没有默认地址,需要创建
- if (!$address) {
- // 生成uraus地址
- $addStr = WalletAddress::createAddress();
- $walletAddress = '0xuraus' . $addStr;
- WalletAddress::createRow($userId, $walletAddress);
- $address = WalletAddress::getInfoByCondition('user_id', $userId);
- }
- $result = [
- 'uraus' => $data[FUND_TYPE::FUND1->value()] ?? 0,
- 'usdt' => $data[FUND_TYPE::USD->value()] ?? 0,
- 'bnb' => $data[FUND_TYPE::BNB->value()] ?? 0,
- 'address' => $address->address
- ];
- return $result;
- }
- /**
- * @param $userId
- * @param $type
- * @return array|false
- * @throws \Exception
- * 资金详情
- */
- public static function walletDetail($userId, $type)
- {
- // proto枚举
- $map = [
- 1 => FUND_TYPE::FUND1->value(),
- 2 => FUND_TYPE::USD->value(),
- 3 => FUND_TYPE::BNB->value()
- ];
- $fundId = $map[$type];
- $fundData = User::get_account($userId, $fundId, true);
- $address = WalletAddress::getInfoByCondition('user_id', $userId);
- return [
- 'type' => $type,
- 'balance' => $fundData->balance,
- 'address' => $address->address,
- ];
- }
- }
|