浏览代码

teac兑换

afa 6 月之前
父节点
当前提交
8728eb733e

+ 205 - 0
application/api/controller/Exchange.php

@@ -0,0 +1,205 @@
+<?php
+
+
+namespace app\api\controller;
+
+use app\api\logic\WelfareLoginc;
+use app\common\controller\Api;
+use app\common\logic\BscApi;
+use app\common\model\ProductLists;
+use app\common\model\LedgerFrozenChangeModel;
+use app\common\model\ProductOrder;
+use app\common\model\ProductsModel;
+use app\common\model\RwaExchangeRecordModel;
+use app\common\model\LedgerWalletModel;
+use fast\Action;
+use fast\Asset;
+use think\Db;
+use think\Exception;
+use think\Log;
+
+//Teac兑换
+class Exchange extends Api
+{
+
+      protected string $lan = '';
+
+      public function _initialize()
+      {
+            parent::_initialize();
+            $this->lan = $this->request->getLan();
+      }
+
+      //Ledger/getWelfareRedeConfig Exchange
+      //Ledger/submitWelfare
+      //Rwa福利兑换配置
+      public function getWelfareRedeConfig(){
+
+            $this->success('ok', config('welfare_rede'));
+      }
+
+      //Rwa兑换
+      public function submitWelfare(LedgerWalletModel $ledgerWalletModel)
+      {
+            $coin = $this->request->post('coin'); // 代币
+            $coin_from_address = $this->request->post('coin_from_address'); // 代码转入地址
+            $usdt_from_address = $this->request->post('usdt_from_address'); // U转入地址
+            if (empty($coin) || empty($coin_from_address) || empty($usdt_from_address)) {
+                  $this->error(__('Parameter error'));
+            }
+            //检查区块链地址是否合法
+            if(!(isErc20AddressValid($coin_from_address) && isErc20AddressValid($usdt_from_address))){
+                  $this->error(__('Invalid parameters'));
+            }
+
+            $welfare_config = config('welfare_rede');
+            if (!in_array($coin, $welfare_config['currency'])) {
+                  $this->error(__('Invalid parameters'));
+            }
+
+            $check_user = (new RwaExchangeRecordModel())->where('user_id', $this->auth->id)->where('status', 200)->count();
+            if($check_user >= 4){
+                  $this->error('每人限制兑换两套,您已达上限');
+            }
+
+            $BscApi = new BscApi($welfare_config['contract_address'][$coin]);
+            $result_coin = $BscApi->getTransactionRecordsByAddress($coin_from_address, $welfare_config['transfer_address'], 49990000);
+            if ($result_coin['code'] == 0) {
+                  $this->error($result_coin['msg']);
+            }
+            Log::info($result_coin, '代币所有转入记录');
+            $coin_list = [];
+            foreach ($result_coin['data'] as $value) {
+                  if ($value['amount'] == $welfare_config['currency_price'][$coin]) {
+                  $coin_list[] = $value;
+                  }
+            }
+            if (empty($coin_list)) {
+                  $this->error('未识别到代币转入记录');
+            }
+            Log::info($coin_list, '代币精准转入记录');
+
+            $coin_data = [];
+            foreach ($coin_list as $item) {
+                  $check_info = (new RwaExchangeRecordModel())->where('tx_hash', $item['hash'])->find();
+                  if (empty($check_info)) {
+                  $coin_data = $item;
+                  break;
+                  }
+            }
+            if (empty($coin_data)) {
+                  $this->error('未识别到新代币转入记录');
+            }
+            Log::info($coin_list, '代币可用转入记录');
+
+            $BscApi = new BscApi($welfare_config['contract_address']['USDT']);
+            $result_usdt = $BscApi->getTransactionRecordsByAddress($usdt_from_address, $welfare_config['transfer_address'], 49990000);
+            if ($result_usdt['code'] == 0) {
+                  $this->error($result_usdt['msg']);
+            }
+            Log::info($result_usdt, 'USDT所有转入记录');
+
+            $usdt_list = [];
+            foreach ($result_usdt['data'] as $value) {
+                  if ($value['amount'] == $welfare_config['currency_price']['USDT']) {
+                  $usdt_list[] = $value;
+                  }
+            }
+            if (empty($usdt_list)) {
+                  $this->error('未识别到USDT转入记录');
+            }
+            Log::info($usdt_list, 'USDT精准转入记录');
+
+            $usdt_data = [];
+            foreach ($usdt_list as $item) {
+                  $check_info = (new RwaExchangeRecordModel())->where('tx_hash', $item['hash'])->find();
+                  if (empty($check_info)) {
+                  $usdt_data = $item;
+                  break;
+                  }
+            }
+            if (empty($usdt_data)) {
+                  $this->error('未识别到新USDT转入记录');
+            }
+            Log::info($usdt_list, 'USDT可用入记录');
+
+            $order_no = date('YmdHis') . rand(1000, 9999);
+            $inster_data = [
+                  [
+                  'order_no' => $order_no,
+                  'tx_hash' => $coin_data['hash'],
+                  'user_id' => $this->auth->id,
+                  'symbol' => $coin,
+                  'amount' => $coin_data['amount'],
+                  'product_id' => $welfare_config['product_id'],
+                  'from_address' => $coin_data['from'],
+                  'to_address' => $coin_data['to'],
+                  'status' => 200,
+                  'create_time' => time(),
+                  ],
+                  [
+                  'order_no' => $order_no,
+                  'tx_hash' => $usdt_data['hash'],
+                  'user_id' => $this->auth->id,
+                  'symbol' => 'USDT',
+                  'amount' => $usdt_data['amount'],
+                  'product_id' => $welfare_config['product_id'],
+                  'from_address' => $usdt_data['from'],
+                  'to_address' => $usdt_data['to'],
+                  'status' => 200,
+                  'create_time' => time(),
+                  ]
+            ];
+            Log::info($inster_data, '插入数据');
+            $product_id = $welfare_config['product_id'];
+            $product_info =  (new ProductLists())->where('id', $product_id)->find();
+            if (empty($product_info))  $this->error('产品不存在');
+            try {
+                  Db::startTrans();
+                  $rs = Db::name('rwa_exchange_record')->fetchSql(false)->insertAll($inster_data);
+                  //添加标记茶宝记录
+                  $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::FROZEN, $usdt_data['amount'], LedgerFrozenChangeModel::RwaExchangeRecord, 0);
+                  //发放产品
+                  $rs = WelfareLoginc::setUserProductOrder(1, false, $order_no, 0, $product_info['id'], $this->auth->id, ProductOrder::RwaExchange);
+                  Db::commit();
+                  $this->success('ok', $order_no);
+            } catch (Exception $e) {
+                  Db::rollback();
+                  $this->error($e->getMessage(), null, $e->getCode());
+            }
+      }
+
+
+      //Teac兑换列表
+      public function getTeacList(ProductLists $productLists){
+             
+            $list = $productLists::where('is_teac', 1)
+                  ->where('status', 1)
+                  ->field('id,teac_price,thum,'.$this->lan.'_name as name')
+                  ->order('weigh desc')
+                  ->paginate($this->pageSize);
+            $this->success('ok', $list);
+      }
+
+      //Teac兑换详情
+      public function getTeacDetail(ProductLists $productLists){
+             
+            $ids = $this->request->post('product_id/d', 0);
+            $list = $productLists::where('is_teac', 1)
+                  ->where('id', $ids)
+                  ->field('id,teac_price,thum,'.$this->lan.'_name as name,details')
+                  ->find();
+            $this->success('ok', $list);
+      }
+
+      //Teac兑换购买
+      public function getTeacOrder(ProductLists $productLists){
+             
+            $list = $productLists::where('is_teac', 1)
+                  ->field('id,teac_price,thum,'.$this->lan.'_name as name')
+                  ->order('weigh desc')
+                  ->find();
+            $this->success('ok', $list);
+      }
+
+}

