afa 11 сар өмнө
parent
commit
d809505780

+ 2 - 2
application/api/controller/Ledger.php

@@ -24,7 +24,7 @@ class Ledger extends Api
     protected array $noNeedLogin = ['withdrawCallback'];
 
     /**
-     * 资产首页
+     * 资产首页  
      */
     public function assets()
     {
@@ -45,7 +45,7 @@ class Ledger extends Api
                 'coin_key' => 'usdt',
                 'amount' => $info['usdt']??0,
                 'frozen_amount' => $this->auth->frozen_amount, //冻结金额
-                'convert_amount'=>  $this->auth->convert_amount //折合金额
+                'convert_rate'  => getConfig('convert_rate')   //折合比例
             ]
         ];
         $this->success('', $res);

+ 5 - 10
application/api/controller/Offline.php

@@ -32,13 +32,9 @@ class Offline extends Api
     {
         $resp   = [
             'usdt'                => '0', // 系统余额(U)
-            'withdraw_min_amount' => Env::get('rental.withdraw_min_amount'), // 最低提现U数量
-            'withdraw_fee_rate'   => Env::get('rental.withdraw_fee_rate') // 手续费比例
+            'withdraw_min_amount' => getConfig('withdraw_min_amount'), // 最低提现U数量
+            'withdraw_fee_rate'   => getConfig('withdrawal_fee')       // 手续费比例
         ];
-        $wallet = (new LedgerWalletModel)->getWallet($this->auth->getTokenUserID());
-        if (!empty($wallet)) {
-            $resp['usdt'] = $wallet['usdt'];
-        }
         $this->success('', $resp);
     }
 
@@ -53,10 +49,9 @@ class Offline extends Api
         if(empty($sign)){
             $this->error('参数错误');
         }
-
-        $real   = $amount; // 实际到账
-        $min    = Env::get('rental.withdraw_min_amount');
-        $rate   = Env::get('rental.withdraw_fee_rate');
+        $real   = bcdiv($amount, getConfig('convert_rate'), 6); // 折合转换 U = 1
+        $min    = getConfig('withdraw_min_amount');
+        $rate   = getConfig('withdrawal_fee');
         if ($amount <= 0) {
             $this->error('提现金额必须大于0');
         } else if ($amount < $min) {

+ 60 - 8
application/common/model/LedgerWalletModel.php

@@ -63,6 +63,65 @@ class LedgerWalletModel extends Model
         return $this->lock(true)->where('user_id', $userID)->find();
     }
 
+    /**
+     * 更新钱包余额并添加账变记录
+     * @param int $uid 用户ID
+     * @param string $asset 资产类型
+     * @param string $amount 金额 正:表示加 负:表示减
+     * @param int $action 账变类型
+     * @return void
+     * @throws Exception
+     */
+    public function changeWalletAccount(int $uid, string $asset, string $amount, int $action, int $from_id = 0)
+    {
+        $available = $this->getWallet($uid);
+        if (empty($available)) {
+            // 创建钱包
+            (new LedgerWalletModel())->insertGetId([
+                'user_id' => $uid,
+            ]);
+        }
+        // 账变资产模型
+        switch ($asset) {
+            case Asset::POWER:
+                $changeModel = new LedgerPowerChangeModel();
+                break;
+            case Asset::USDT:
+                $changeModel = new LedgerUsdtChangeModel();
+                break;
+            case Asset::TOKEN:
+                $changeModel = new LedgerTokenChangeModel();
+                break;
+            case Asset::DECLARATION:
+                $changeModel = new LedgerDeclarationChangeModel();
+                break;
+            case Asset::SMH:
+                $changeModel = new LedgerSmhChangeModel();
+                break;
+            case Asset::QUBIC:
+                $changeModel = new LedgerQubicChangeModel();
+                break;
+            default:
+                throw new Exception('币种错误:' . $asset);
+        }
+
+        // 更新钱包余额
+        $newAmount = $this->changeWalletOnly($uid, $asset, $amount);
+
+        // 创建账变记录
+        $insertRs = $changeModel->insert([
+            'user_id'        => $uid,
+            'from_id'        => $from_id,
+            'change_amount'  => $amount,
+            'present_amount' => $newAmount,
+            'create_time'    => time(),
+            'action'         => $action,
+        ]);
+
+        if (empty($insertRs)) {
+            throw new Exception('创建' . $asset . '账变记录失败');
+        }
+    }
  
 
     /**
@@ -149,9 +208,6 @@ class LedgerWalletModel extends Model
             return;
         }
 
-//        dump('参数打印');
-//        dump($power);
-
         // 查询直推奖励比例
         $directProfit      = (new Config())->getValue('direct_income');
         $directProfitFloat = floatval($directProfit);
@@ -159,11 +215,7 @@ class LedgerWalletModel extends Model
             return;
         }
 
-        // 每直推一个增加20%,封顶收益为100%
-//        $directProfitFloat = $directProfitFloat * ($parent['direct_num']);
-//        if ($directProfitFloat > 1) {
-//            $directProfitFloat = 1;
-//        }
+
         $directPower = $power * $directProfitFloat; // 可获得的直推奖励(算力)
 
         if($directPower > 0){