Browse Source

转账teac

afa 4 months ago
parent
commit
f4321275b5

+ 40 - 9
application/api/controller/Ledger.php

@@ -6,7 +6,7 @@ use app\api\logic\WelfareLoginc;
 use app\common\controller\Api;
 use app\common\model\LedgerFrozenChangeModel;
 use app\common\model\ProductLists;
-use app\common\model\ProductOrder;
+use app\common\model\LedgerTeacChangeModel;
 use app\common\model\LedgerTeacAngelChangeModel;
 use app\common\model\UserModel;
 use app\common\model\LedgerTokenChangeModel;
@@ -102,9 +102,6 @@ class Ledger extends Api
                 $paginator = (new LedgerTeacAngelChangeModel());
                 $res['data'] = $paginator->where($where)->order('id DESC')->paginate($this->pageSize);
                 break;
-            case 'smh':
-                $paginator = (new LedgerSmhChangeModel());
-                break;
             default:
                 $this->error(__('Invalid parameters'));
                 break;
@@ -161,7 +158,8 @@ class Ledger extends Api
     public function getGiftDesc()
     {
         $this->success('', ['chabao'=>['value' => getConfig('chabao_giveaway'), 'text' => getConfig('chabao_giveaway_txt')], 
-        'frozen'=>['value' => getConfig('frozen_transfer'), 'text' => getConfig('frozen_transfer_txt')]]);
+        'frozen'=>['value' => getConfig('frozen_transfer'), 'text' => getConfig('frozen_transfer_txt')],
+        'teac'=>['value' => config('app.teac_giveaway'), 'text' => config('app.teac_giveaway_txt')]]);
     }
     
     /**
@@ -176,8 +174,7 @@ class Ledger extends Api
         if(empty($amount) || empty($account)){
             $this->error(__('Parameter error'));
         }
-        $real   = bcsub($amount, bcmul(getConfig('chabao_giveaway'), $amount, 2), 2) ; // 手续费
-
+        $real   = bcsub($amount, bcmul(config('app.teac_giveaway'), $amount, 2), 2) ; // 手续费
         // 启动事务
         Db::startTrans();
         try {
@@ -202,6 +199,42 @@ class Ledger extends Api
         $this->success('ok');
     }
 
+    /**
+     * Teac赠送 0x
+     * @return void
+     */
+    public function teacGift(UserModel $userModel,  LedgerWalletModel $ledgerWalletModel)
+    {
+        $amount = $this->request->post('amount'); // 茶宝
+        $account= $this->request->post('account', ''); // 账号
+        $type    = (strlen($account) > 11)? 0: 1;    // type: 0地址 1uid
+        if(empty($amount) || empty($account)){
+            $this->error(__('Parameter error'));
+        }
+        $real   = bcsub($amount, bcmul(getConfig('teac_giveaway'), $amount, 2), 2) ; // 手续费
+        // 启动事务
+        Db::startTrans();
+        try {
+
+            $user = (empty($type))? $userModel->getByAddress($account): $userModel->getById($account); 
+            if(empty($user)) throw new Exception(__("赠送用户不存在"));    
+            if($user['id'] == $this->auth->id) throw new Exception(__("赠送用户不能是自己"));  
+            $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id);
+            if(bccomp($amount, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
+        
+            // 更新USDT和账变
+            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TEAC, -$amount, LedgerTeacChangeModel::GiftPay, $user['id']);
+
+            $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TEAC, $real, LedgerTeacChangeModel::GiftReceipt, $this->auth->id);
+            // 提交事务
+            Db::commit();
+        } catch (Exception $e) {
+            // 回滚事务
+            Db::rollback();
+            $this->error($e->getMessage(), null, $e->getCode());
+        }
+        $this->success('ok');
+    }
 
 
     /**
@@ -215,11 +248,9 @@ class Ledger extends Api
         $parems = $this->request->post();
         Log::write('提现自动打款回调参数:','info');
         Log::info(json_encode($parems));
-
         if(empty($parems)){
             $this->error("回调参数为空");
         }
-
         if($parems['code'] != 1){
             $this->error("本次提现失败");
         }

+ 6 - 0
application/common/model/LedgerTeacChangeModel.php

@@ -20,6 +20,8 @@ class LedgerTeacChangeModel extends Model
     const Exchange         = 6;
     const PledgeFee        = 7; //存储服务费
     const TeamLevel        = 8; //等级分佣
+    const GiftPay          = 9; //赠送支付
+    const GiftReceipt      = 10; //赠送收款
     const System           = 100; //系统调整
     /*
      * 支付状态
@@ -37,6 +39,8 @@ class LedgerTeacChangeModel extends Model
         self::PledgeFee        => '存储服务费',
         self::TeamLevel        => '社区服务奖励',
         self::System           => '系统调整',
+        self::GiftPay          => '赠送支付',
+        self::GiftReceipt      => '赠送收款',
     ];
 
     //getStatusList
@@ -52,6 +56,8 @@ class LedgerTeacChangeModel extends Model
             self::Exchange     => __('C2C兑换产品'),
             self::PledgeFee    => __('存储服务费'),
             self::TeamLevel    => __('社区服务奖励'),
+            self::GiftPay      => __('赠送支付'),
+            self::GiftReceipt  => __('赠送收款'),
             self::System       => __('系统调整'),
         ];
     }

+ 6 - 1
application/config.php

@@ -363,7 +363,12 @@ return [
             2.成交顺序以发起求购成功的时间,顺序成交。<br/>
             3.求购期间成交,无法撤销。',   //求购说明
     ],
-  
+    //teac转账
+    'teac_giveaway' => 0.01, //转账手续费
+    'teac_giveaway_txt' => [
+        0 => "1.请务必核实接收方的地址,转账操作一旦完成不可撤回。",
+        1 => "2.转账收取 1% 网络费,对方将收到你转账数额的 99%。"
+    ],
     //生态节点推广
     'ecology' => [
         'product_id'    => [17],//购买指定产品

+ 2 - 0
public/assets/js/backend/ledger/ledger_teac_change.js

@@ -43,6 +43,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 '6': 'Teac兑换',
                                 '7': '存储服务费',
                                 '8': '社区服务奖励',
+                                '9': '赠送支付',
+                                '10': '赠送收款',
                                 '100': '系统调整',
                             }, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label
                         },