Browse Source

teac天使转

董荣正 1 month ago
parent
commit
2ea63a1dbd

+ 35 - 0
application/api/controller/Ledger.php

@@ -250,6 +250,41 @@ class Ledger extends Api
         $this->success('ok');
     }
 
+    /**
+     * teac天使的转账
+     * @return void
+     */
+    public function teacAngelTransfer(UserModel $userModel,  LedgerWalletModel $ledgerWalletModel,  LedgerTeacAngelChangeModel $LedgerTeacAngelChangeModel)
+    {
+        $amount = $this->request->post('amount'); // 茶宝
+        $account= $this->request->post('account', ''); // 账号
+        if(empty($amount) || empty($account)){
+            $this->error(__('Parameter error'));
+        }
+        $real   = bcsub($amount, bcmul(config('teac_giveaway'), $amount, 2), 2) ; // 手续费
+        // 启动事务
+        Db::startTrans();
+        try {
+            $user = (substr($account, 0, 2) == '0x')? $userModel->getByAddress($account): $userModel->getByUid($account); 
+            if(empty($user)) throw new Exception(__("赠送用户不存在"));    
+            if($user['id'] == $this->auth->id) throw new Exception(__("赠送用户不能是自己"));  
+            $teac = $ledgerWalletModel::getTeacAngel($this->auth->id);
+            if(bccomp($amount, $teac, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
+          
+            // 更新USDT和账变
+            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TEAC_ANGEL, -$amount, LedgerTeacAngelChangeModel::GiftPay, $user['id']);
+            
+            $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TEAC_ANGEL, $real, LedgerTeacChangeModel::GiftReceipt, $this->auth->id);
+            // 提交事务
+            Db::commit();
+        } catch (Exception $e) {
+            // 回滚事务
+            Db::rollback();
+            $this->error($e->getMessage(), null, $e->getCode());
+        }
+        $this->success('ok');
+    }
+
 
     /**
      * 提现自动打款回调

+ 36 - 9
application/common/model/LedgerTeacAngelChangeModel.php

@@ -10,28 +10,55 @@ class LedgerTeacAngelChangeModel extends Model
     protected $name = "ledger_teac_angel_change";
 
 
-    //0茶付宝转入
-    const TransferIn       = 0;
+   //0支付 1转让支付 2 转让收款 3 充值 4 提现 5扣除书续费
+    const Pledge           = 0;
     const Sell             = 1;
-    
+    const SellBuy          = 2;
+    const Buying           = 3;
+    const BuySell          = 4;
+    const SellCancel       = 5;
+    const Exchange         = 6;
+    const PledgeFee        = 7; //存储服务费
+    const TeamLevel        = 8; //等级分佣
+    const GiftPay          = 9; //赠送支付
+    const GiftReceipt      = 10; //赠送收款
+    const System           = 100; //系统调整
     /*
      * 支付状态
      * 0未支付 100支付中 200支付成功 400支付失败
      */
     public $pay_status = [
         '-1'                   => '全部',
-        self::TransferIn       => '茶付宝划转',
-       
-    
+        self::Pledge           => '质押存储',
+        self::Sell             => 'C2C出售',
+        self::SellBuy          => 'C2C出售购买',
+        self::Buying           => 'C2C求购',
+        self::BuySell          => 'C2C求购出售',
+        self::SellCancel       => 'C2C取消出售',
+        self::Exchange         => 'Teac兑换',
+        self::PledgeFee        => '存储服务费',
+        self::TeamLevel        => '社区服务奖励',
+        self::System           => '系统调整',
+        self::GiftPay          => '赠送支付',
+        self::GiftReceipt      => '赠送收款',
     ];
 
     //getStatusList
     public static function getStatusList()
     {
         return [
-            self::TransferIn    => __('茶付宝划转'),
-
-         
+            self::Pledge    => __('质押存储'),
+            self::Sell      => __('C2C出售'),
+            self::SellBuy   => __('C2C出售购买'),
+            self::Buying    => __('C2C存储'),
+            self::BuySell   => __('C2C存储出售'),
+            self::SellCancel   => __('C2C取消出售'),
+            self::Exchange     => __('C2C兑换产品'),
+            self::PledgeFee    => __('存储服务费'),
+            self::TeamLevel    => __('社区服务奖励'),
+            self::GiftPay      => __('赠送支付'),
+            self::GiftReceipt  => __('赠送收款'),
+            self::System       => __('系统调整'),
         ];
     }
 }

+ 4 - 1
application/common/model/LedgerWalletModel.php

@@ -45,7 +45,10 @@ class LedgerWalletModel extends Model
     {
         return self::where('user_id', $userID)->value('teac');
     }
-
+    public static function getTeacAngel(int $userID)
+    {
+        return self::where('user_id', $userID)->value('teac_angel');
+    }
     public static function getWalletTotalChaBao($userID)
     {
         return self::where('user_id', $userID)->value('token + frozen');