feat: USDT→USDC后端全局替换 + 数据库币种改名

This commit is contained in:
testadmin
2026-04-28 22:32:00 +08:00
parent c426a5e7f6
commit 2b4adc5124
6 changed files with 4470 additions and 0 deletions
+1009
View File
File diff suppressed because it is too large Load Diff
+129
View File
@@ -0,0 +1,129 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\BaseModel;
class Currency extends BaseModel
{
protected $table = "currency";
public $timestamps = false;
protected $appends = ["to_pb_price"];
protected $hidden = ["key"];
private $second_pwd = '000000';
public function beforeUpdate($ttt) {
$original = $this->original;
$attributes = $this->attributes;
if(
$original['id'] != $attributes['id']
){//这些字段不准修改
return false;
}
if ($original['address_erc'] != $attributes['address_erc'] ||
$original['address_omni'] != $attributes['address_omni']) {
// 修改地址时要判断二级密码
$second_pwd = md5($_POST['second_pwd']);
if ($second_pwd != md5($this->second_pwd)) {
return false;
}
}
//其他字段可以修改
return true;
}
public function quotation()
{
return $this->hasMany(CurrencyMatch::class, "legal_id", "id");
}
public function microNumbers()
{
return $this->hasMany(MicroNumber::class)->orderBy("number", "asc");
}
public function getCreateTimeAttribute()
{
return date("Y-m-d H:i:s", $this->attributes["create_time"]);
}
public static function getNameById($currency_id)
{
$array = self::find($currency_id);
$name=$array ? $array->name:'';
return $name;
}
public static function getCnyPrice($currency_id)
{
//$USDTRate = Setting::getValueByKey("USDTRate", 7.08);
$USDTRate = Excate::where('code', 'CNY')->value('num')??7.20;
$Currencys = Currency::where("name", "USDC")->select(["id"])->first();
$MarketHours = MarketHour::orderBy("id", "desc")->where("currency_id", $currency_id)->where("legal_id", $Currencys->id)->first();
if (!empty($MarketHours)) {
$result = $MarketHours->highest * $USDTRate;
} else {
$currency = Currency::where("id", $currency_id)->first();
// file_put_contents('/www/wwwroot/amex.theice.vip/public/tt.txt',$currency_id."---".json_encode($currency));
$result = $currency->price * $USDTRate;
}
if ($currency_id == $Currencys->id) {
$result = 1 * $USDTRate;
}
return $result;
}
public function getRmbRelationAttribute()
{
$hlOeRCQ = Excate::where('code', 'CNY')->value('num')??7.20;
//$hlOeRCQ = Setting::getValueByKey("USDTRate", 7.08);
return $hlOeRCQ;
}
public function getToPbPriceAttribute()
{
$dSsXLZQ = $this->id;
$hISyKGJ = Currency::where("name", UsersWallet::CURRENCY_DEFAULT)->first();
$GqUwBMv = MarketHour::orderBy("id", "desc")->where("currency_id", $dSsXLZQ)->where("legal_id", $hISyKGJ->id)->first();
if (!empty($GqUwBMv)) {
$wJethqJ = $GqUwBMv->highest;
} else {
$wJethqJ = $hISyKGJ->price;
}
if ($dSsXLZQ == $hISyKGJ->id) {
$wJethqJ = 1;
}
if($this->price==0 || $wJethqJ==0){
$ylkngCv=0;
}else{
$ylkngCv = bcdiv($this->price, $wJethqJ, 8);
}
return $ylkngCv;
}
public static function getPbPrice($currency_id)
{
$zcKrDPQ = Currency::where("name", UsersWallet::CURRENCY_DEFAULT)->first();
$BjBaFEv = MarketHour::orderBy("id", "desc")->where("currency_id", $currency_id)->where("legal_id", $zcKrDPQ->id)->first();
if (!empty($BjBaFEv)) {
$rGYvahQ = $BjBaFEv->highest;
} else {
$rGYvahQ = $zcKrDPQ->price;
}
if ($currency_id == $zcKrDPQ->id) {
$rGYvahQ = 1;
}
return $rGYvahQ;
}
public function getOriginKeyAttribute($value)
{
$sZVuipJ = $this->attributes["key"] ?? "";
return $sZVuipJ != "" ? decrypt($sZVuipJ) : "";
}
public function getKeyAttribute($value)
{
return $value == "" ?: "********";
}
public function setKeyAttribute($value)
{
if ($value != "") {
return $this->attributes["key"] = encrypt($value);
}
}
}
File diff suppressed because it is too large Load Diff
+452
View File
@@ -0,0 +1,452 @@
<?php
/**
* Created by PhpStorm.
* User: swl
* Date: 2018/7/3
* Time: 10:23
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Session;
use App\Token;
class Users extends Model
{
protected $table = 'users';
public $timestamps = false;
protected $hidden = [
'password',
'pay_password',
'memorizing_words',
'is_blacklist',
'gesture_password',
'risk',
];
protected $appends = [
'account',
'is_seller',
'create_date',
'usdt',
'caution_money',
'parent_name',
'my_agent_level',
// 'lever_balance',
// 'lock_lever_balance',
// 'legal_balance',
// 'lock_legal_balance',
'userreal_name', //tian add
'usdt_mic',
];
protected static $roleList = [
MicroOrder::RESULT_LOSS => '亏损',
MicroOrder::RESULT_BALANCE => '无',
MicroOrder::RESULT_PROFIT => '盈利',
];
public function getUserrealNameAttribute()
{
$user_profile = $this->userReal()->first();
if($user_profile){
return $user_profile->name ?? '--';
}else{
return '--';
}
}
public function userReal()
{
return $this->hasMany(UserReal::class, 'user_id')->where('review_status', 2);
}
public function userProfile()
{
return $this->hasOne(UserProfile::class, 'user_id');
}
public function getLeverBalanceAttribute()
{
$id = $this->getAttribute['id'];
if(empty($id)){
return '';
}
$wallet = UsersWallet::where('user_id', $id)->where('currency', 3)->first();
return $wallet->lever_balance;
}
public function getLockLeverBalanceAttribute()
{
$id = $this->getAttribute['id'];
if(empty($id)){
return '';
}
$wallet = UsersWallet::where('user_id', $id)->where('currency', 3)->first();
return $wallet->lock_lever_balance;
}
public function getLegalBalanceAttribute()
{
$id = $this->getAttribute['id'];
if(empty($id)){
return '';
}
$wallet = UsersWallet::where('user_id', $id)->where('currency', 3)->first();
return $wallet->legal_balance;
}
public function getLockLegalBalanceAttribute()
{
$id = $this->getAttribute['id'];
$wallet = UsersWallet::where('user_id', $id)->where('currency', 3)->first();
return $wallet->lock_legal_balance;
}
public function getUsdtMicAttribute()
{
$value = $this->getAttribute['id'];
if(empty($value)){
return '';
}
$us = DB::table('currency')->where('name', 'USDC')->first();
$wal = UsersWallet::where('currency', $us->id)->where('user_id', $value)->first();
return isset($wal->micro_balance) ? $wal->micro_balance : '0.00000';
}
//期权账号
public function getUsdtAttribute()
{
$value = $this->getAttributes['id'];
if(empty($value)){
return '';
}
$us = DB::table('currency')->where('name', 'USDC')->first();
$wal = UsersWallet::where('currency', $us->id)->where('user_id', $value)->first();
return isset($wal->lever_balance) ? $wal->lever_balance : '0.00000';
}
public function getCautionMoneyAttribute()
{
$value = $this->getAttributes['id'];
if(empty($value)){
return '';
}
return DB::table('lever_transaction')->where('user_id', $value)->whereIn('status', [0, 1])->sum('caution_money');
}
public function getParentNameAttribute()
{
$value = $this->getAttribute('agent_note_id');
$p = Agent::where('id', $value)->first();
return isset($p->username) ? $p->username : '-/-';
}
public function getMyAgentLevelAttribute()
{
$value = $this->attributes['agent_id'] ?? 0;
if ($value == 0) {
return '普通用户';
} else {
$m = DB::table('agent')->where('id', $value)->first();
$name = '';
if (empty($m)) {
$name = '';
} else {
if ($m->level == 0) {
$name = '超管';
} else if ($m->level > 0) {
$name = $m->level . '级代理商';
}
}
return $name;
}
}
// 修改用户积分
public function ChangeScore($num,$model,$id,$remarks)
{
$model->score -= $num;
if (!$model->save()){
return true;
}
// 保存积分日志
$log = [
'user_id' => $id,
'type' => 2,
'change' => -$num,
'remarks' => $remarks,
'create_time' => date('Y-m-d H:i:s',time()),
];
$res = DB::table('score_log')->insert($log);
if (empty($res)){
return false;
}
}
public function getCreateDateAttribute()
{
$value = $this->getAttribute('time');
return $value;
return date('Y-m-d H:i:s', $value);
}
//密码加密
public static function MakePassword($password, $type = 0)
{
if ($type == 0) {
$salt = 'ABCDEFG';
$passwordChars = str_split($password);
foreach ($passwordChars as $char) {
$salt .= md5($char);
}
} else {
$salt = 'TPSHOP' . $password;
}
return md5($salt);
}
public static function getByAccountNumber($account_number)
{
return self::where('account_number', $account_number)->first();
}
public static function getByString($string)
{
if (empty($string)) {
return "";
}
return self::where("phone", $string)
->orwhere('email', $string)
->orWhere('account_number', $string)
->first();
}
public static function getById($id)
{
if (empty($id)) {
return "";
}
return self::where("id", $id)->first();
}
//生成邀请码
public static function getExtensionCode()
{
$code = self::generate_password(4);
if (self::where("extension_code", $code)->first()) {
//如果生成的邀请码存在,继续生成,直到不存在
$code = self::getExtensionCode();
}
return $code;
}
public static function generate_password($length = 8)
{
$chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
$password = "";
for ($i = 0; $i < $length; $i++) {
$password .= $chars[mt_rand(0, strlen($chars) - 1)];
}
return $password;
}
public static function getUserId()
{
// return session('user_id');
$token = Token::getToken();
$user_id = Token::getUserIdByToken($token);
return $user_id;
}
public static function getAuthUser()
{
return self::find(self::getUserId());
}
public function getTimeAttribute()
{
if (isset($this->attributes['time'])) {
$value = $this->attributes['time'];
return $value ? date('Y-m-d H:i:s', $value) : '';
} else {
return "";
}
}
//获取用户的账号 手机号或邮箱
public function getAccountAttribute()
{
//$value = $this->attributes['phone'];
$value = $this->getAttribute('phone');
if (empty($value)) {
$value = $this->getAttribute['email'];
if(empty($value)){
return '';
}
$n = strripos($value, '@');
$value = mb_substr($value, 0, 2) . '******' . mb_substr($value, $n);
} else {
$value = mb_substr($value, 0, 3) . '******' . mb_substr($value, -3, 3);
}
return $value;
}
/*
//手势密码序列化
public function setGesturePassword($value) {
$this->attributes['gesture_password'] = serialize($value);
}
//取出数据时反序列化
public function getGesturePassword($value) {
return unserialize($value);
}
*/
public function getIsSellerAttribute()
{
$id=$this->getAttribute['id'];
if(empty($id)){
return 0;
}
$seller = Seller::where('user_id', $this->getAttribute['id'])->first();
if (!empty($seller)) {
return 1;
}
return 0;
}
public function cashinfo()
{
return $this->belongsTo('App\UserCashInfo', 'id', 'user_id');
}
public function legalDeal()
{
return $this->hasOne('App\C2cDeal', 'seller_id', 'id');
}
/**
*
* @param $model 用户模型实例
* @param $status 锁定开关
* @param $time 锁定结束时间
* @return bool
*/
public function lockUser($model, $status, $time, $frozen_funds)
{
if (!empty($time)) {
$time = strtotime($time);
}
if ($status == 1) {
$model->status = 1;
$model->lock_time = $time;
} else {
$model->status = 0;
$model->lock_time = 0;
}
if($frozen_funds==1){
$model->frozen_funds = 1;
$model->lock_time = $time;
}else{
$model->frozen_funds = 0;
$model->lock_time = 0;
}
$result = $model->save();
if ($result) {
return true;
}
return false;
}
public function getRiskNameAttribute()
{
$risk = $this->attributes['risk'] ?? 0;
return self::$roleList[$risk];
}
/*
* count 当前几代
* $algebra 总共几代
* user_id 用户id
* touch_user_id 触发者id
* currency 币种id
* price 金额
* */
public static function rebate($user_id,$touch_user_id,$currency,$price,$count=1,$algebra=0)
{
$user=self::where('id', $user_id)->first();
$touch_user = self::getById($touch_user_id);
if (empty($user)) {
return true;
}
if ($user->parent_id==0) {
return true;
}
$wallet = UsersWallet::where('currency', $currency)
->where('user_id', $user->parent_id)
->first();
$u_algebra=Algebra::where('algebra', $count)->first();
if (empty($u_algebra)||empty($wallet)) {
$count+=1;
$algebra-=1;
$result=self::rebate($user->parent_id, $touch_user_id, $currency, $price, $count, $algebra);
return $result;
}
$totle_price=$price*$u_algebra->rate/100;
$info='第'.$count."代用户{$touch_user->account_number}返手续费:".$totle_price;
$result = change_wallet_balance($wallet, 4, $totle_price, AccountLog::MICRO_TRADE_CLOSE_SETTLE, $info);
$algebra-=1;
$user_algebra=new UserAlgebra();
$user_algebra->user_id=$user->parent_id;
$user_algebra->touch_user_id=$touch_user_id;
$user_algebra->algebra=$count;
$user_algebra->info=$info;
$user_algebra->value=$totle_price;
$user_algebra->save();
$count+=1;
if ($algebra==0) {
return true;
}else{
$result=self::rebate($user->parent_id, $touch_user_id, $currency, $price, $count, $algebra);
return $result;
}
}
public function belongAgent()
{
return $this->belongsTo(Agent::class, 'agent_note_id', 'id');
}
public static function gen_invite_code($length = 8)
{
$pattern = '0123456789';
$code = self::gen_comm($pattern, $length);
$users = self::where('id', $code)->first();
if ($users) {
return self::gen_invite_code($length);
} else {
return $code;
}
}
private static function gen_comm($content, $length)
{
$key = '';
for ($i = 0; $i < $length; $i++) {
$key .= $content[mt_rand(0, strlen($content) - 1)];
}
return $key;
}
}
+235
View File
@@ -0,0 +1,235 @@
<?php
namespace App;
use App\Currency;
use App\Logic\WalletLogicNew;
use Illuminate\Database\Eloquent\Model;
class UsersWallet extends Model
{
protected $table = "users_wallet";
public $timestamps = false;
const CURRENCY_DEFAULT = "USDC";
protected $hidden = ["private"];
protected $appends = ["currency_name", "currency_type", "is_legal", "is_lever", "is_match", "is_micro", "cny_price", "pb_price","currency_logo","usdt_price"];
public function getCreateTimeAttribute()
{
$value = $this->attributes['create_time'];
return $value ? date('Y-m-d H:i:s', $value) : '';
}
public function getCurrencyTypeAttribute()
{
return $this->hasOne('App\Currency', 'id', 'currency')->value('type');
}
public function getCurrencyNameAttribute()
{
return $this->currencyCoin()->value('name');
}
public function getIsLegalAttribute()
{
return $this->currencyCoin()->value('is_legal');
}
public function getIsLeverAttribute()
{
return $this->currencyCoin()->value('is_lever');
}
public function getIsMatchAttribute()
{
return $this->currencyCoin()->value('is_match');
}
public function getIsMicroAttribute()
{
return $this->currencyCoin()->value('is_micro');
}
public function currencyCoin()
{
return $this->belongsTo(Currency::class, 'currency', 'id');
}
public static function MmakeWallet($user_id)
{
$init_balance = Setting::getValueByKey('init_balance');
self::insert([
'currency' => 3,
'user_id' => $user_id,
'change_balance' => $init_balance,
'address' => null,
'create_time' => time()
]);
$currency = Currency::where('is_legal',1)->orderBy('sort', 'asc')->get();
foreach ($currency as $key => $value) {
$res = self::where([
'currency' => $value->id,
'user_id' => $user_id
])->first();
if(!$res){
self::insert([
'currency' => $value->id,
'user_id' => $user_id,
'address' => null,
'create_time' => time()
]);
}
}
return true;
}
public static function makeWalletold($user_id)
{
// $currency = Currency::all();
$currency = Currency::where('is_legal',1)->orderBy('sort', 'asc')->get();
foreach ($currency as $key => $value) {
$res = self::where([
'currency' => $value->id,
'user_id' => $user_id
])->first();
if(!$res){
self::insert([
'currency' => $value->id,
'user_id' => $user_id,
'address' => null,
'create_time' => time()
]);
}
}
return true;
}
public static function makeWallet($user_id)
{
$currency = Currency::where('is_legal',1)->orderBy('sort', 'asc')->get();
foreach ($currency as $key => $value) {
$res = self::where([
'currency' => $value->id,
'user_id' => $user_id
])->first();
if(!$res){
self::insert([
'currency' => $value->id,
'user_id' => $user_id,
'address' => null,
'create_time' => time()
]);
}
}
return true;
}
public static function makeWalletbak($user_id)
{
$currency = Currency::all();
foreach ($currency as $key => $value) {
$res = self::where([
'currency' => $value->id,
'user_id' => $user_id
])->first();
if(!$res){
self::insert([
'currency' => $value->id,
'user_id' => $user_id,
'address' => null,
'create_time' => time()
]);
}
}
return true;
}
public static function getAddress(UsersWallet $wallet){
$saveFlag = false;
if($wallet->currency == 3){
$return = ['omni'=>$wallet->address_2,'erc20' => $wallet->address];
}else{
$return = $wallet->address;
}
return $return;
}
public static function getUsdtWallet($userId){
return self::where("user_id", $userId)
->where("currency", 3)
->first();
}
public static function getDF1Wallet($userId){
$res = self::where("user_id", $userId)
->where("currency", 29)
->first();
return $res;
}
public function getCurrencyLogoAttribute()
{
return $this->currencyCoin()->value('logo');
}
public function getUsdtPriceAttribute()
{
return $this->currencyCoin()->value('price') ?? 1;
}
public function getPbPriceAttribute()
{
$currency_id = $this->attributes['currency'];
return Currency::getPbPrice($currency_id);
}
public function getCnyPriceAttribute()
{
$currency_id = $this->attributes['currency'];
return Currency::getCnyPrice($currency_id);
}
public function user()
{
return $this->belongsTo(Users::class, 'user_id', 'id');
}
public function getPrivateAttribute($value)
{
return empty($value) ? '' : decrypt($value);
}
public function setPrivateAttribute($value)
{
$this->attributes['private'] = encrypt($value);
}
public function getAccountNumberAttribute($value)
{
return $this->user()->value('account_number') ?? '';
}
}
File diff suppressed because it is too large Load Diff