+ 1 - 142
application/api/controller/Ledger.php

@@ -4,7 +4,6 @@ namespace app\api\controller;
 
 use app\api\logic\WelfareLoginc;
 use app\common\controller\Api;
-use app\common\logic\BscApi;
 use app\common\model\LedgerFrozenChangeModel;
 use app\common\model\ProductLists;
 use app\common\model\ProductOrder;
@@ -119,7 +118,6 @@ class Ledger extends Api
             $this->error(__('Parameter error'));
         }
         $real   = bcsub($amount, bcmul(getConfig('frozen_transfer'), $amount, 2), 2) ; // 手续费
-
         // 启动事务
         Db::startTrans();
         try {
@@ -148,8 +146,6 @@ class Ledger extends Api
     }
 
 
-
-
     /**
      * 赠送/转账明细
      * @return void
@@ -159,6 +155,7 @@ class Ledger extends Api
         $this->success('', ['chabao'=>['value' => getConfig('chabao_giveaway'), 'text' => getConfig('chabao_giveaway_txt')], 
         'frozen'=>['value' => getConfig('frozen_transfer'), 'text' => getConfig('frozen_transfer_txt')]]);
     }
+    
     /**
      * 茶宝赠送
      * @return void
@@ -196,144 +193,6 @@ class Ledger extends Api
         $this->success('ok');
     }
 
-    //福利兑换配置
-    public function getWelfareRedeConfig(){
-
-        $this->success('ok', config('welfare_rede'));
-    }
-
-    public function submitWelfare(LedgerWalletModel $ledgerWalletModel)
-    {
-        $coin = $this->request->post('coin'); // 代币
-        $coin_from_address = $this->request->post('coin_from_address'); // 代码转入地址
-        $usdt_from_address = $this->request->post('usdt_from_address'); // U转入地址
-        if (empty($coin) || empty($coin_from_address) || empty($usdt_from_address)) {
-            $this->error(__('Parameter error'));
-        }
-        //检查区块链地址是否合法
-        if(!(isErc20AddressValid($coin_from_address) && isErc20AddressValid($usdt_from_address))){
-            $this->error(__('Invalid parameters'));
-        }
-
-        $welfare_config = config('welfare_rede');
-        if (!in_array($coin, $welfare_config['currency'])) {
-            $this->error(__('Invalid parameters'));
-        }
-
-        $check_user = (new RwaExchangeRecordModel())->where('user_id', $this->auth->id)->where('status', 200)->count();
-        if($check_user >= 4){
-            $this->error('每人限制兑换两套,您已达上限');
-        }
-
-        $BscApi = new BscApi($welfare_config['contract_address'][$coin]);
-        $result_coin = $BscApi->getTransactionRecordsByAddress($coin_from_address, $welfare_config['transfer_address'], 49990000);
-        if ($result_coin['code'] == 0) {
-            $this->error($result_coin['msg']);
-        }
-        Log::info($result_coin, '代币所有转入记录');
-        $coin_list = [];
-        foreach ($result_coin['data'] as $value) {
-            if ($value['amount'] == $welfare_config['currency_price'][$coin]) {
-                $coin_list[] = $value;
-            }
-        }
-        if (empty($coin_list)) {
-            $this->error('未识别到代币转入记录');
-        }
-        Log::info($coin_list, '代币精准转入记录');
-
-        $coin_data = [];
-        foreach ($coin_list as $item) {
-            $check_info = (new RwaExchangeRecordModel())->where('tx_hash', $item['hash'])->find();
-            if (empty($check_info)) {
-                $coin_data = $item;
-                break;
-            }
-        }
-        if (empty($coin_data)) {
-            $this->error('未识别到新代币转入记录');
-        }
-        Log::info($coin_list, '代币可用转入记录');
-
-        $BscApi = new BscApi($welfare_config['contract_address']['USDT']);
-        $result_usdt = $BscApi->getTransactionRecordsByAddress($usdt_from_address, $welfare_config['transfer_address'], 49990000);
-        if ($result_usdt['code'] == 0) {
-            $this->error($result_usdt['msg']);
-        }
-        Log::info($result_usdt, 'USDT所有转入记录');
-
-        $usdt_list = [];
-        foreach ($result_usdt['data'] as $value) {
-            if ($value['amount'] == $welfare_config['currency_price']['USDT']) {
-                $usdt_list[] = $value;
-            }
-        }
-        if (empty($usdt_list)) {
-            $this->error('未识别到USDT转入记录');
-        }
-        Log::info($usdt_list, 'USDT精准转入记录');
-
-        $usdt_data = [];
-        foreach ($usdt_list as $item) {
-            $check_info = (new RwaExchangeRecordModel())->where('tx_hash', $item['hash'])->find();
-            if (empty($check_info)) {
-                $usdt_data = $item;
-                break;
-            }
-        }
-        if (empty($usdt_data)) {
-            $this->error('未识别到新USDT转入记录');
-        }
-        Log::info($usdt_list, 'USDT可用入记录');
-
-        $order_no = date('YmdHis') . rand(1000, 9999);
-        $inster_data = [
-            [
-                'order_no' => $order_no,
-                'tx_hash' => $coin_data['hash'],
-                'user_id' => $this->auth->id,
-                'symbol' => $coin,
-                'amount' => $coin_data['amount'],
-                'product_id' => $welfare_config['product_id'],
-                'from_address' => $coin_data['from'],
-                'to_address' => $coin_data['to'],
-                'status' => 200,
-                'create_time' => time(),
-            ],
-            [
-                'order_no' => $order_no,
-                'tx_hash' => $usdt_data['hash'],
-                'user_id' => $this->auth->id,
-                'symbol' => 'USDT',
-                'amount' => $usdt_data['amount'],
-                'product_id' => $welfare_config['product_id'],
-                'from_address' => $usdt_data['from'],
-                'to_address' => $usdt_data['to'],
-                'status' => 200,
-                'create_time' => time(),
-            ]
-        ];
-        Log::info($inster_data, '插入数据');
-
-        $product_id = $welfare_config['product_id'];
-        $product_info =  (new ProductLists())->where('id', $product_id)->find();
-        if (empty($product_info)) {
-            $this->error('产品不存在');
-        }
-        try {
-            Db::startTrans();
-            $rs = Db::name('rwa_exchange_record')->fetchSql(false)->insertAll($inster_data);
-            //添加标记茶宝记录
-            $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::FROZEN, $usdt_data['amount'], LedgerFrozenChangeModel::RwaExchangeRecord, 0);
-            //发放产品
-            $rs = WelfareLoginc::setUserProductOrder(1, false, $order_no, 0, $product_info['id'], $this->auth->id, ProductOrder::Exchange);
-            Db::commit();
-            $this->success('ok', $order_no);
-        } catch (Exception $e) {
-            Db::rollback();
-            $this->error($e->getMessage(), null, $e->getCode());
-        }
-    }
 
 
     /**

+ 0 - 714
application/api/controller/Test.php

@@ -1,714 +0,0 @@
-<?php
-
-
-namespace app\api\controller;
-
-use app\api\logic\WelfareLoginc;
-use app\common\logic\BscApi;
-use app\common\logic\MyBscApi;
-use app\common\logic\TeamRewards;
-use app\common\model\AnnouncementModel;
-use app\common\model\LedgerSmhChangeModel;
-use app\common\model\LedgerUsdtChangeModel;
-use app\common\model\OfflineRechargeRecordModel;
-use app\api\logic\MarketLogic;
-use app\common\model\ParametersModel;
-use app\common\model\ProductOrder;
-use app\common\model\ProductsModel;
-use app\common\model\RwaExchangeRecordModel;
-use app\common\model\UserModel;
-use app\common\model\UserPathModel;
-use app\common\model\LedgerWalletModel;
-use app\common\model\ProductTransfer;
-use fast\Action;
-use fast\Asset;
-use fast\Http;
-use fast\RechargeStatus;
-use think\Db;
-use think\Exception;
-use think\Log;
-use think\Model;
-
-class Test
-{
-
-
-    //取消寄售
-    public function copy_user(ProductTransfer $productTransfer, ProductOrder $productOrder, UserModel $userModel)
-    {
-        
-        $user_ids = $productOrder::where('type_id', 3)
-            ->field('user_id')
-            ->where('order_id', 0)
-            ->group('user_id')
-            ->column('user_id');
-        $rs = $userModel->whereIn('id', $user_ids)->update(['is_super'=> 1]);
-
-        dump('更新状态' . $rs . '个用户');
-
-        $user_ids = $productOrder::where('type_id', 4)
-            ->field('user_id')
-            ->where('order_id', 0)
-            ->group('user_id')
-            ->select();
-        $rs = $userModel->whereIn('id', $user_ids)->update(['is_super'=> 2]);
-
-        dump('更新状态' . $rs . '个用户');
-    }
-
-    /*
-     * 更新上级    SELECT * FROM  product_order where order_id in ( SELECT MAX( order_id ) FROM product_order GROUP  BY type_id )
-
-     */
-    public function change_parent()
-    {
-        //1.从主表复制到备份表,需手动插入上级信息
-//        dump('从主表复制到备份表');
-//        $user_list = Db::name('user')
-//            ->fetchSql(false)
-//            ->field('u.*,p.distance')
-//            ->alias('u')
-//            ->join('user_path p', 'u.id = p.user_id')
-//            ->where('p.parent_id', 101985)
-//            //->where('u.id','>', 103931)
-//            ->select();
-//
-//        $i = 0;
-//        foreach ($user_list as $user){
-//            $is = Db::table('user_1')
-//                ->insert($user);
-//            $i++;
-//        }
-//        halt($i);
-
-        //*2.更新备份表上级地址
-//        dump('更新上级地址');
-//        $user_list = Db::name('user_1')
-//            ->whereNull('parent_address')
-//            ->select();
-//        $i = 0;
-//        foreach ($user_list as $user){
-//            $parent_info = (new UserModel())
-//                ->where('id', $user['parent_id'])
-//                ->find();
-//            if(!empty($parent_info)){
-//                $is = Db::table('user_1')
-//                    ->where('id', $user['id'])
-//                    ->update([
-//                        'parent_address' => $parent_info['address']
-//                    ]);
-//                $i++;
-//            }
-//        }
-//        halt($i);
-
-
-        //3.更新主表会员上级
-        dump('重建网体');
-        $user_list = Db::table('user_1')
-            ->order('distance')
-            ->select();
-        $i = 0;
-        foreach ($user_list as $user){
-            $parent_info = (new UserModel())
-                ->where('address', $user['parent_address'])
-                ->find();
-            if(!empty($parent_info)){
-                $is = Db::table('user')
-                    ->where('id', $user['id'])
-                    ->update([
-                        'parent_id' => $parent_info['id']
-                    ]);
-                //删除网体
-                (new UserPathModel())
-                    ->where('user_id', $user['id'])
-                    ->delete();
-
-                // 创建网体
-                (new UserPathModel())->createPath($user['id'], $parent_info['id']);
-                $i++;
-            } else{
-                dump($user['id'] . '--无上级');
-            }
-        }
-
-        halt($i);
-    }
-
-    /*
-     * 更新上级
-     *
-     * 更改给定ID的上级,并把它的直推一并更改
-     */
-    public function resetParent()
-    {
-        //3.更新主表会员上级
-        dump('重建网体');
-        $parent_id = 100100;
-        $user_id = 101134;
-        $user = (new UserModel())
-            ->fetchSql(false)
-            ->where('id', $user_id)
-            ->update([
-                'parent_id' => $parent_id
-            ]);
-        dump($user, true, '更新状态');
-        //删除网体
-        (new UserPathModel())
-            ->where('user_id', $user_id)
-            ->delete();
-        // 创建网体
-        (new UserPathModel())->createPath($user_id, $parent_id);
-
-        $user_list = (new UserModel())
-            ->where('parent_id', $user_id)
-            ->select();
-        $i = 0;
-        foreach ($user_list as $user){
-            //删除网体
-            (new UserPathModel())
-                ->where('user_id', $user['id'])
-                ->delete();
-
-            // 创建网体
-            (new UserPathModel())->createPath($user['id'], $user['parent_id']);
-            $i++;
-        }
-
-        halt($i);
-    }
-    /**
-    导入数据表生成 sql
-    CREATE TABLE dao_ru AS SELECT
-    u.id,
-    u.parent_id,
-    u.address,
-    u.team_power,
-    u.team_num,
-    w.power,
-    w.rental_power,
-    w.usdt
-    FROM
-    `user` u
-    LEFT JOIN ledger_wallet w ON u.id = w.user_id
-    WHERE
-    id IN ( SELECT user_id FROM `user_path` WHERE parent_id = 1012 )
-    OR id = 1012
-    ORDER BY
-    id
-     */
-    public function daoru()
-    {
-        die;
-        $daoru_list = Db::table('user_base')
-            //->where('is_dao', 1)
-            ->select();
-        $i = 0;
-        $j = 0;
-        //重建钱包
-        foreach ($daoru_list as $key => $info) {
-            $user = (new UserModel())->getByAddress($info['address']);
-            if (!empty($user)) { // 已存在
-                // 更新总算力和账变
-                (new LedgerWalletModel)->changeWalletAccount($user['id'], Asset::POWER, $info['power'], Action::Reversal, 0);
-
-                // 更新自己(有效会员时间)和所有上级的信息(有效直推人数和团队总算力)
-                (new UserModel())->updateForRental($user['id'], $info['power']);
-                $j++;
-                continue;
-            }
-        }
-
-        //重建用户
-//        foreach ($daoru_list as $key => $info) {
-//
-//            $parent_user = (new UserModel())->getByAddress($info['parent_address']);
-//            if(empty($parent_user)){
-//                dump('没有上级');
-//                dump($info);
-//                continue;
-//            }
-//
-//            $user = (new UserModel())->getByAddress($info['address']);
-//            if (!empty($user)) { // 已存在
-//                dump($info['id'] . ' - ' . $info['address'] . ' - 已存在');
-//
-//                $is = Db::table('user')
-//                    ->where('id', $user['id'])
-//                    ->update([
-//                        'parent_id' => $parent_user['id']
-//                    ]);
-//                $j++;
-//                continue;
-//            }
-//
-//            unset($info['id']);
-//            unset($info['parent_address']);
-//            unset($info['is_dao']);
-//            $info['parent_id'] = $parent_user['id'];
-//            // 创建用户
-//            $newUserID = (new UserModel())->insertGetId($info);
-//            // 创建钱包
-//            (new LedgerWalletModel())->insertGetId([
-//                'user_id' => $newUserID,
-//            ]);
-//
-//            // 创建网体
-//            (new UserPathModel())->createPath($newUserID, $parent_user['id']);
-//
-//            $i++;
-//
-//        }
-        dump($i);
-        dump($j);
-    }
-
-    public function updaetWallet()
-    {
-        $daoru_list = Db::table('ledger_wallet_1')
-            ->whereNotNull('address')
-            ->select();
-        $i = 0;
-        foreach ($daoru_list as $key => $info) {
-            dump($info);
-            $user = (new UserModel())->getByAddress($info['address']);
-            if (empty($user)) {
-                dump($info['user_id'] . ' - ' . $info['address'] . ' - 不存在');
-                continue;
-            }
-            unset($info['user_id']);
-            unset($info['address']);
-
-            //更新钱包
-            $is_up = (new LedgerWalletModel())
-                ->where('user_id', $user['id'])
-                ->update($info);
-            dump($user['id'] . '更新' . $is_up);
-            $i++;
-        }
-        dump($i);
-    }
-
-    /**
-     * 手段向某会员报单算力
-     * @return void
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\ModelNotFoundException
-     * @throws \think\exception\DbException
-     */
-    public function updateOrder()
-    {
-        //算力租赁订单处理
-        // 查询兑换比例
-        $usdtToPower      = (new ParametersModel)->getValue('usdtToPowerRate');
-        $usdtToPowerFloat = floatval($usdtToPower);
-        if (is_null($usdtToPower) || $usdtToPowerFloat <= 0) {
-            return '获取USDT兑换算力的比例失败';
-        }
-
-        $orderInfo = (new OfflineRechargeRecordModel())
-            ->where('id', 4)
-            ->find();
-        if(empty($orderInfo)){
-            halt('订单信息不存在');
-        }
-        $uid   = $orderInfo['user_id'];
-        $fee   = $orderInfo['amount'];
-        $power = bcmul($fee, $usdtToPowerFloat, 6); // 该用户兑得的算力
-        // 启动事务
-        Db::startTrans();
-        try {
-            // 更新总算力和账变
-            (new LedgerWalletModel)->changeWalletAccount($uid, Asset::POWER, $power, Action::PowerRentalPower, $orderInfo['id']);
-
-            // 更新服务器算力,不账变
-            (new LedgerWalletModel)->changeWalletOnly($uid, Asset::RENTAL_POWER, $power);
-
-            // 更新自己(有效会员时间)和所有上级的信息(有效直推人数和团队总算力)
-            (new UserModel())->updateForRental($uid, $power);
-
-            // 发放直推USDT收益
-            (new LedgerWalletModel)->sendUsdtProfit($uid, $fee);
-
-            // 发放直推算力收益
-            (new LedgerWalletModel)->sendDirectProfit($uid, $power);
-
-            // 发代数收益
-            (new LedgerWalletModel)->sendGenerateProfit($uid, $fee);
-
-            // 发放见点奖
-            (new LedgerWalletModel)->sendRegBonus($uid, $fee);
-
-            // 更新购买(充值)记录
-            (new OfflineRechargeRecordModel())->updateOrderStatus($orderInfo['id'], RechargeStatus::StatusAuthSuccess, 0, $power);
-
-            // 提交事务
-            Db::commit();
-        } catch (Exception $e) {
-            // 回滚事务
-            Db::rollback();
-            return $e->getMessage();
-        }
-    }
-
-    //重算团队业绩和直推人数
-    public function reset_team()
-    {
-        set_time_limit(0);
-
-        //先清空
-        $update = Db::table('user')
-            ->where('id', '>', 0)
-            ->update([
-                'team_power' => 0,
-                'team_num'   => 0,
-                'direct_num' => 0
-            ]);
-
-        $up_power = Db::table('ledger_wallet')
-            ->field('u.id')
-            ->alias('w')
-            ->join('user u', 'w.user_id = u.id')
-            ->where('u.effective_time','>',0)
-            ->where('w.rental_power', 0)
-            ->select();
-        foreach ($up_power as $item){
-            $update = Db::table('ledger_wallet')
-                ->where('user_id', $item['id'])
-                ->update([
-                    'rental_power' => 0.01
-                ]);
-        }
-
-        $power_list = Db::table('ledger_wallet')
-            ->where('rental_power', '>', 0)
-            ->select();
-        $info_list  = 0;
-        $bad_list   = [];
-        foreach ($power_list as $key => $info) {
-            dump('正在处理ID:' . $info['user_id']);
-            $parent_ids = (new UserPathModel())
-                ->where('user_id',$info['user_id'])
-                ->order('distance')
-                ->select();
-            foreach ($parent_ids as $item) {
-                $data = [
-                    'team_power' => Db::raw('team_power + ' . $info['rental_power']),
-                    'team_num'   => Db::raw('team_num + 1'),
-                ];
-                if ($item['distance'] == 1) {
-                    $data['direct_num'] = Db::raw('direct_num+1');
-                }
-                $update = Db::table('user')
-                    ->where('id', $item['parent_id'])
-                    ->update($data);
-                if (!$update) {
-                    $bad_list[] = $info;
-                } else {
-                    $info_list++;
-                }
-            }
-        }
-        dump('成功数量');
-        dump($info_list);
-        dump('失败数量');
-        dump($bad_list);
-    }
-    //累加新增团队业绩
-    public function addTeamPower()
-    {
-        set_time_limit(0);
-
-        $uid = 100702;
-        $num = 1429;
-        $parentIDs = (new UserPathModel())->getAllParentIDs($uid);
-        $parentIDs[] = $uid;
-
-        dump($parentIDs, true, 'ID列表');
-
-        $update = (new UserModel())
-            ->where('id', 'in', $parentIDs)
-            ->update([
-                'team_power' => Db::raw('team_power + ' . $num)
-            ]);
-        dump($update, true, '影响行数');
-
-    }
-
-    public function resetUserPath()
-    {
-        $ratio = 0.05;//直推奖励
-
-        $info_list = (new OfflineRechargeRecordModel())
-            ->where('status', OfflineRechargeRecordModel::StatusFail)
-            ->order('id', 'ASC')
-            ->select();
-        dump('本次数据共有:' . count($info_list));
-        foreach ($info_list as $info) {
-            $user = (new UserModel())->get($info['user_id']);
-            if (empty($user) || $user['parent_id'] == 0) {
-                continue;
-            }
-
-            $check = (new LedgerUsdtChangeModel())
-                ->where('user_id', $user['parent_id'])
-                ->where('action', Action::UsdtShareBonus)
-                ->where('from_id', $info['user_id'])
-                ->count();
-
-            if($check == 0){
-                (new LedgerWalletModel())->changeWalletAccount($user['parent_id'], Asset::USDT, $info['amount'] * $ratio, Action::UsdtShareBonus, $info['user_id']);
-                dump('订单ID:' . $info['id'] . '处理成功,奖金:' . $info['amount'] * $ratio);
-            }else{
-                dump('订单ID:' . $info['id'] . '处理失败,奖金已存在');
-            }
-        }
-    }
-
-    /**
-     * 补发直推奖
-     * @return void
-     */
-    public function resetShareBonus()
-    {
-        $users = (new UserModel())->order('id', 'ASC')->select();
-        foreach ($users as $v) {
-            (new UserPathModel())->createPath($v['id'], $v['parent_id']);
-        }
-    }
-
-    /**
-     * @return string
-     *
-     * 返回结果
-     * {
-            "status": "1",
-            "message": "OK",
-            "result": {
-                "status": "1"
-            }
-        }
-     */
-    public function getStatusByHaxh()
-    {
-        $url = "https://api.bscscan.com/api?module=transaction&action=gettxreceiptstatus&txhash=0x30f4190a8237c7744a0981a2895728bab93acf4cb78b03c192ed5ac387405c54&apikey=VTCKIP346DCRWB6JNS4KDANUJJEQN9VAKW";
-
-        $body = Http::get($url);
-        if (empty($body)) {
-            return "api返回内容为空";
-        }
-        dump($body);
-        // 转成数组
-        $rsArr = json_decode($body, true);
-        dump($rsArr);
-        if (empty($rsArr) || !is_array($rsArr)) {
-            return "状态api返回数据异常";
-        }
-
-        if ($rsArr['status'] != '1') {
-            return '状态api返回status不为1,错误信息:' . $rsArr['message'];
-        }
-
-        if ($rsArr['result']['status'] != 1) {
-            return '状态api返回result中的status不为1,错误信息:' . $rsArr['message'];
-        }
-
-    }
-
-    public function AllocateEtc()
-    {
-        $url = "https://www.binance.com/api/v1/klines?symbol=ETCUSDT&limit=1&interval=3m";
-        $body = Http::get($url);
-        if (empty($body)) {
-            return "api返回内容为空";
-        }
-        dump($body);
-        // 转成数组
-        $rsArr = json_decode($body, true);
-        dump($rsArr[0][2]);
-
-        $body = Http::get($url);
-        if (empty($body)) {
-            return "api返回内容为空";
-        }
-        dump($body);
-        // 转成数组
-        $rsArr = json_decode($body, true);
-        dump($rsArr);
-        if (empty($rsArr) || !is_array($rsArr)) {
-            return "状态api返回数据异常";
-        }
-
-        if ($rsArr['status'] != '1') {
-            return '状态api返回status不为1,错误信息:' . $rsArr['message'];
-        }
-
-        if ($rsArr['result']['status'] != 1) {
-            return '状态api返回result中的status不为1,错误信息:' . $rsArr['message'];
-        }
-
-    }
-    public function debug()
-    {
-        $coin = $this->request->post('coin'); // 代币
-        $coin_from_address = $this->request->post('coin_from_address'); // 代码转入地址
-        $usdt_from_address = $this->request->post('usdt_from_address'); // U转入地址
-        if (empty($coin) || empty($coin_from_address) || empty($usdt_from_address)) {
-            $this->error(__('Parameter error'));
-        }
-        //检查区块链地址是否合法
-        if(!(isErc20AddressValid($coin_from_address) && isErc20AddressValid($usdt_from_address))){
-            $this->error(__('Invalid parameters'));
-        }
-
-        $welfare_config = config('welfare_rede');
-        if (!in_array($coin, $welfare_config['welfare_rede']['currency'])) {
-            $this->error(__('Invalid parameters'));
-        }
-
-        $BscApi = new BscApi($welfare_config['welfare_rede']['contract_address'][$coin]);
-        $result_coin = $BscApi->getTransactionRecordsByAddress($coin_from_address, $welfare_config['welfare_rede']['transfer_address'], 49990000);
-        if ($result_coin['code'] == 0) {
-            $this->error($result_coin['msg']);
-        }
-        $coin_list = [];
-        foreach ($result_coin['data'] as $value) {
-            if ($value['amount'] == $welfare_config['welfare_rede']['currency_price'][$coin]) {
-                $coin_list[] = $value;
-            }
-        }
-        if (empty($coin_list)) {
-            $this->error('未识别到代币转入记录');
-        }
-        $coin_data = [];
-        foreach ($coin_list as $item) {
-            $check_info = (new RwaExchangeRecordModel())->where('tx_hash', $item['hash'])->find();
-            if (empty($check_info)) {
-                $coin_data = $item;
-                break;
-            }
-        }
-        if (empty($coin_data)) {
-            $this->error('未识别到新代币转入记录');
-        }
-
-        $BscApi = new BscApi($welfare_config['welfare_rede']['contract_address']['USDT']);
-        $result_usdt = $BscApi->getTransactionRecordsByAddress($usdt_from_address, $welfare_config['welfare_rede']['transfer_address'], 49990000);
-        if ($result_usdt['code'] == 0) {
-            $this->error($result_usdt['msg']);
-        }
-        $usdt_list = [];
-        foreach ($usdt_list['data'] as $value) {
-            if ($value['amount'] == $welfare_config['welfare_rede']['currency_price']['USDT']) {
-                $usdt_list[] = $value;
-            }
-        }
-        if (empty($usdt_list)) {
-            $this->error('未识别到USDT转入记录');
-        }
-        $usdt_data = [];
-        foreach ($usdt_list as $item) {
-            $check_info = (new RwaExchangeRecordModel())->where('tx_hash', $item['hash'])->find();
-            if (empty($check_info)) {
-                $usdt_data = $item;
-                break;
-            }
-        }
-        if (empty($usdt_data)) {
-            $this->error('未识别到新USDT转入记录');
-        }
-        $order_no = date('YmdHis') . rand(1000, 9999);
-        $inster_data = [
-            [
-                'order_no' => $order_no,
-                'tx_hash' => $coin_data['hash'],
-                'user_id' => $this->auth->id,
-                'symbol' => $coin,
-                'amount' => $coin_data['amount'],
-                'product_id' => $welfare_config['welfare_rede']['product_id'],
-                'from_address' => $coin_data['from'],
-                'to_address' => $coin_data['to'],
-                'status' => 200,
-                'create_time' => time(),
-            ],
-            [
-                'order_no' => $order_no,
-                'tx_hash' => $usdt_data['hash'],
-                'user_id' => $this->auth->id,
-                'symbol' => 'USDT',
-                'amount' => $usdt_data['amount'],
-                'product_id' => $welfare_config['welfare_rede']['product_id'],
-                'from_address' => $usdt_data['from'],
-                'to_address' => $usdt_data['to'],
-                'status' => 200,
-                'create_time' => time(),
-            ]
-        ];
-
-        $product_id = $welfare_config['welfare_rede']['product_id'];
-        $product_info =  (new ProductsModel())->where('id', $product_id)->find();
-        if (empty($product_info)) {
-            $this->error('产品不存在');
-        }
-        try {
-            Db::startTrans();
-            (new RwaExchangeRecordModel())->saveAll($inster_data);
-
-            $rs = WelfareLoginc::setUserProductOrder(1, false, $order_no, $product_info['price'], $product_info['product_id'], $this->auth->id, ProductOrder::Exchange);
-            if($rs && $product_info['price'] >= config('min_rwa_price')){
-                (new UserModel())->updateForRwaNum($this->auth->id, UserModel::getByParentId($user_id), 1, '+');
-            }
-            Db::commit();
-            $this->success('ok', $order_no);
-        } catch (Exception $e) {
-            Db::rollback();
-            $this->error($e->getMessage(), null, $e->getCode());
-        }
-    }
-    public function resetAirdrop()
-    {
-        $order_list = (new ProductOrder())
-            ->where('type_id', 3)
-            ->group('user_id')
-            ->column('user_id');
-        dump($order_list);
-        $order_list_send = (new ProductOrder())
-            ->where('type_id', 4)
-            ->group('user_id')
-            ->column('user_id');
-        dump($order_list_send);
-        $order_list = array_diff($order_list, $order_list_send);
-        dump($order_list);
-        $rs = (new ProductOrder())
-            ->where('type_id', 3)
-            ->where('user_id', 'in', $order_list)
-            ->update([
-                'create_time' => 1745942400
-            ]);
-        dump($rs);
-    }
-
-    public function updateNews()
-    {
-        $en_news = DB::name('announcement_cope')->select();
-        foreach ($en_news as $info) {
-            if(strlen($info['en_title']) > 3){
-                $rs = (new AnnouncementModel())
-                    ->save([
-                        'type_id' => $info['type_id'],
-                        'title' => $info['en_body'],
-                        'introduction' => $info['en_introduction'],
-                        'body' => $info['en_body'],
-                        'img_url' => $info['img_url'],
-                        'to_lang' => 1,
-                        'status' => $info['status'],
-                        'created_by' => $info['created_by'],
-                        'createtime' => $info['createtime'],
-                    ]);
-            }
-        }
-        dump($rs);
-    }
-
-
-}

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

@@ -17,6 +17,7 @@ class LedgerTeacChangeModel extends Model
     const Buying           = 3;
     const BuySell          = 4;
     const SellCancel       = 5;
+    const ProductOrder       = 6;
     /*
      * 支付状态
      * 0未支付 100支付中 200支付成功 400支付失败

+ 6 - 1
application/common/model/ProductOrder.php

@@ -43,7 +43,8 @@ class ProductOrder extends Model
     const Airdrop           = 5; //空投
     const Synthesi          = 6; //合成
     const Buying            = 7; //求购
-    const Exchange          = 8; //兑换
+    const RwaExchange       = 8; //Rwa茶兑换
+    const TeacExchange      = 9; //Teac兑换
 
     // 订单状态 '已下单', 1=>'已付款', 2=>'已转让', 3=>'提货', 4=>'已取消', 5=>'完成'];
     public $order_status = [
@@ -198,6 +199,10 @@ class ProductOrder extends Model
             ['type_id'=>self::Newbie, 'status' => self::Closure, 'text' => __('新人茶权关闭')],
             ['type_id'=>self::Super, 'status' => self::Paid, 'text' => __('新人福利')],
             ['type_id'=>self::Super, 'status' => self::Closure, 'text' => __('新人福利关闭')],
+            ['type_id'=>self::RwaExchange, 'status' => self::Paid, 'text' => __('Rwa兑换')],
+            ['type_id'=>self::RwaExchange, 'status' => self::Closure, 'text' => __('Rwa兑换关闭')],
+            ['type_id'=>self::TeacExchange, 'status' => self::Paid, 'text' => __('Teac兑换')],
+            ['type_id'=>self::TeacExchange, 'status' => self::Closure, 'text' => __('Teac兑换关闭')],
         ];
     }