Эх сурвалжийг харах

Merge branch 'master' of https://git.hxiaoju.top/Teapay/RWACha-API

* 'master' of https://git.hxiaoju.top/Teapay/RWACha-API:
  权限
  分类查询
  寄售转让列表
  寄售转让收藏列表
  寄售
  取消市场寄售
  地板价
  求购teac
  取消

# Conflicts:
#	application/api/controller/Test.php
jason 6 сар өмнө
parent
commit
a142899ebf

+ 2 - 0
application/admin/controller/general/Announcement.php

@@ -18,6 +18,8 @@ class Announcement extends Backend
      */
     protected $model = null;
 
+    protected $multiFields = 'status,is_show' ;
+
     public function _initialize()
     {
         parent::_initialize();

+ 1 - 1
application/admin/view/general/announcement/add.html

@@ -21,7 +21,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('关联产品')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-product_id" data-rule="required" data-source="product/lists/index" data-multiple="true" data-field="zh_name" class="form-control selectpage" name="row[product_id]" type="text" value="">
+            <input id="c-product_id"  data-source="product/lists/index" data-multiple="true" data-field="zh_name" class="form-control selectpage" name="row[product_id]" type="text" value="">
         </div>
     </div>
 

+ 1 - 1
application/admin/view/general/announcement/edit.html

@@ -20,7 +20,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('关联产品')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-product_id" data-rule="required" data-source="product/lists/index" data-multiple="true" data-field="zh_name" class="form-control selectpage" name="row[product_id]" type="text" value="{$row.product_id|htmlentities}">
+            <input id="c-product_id" data-source="product/lists/index" data-multiple="true" data-field="zh_name" class="form-control selectpage" name="row[product_id]" type="text" value="{$row.product_id|htmlentities}">
         </div>
     </div>
 

+ 2 - 0
application/api/controller/Home.php

@@ -44,6 +44,7 @@ class Home extends Api
             ->field('id,title as title,img_url,createtime')
             ->where('type_id', $announcement::Banner)
             ->where('status', $announcement::Normal)
+            ->where('is_show', $announcement::Normal)
             ->where('to_lang', $this->lan)
             ->limit(0,10)
             ->order('id DESC,weigh desc')
@@ -54,6 +55,7 @@ class Home extends Api
             ->field('id,title as title,img_url,createtime')
             ->where('type_id', $announcement::Announ)
             ->where('status', $announcement::Normal)
+            ->where('is_show', $announcement::Normal)
             ->where('to_lang', $this->lan)
             ->limit(0,10)
             ->order('id DESC,weigh desc')

+ 1 - 1
application/api/controller/Market.php

@@ -164,7 +164,7 @@ class Market extends Api
             $ledgerWalletModel->changeWalletOnly($buying->user_id, Asset::BUYING, -$buying->min_price); //解冻金额
 
             //添加订单
-            $productOrder::setCreateOrder($params['order_id'], ['product_id' => $buying->product_id, 'area_id' => 0,'price' => $buying->min_price], ProductOrder::Buying, $buying->user_id,  $this->auth->id, getOrderSN('R'), 0, $buying->min_price);
+            $productOrder::setCreateOrder($params['order_id'], ['product_id' => $buying->product_id, 'area_id' => 0,'price' =>$buying->min_price], ProductOrder::Buying, $buying->user_id,  $this->auth->id, getOrderSN('R'), 0, $buying->min_price);
 
             //关闭订单
             $productOrder::where('id', $params['order_id'])->where('user_id', $this->auth->id)->setField(['status' => ProductOrder::Closure]);

+ 1 - 1
application/api/controller/Order.php

@@ -118,7 +118,7 @@ class Order extends Api
 
 
     /**
-     * 订单寄售转让
+     * 添加订单寄售转让
      * @return void
      */
     public function transfer(ProductOrder $productOrder, MarketLogic $marketLogic)

+ 32 - 31
application/api/controller/Product.php

@@ -6,8 +6,7 @@ use think\Db;
 use think\Loader ;
 use app\common\controller\Api;
 use app\common\model\ProductLists;
-use app\common\model\ProductMarket;
-use app\common\model\ProductOrder;
+use app\common\model\ProductTransfer;
 use app\common\model\ProductsModel;
 use app\common\model\ProductPopular;
 use app\api\logic\OrderLogic;
@@ -64,23 +63,22 @@ class Product extends Api
      * type_id 分类
      * key_val 商品名称搜索
      */
-    public function getTransferList(ProductMarket $productMarket, OrderLogic $orderLogic)
+    public function getTransferList(ProductTransfer $productTransfer, OrderLogic $orderLogic)
     {
-
         $sort    = $this->request->post('sort/d', '');
         $type_id = $this->request->post('type_id/s', '');
         $key_val = $this->request->post('key_val/s', '');
-        $order = 'a.price ASC';
-        if($sort == 1) $order = 'a.price DESC';
-        $map['product_market.status'] = $productMarket::Normal;
-        if(!empty($type_id)) $map['product_market.type_id'] = $type_id;
-        if(!empty($key_val)) $map['product_list.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%'];
-
-        $list = $productMarket
+        $order = 'price ASC';
+        if($sort == 1) $order = 'price desc';
+        $map['a.status'] = $productTransfer::Normal;
+        if(!empty($type_id)) $map['b.type_id'] = $type_id;
+        if(!empty($key_val)) $map['b.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%'];
+     
+        $list = $productTransfer
             ->alias('a')
             ->join("product_list b", "a.product_id = b.id", "left")
-            ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.product_id,a.type_id')
-            ->where('a.status', $productMarket::Normal)
+            ->group('a.product_id')
+            ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,min(a.price) as price,a.product_id,b.type_id')
             ->where($map)
             ->order($order)
             ->paginate($this->pageSize);
@@ -97,25 +95,27 @@ class Product extends Api
      * type_id 分类
      * key_val 商品名称搜索
      */
-    public function getTransferCollectList(ProductMarket $productMarket, OrderLogic $orderLogic)
+    public function getTransferCollectList(ProductTransfer $productTransfer, OrderLogic $orderLogic)
     {
         $sort    = $this->request->post('sort/d', '');
         $type_id = $this->request->post('type_id/s', '');
         $key_val = $this->request->post('key_val/s', '');
-        $order = 'a.price ASC';
-        if($sort == 1) $order = 'a.price DESC';
-        $map['a.status'] = $productMarket::Normal;
-        if(!empty($type_id)) $map['a.type_id'] = $type_id;
+        $order = 'b.weigh desc';
+        if($sort == 1) $order = 'price DESC';
+        if($sort == 2) $order = 'price ASC';
+        $map['a.status'] = $productTransfer::Normal;
+        if(!empty($type_id)) $map['b.type_id'] = $type_id;
         if(!empty($key_val)) $map['b.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%'];
-        $list = $productMarket->alias('a')
+        $list = $productTransfer->alias('a')
             ->join("product_list b", "a.product_id = b.id", "left")
-            ->join("user_collect c", "c.market_id = a.id and c.user_id = {$this->auth->id}")
-            ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.product_id,a.type_id')
-            ->where('a.status', $productMarket::Normal)
+            ->join("user_collect c", "c.product_id = a.product_id and c.user_id = {$this->auth->id}")
+            ->group('a.product_id')
+            ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,min(a.price) as price,a.product_id,b.type_id')
+            ->where('a.status', $productTransfer::Normal)
             ->where($map)
             ->order($order)
             ->paginate($this->pageSize);
-
+        //统计
         $list = $this->getProductOrderList($list, $this->auth->id, false, $orderLogic);
         $this->success('', $list);
     }
@@ -128,18 +128,19 @@ class Product extends Api
      * type_id 分类
      * key_val 商品名称搜索
      */
-    public function getTransferDetail(ProductMarket $productMarket, OrderLogic $orderLogic)
+    public function getTransferDetail(ProductLists $productLists, OrderLogic $orderLogic)
     {
-
+       
         $ids    = $this->request->post('ids/d', '');
-        $list = $productMarket->with('products,producttransfer,collect')
-            ->where('product_market.id',   $ids)
-            ->where('product_market.status', $productMarket::Normal)
+        $list = $productLists->with('producttransfer,collect')
+            ->where('product_list.id',   $ids)
+            ->where('product_list.status', $productLists::Normal)
+            ->field('id,'.$this->lan .'_name as name,thum,details')
             ->find();
         if(empty($list)) $this->error('数据不存在');
 
-        $list->issue       = $orderLogic::getProductIssue($list->product_id);  //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的   
-        $list->circulation = $orderLogic::getProductCirculation($list->product_id);  //流通: 所有用户的持有量  
+        $list->issue       = $orderLogic::getProductIssue($list->id);  //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的   
+        $list->circulation = $orderLogic::getProductCirculation($list->id);  //流通: 所有用户的持有量  
         $this->success('', $list);
     }
  
@@ -158,7 +159,7 @@ class Product extends Api
         if($list){
             $userCollect = Loader::model('UserCollect');
             foreach ($list as &$item) {
-                if($isCollect) $item['collect'] = $userCollect::where('user_id', $uid)->where('market_id', $item->id)->count();
+                if($isCollect) $item['collect'] = $userCollect::where('user_id', $uid)->where('product_id', $item->product_id)->count();
                 $item['issue']       = $orderLogic::getProductIssue($item->product_id);  //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的   
                 $item['circulation'] = $orderLogic::getProductCirculation($item->product_id);  //流通: 所有用户的持有量    
             }

+ 85 - 518
application/api/controller/Teac.php

@@ -4,329 +4,126 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
-use app\common\model\AnnouncementModel;
-use app\common\model\LedgerUsdtChangeModel;
-use app\common\model\OfflineRechargeRecordModel;
+use app\api\logic\TeacLogin;
 use app\common\model\ParametersModel;
-use app\common\model\ProductOrder;
+use app\common\model\LedgerTokenChangeModel;
 use app\common\model\UserModel;
-use app\common\model\UserPathModel;
 use app\common\model\LedgerWalletModel;
 use fast\Action;
 use fast\Asset;
-use fast\Http;
+use Exception;
 use fast\RechargeStatus;
 use think\Db;
-use think\Log;
-use think\Model;
+use app\common\model\TeacTrade;
 
 //Teac交易
 class Teac extends Api
 {
     
     
-      //出售
-      public function getSell()
-      {
-        //从主表复制到备份表
-        //$user_list = Db::query("SELECT * FROM `user` where id in (SELECT user_id from user_path where parent_id = 100098) or id = 100098");
-        $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', 100098)
-            ->where('p.parent_id', 100115)
-            ->select();
-
-        halt($i);
-     }
 
     /*
-     * 更新上级
+     * 求购列表
      */
-    public function change_parent()
+    public function getTeacList(TeacTrade $teacTrade)
     {
-        //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);
+        
+        $type_id = $this->request->post('type_id/d', 0);
+        if(!in_array($type_id, [TeacTrade::Buying, TeacTrade::Sell])) $this->error('类型错误');
+           
+        $list = $teacTrade->where('status', TeacTrade::Normal)->where('type_id', $type_id )
+        ->order('create_time desc')
+        ->paginate($this->pageSize);
+        
+        $this->success('ok', $list);
     }
 
+
     /*
-     * 更新上级
-     *
-     * 更改给定ID的上级,并把它的直推一并更改
+     * 发布求购
      */
-    public function resetParent()
+    public function setBuying(LedgerWalletModel $ledgerWalletModel, TeacLogin $teacLogin)
     {
-        //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);
+        $params = $this->request->post();
+        $validate = \think\Loader::validate('Teac');
+        if(!$validate->scene('buying')->check($params)) $this->error($validate->getError());
+        if(config('teac_trade.buy_min_num') > $params['stock']) $this->error('数量不能低于'.config('teac_trade.buy_min_num'));
+        if(config('teac_trade.buy_min_price') > $params['price']) $this->error('价格不能低于'.config('teac_trade.buy_min_price'));
+
+        $chabao = $ledgerWalletModel->getWalletChaBao($this->auth->id);
+        if($chabao < bcmul($params['price'], $params['stock'], 2)) $this->error('您的钱包茶宝余额不足');
+        
+        Db::startTrans();
+        try{
+            
+            //新增求购信息
+            $order_price = $teacLogin::setCreateOrder($this->auth->id, $params['price'],  $params['stock']);
 
-        $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();
+            //冻结资产
+            $ledgerWalletModel->changeWalletAccount($this->auth->id,  Asset::TOKEN, -$order_price, LedgerTokenChangeModel::Buying, $this->auth->id);
 
-            // 创建网体
-            (new UserPathModel())->createPath($user['id'], $user['parent_id']);
-            $i++;
+            Db::commit();
+            $this->success('订单创建成功');
+        }catch(Exception $e){
+            Db::rollback();
+            $this->error($e->getMessage());
         }
-
-        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()
+    //发布出售
+    public function setSell(LedgerWalletModel $ledgerWalletModel, TeacLogin $teacLogin)
     {
-        $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']);
+        $params = $this->request->post();
+        $validate = \think\Loader::validate('Teac');
+        if(!$validate->scene('sell')->check($params)) $this->error($validate->getError());
+        
+        if(config('teac_trade.sell_min_num') > $params['price']) $this->error('数量不能低于'.config('teac_trade.sell_min_num'));
+        if(config('teac_trade.sell_min_price') > $params['price']) $this->error('价格不能低于'.config('teac_trade.sell_min_price'));
+
+        $teac = $ledgerWalletModel->getWalletTeac($this->auth->id);
+        if($teac < bcmul($params['price'], $params['stock'], 2)) $this->error('您的钱包Teac余额不足');
+        
+        Db::startTrans();
+        try{
+            
+            //新增求购信息
+            $order_price = $teacLogin::setCreateOrder($this->auth->id, $params['price'],  $params['stock'], TeacTrade::Sell);
+
+            //冻结资产
+            $ledgerWalletModel->changeWalletAccount($this->auth->id,  Asset::TEAC, -$order_price, LedgerTokenChangeModel::Buying, $this->auth->id);
 
-            //更新钱包
-            $is_up = (new LedgerWalletModel())
-                ->where('user_id', $user['id'])
-                ->update($info);
-            dump($user['id'] . '更新' . $is_up);
-            $i++;
+            Db::commit();
+            $this->success('订单创建成功');
+        }catch(Exception $e){
+            Db::rollback();
+            $this->error($e->getMessage());
         }
-        dump($i);
     }
 
+
     /**
-     * 手段向某会员报单算力
+     * 出售购买
      * @return void
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\exception\DbException
      */
-    public function updateOrder()
+    public function setSellOrder()
     {
-        //算力租赁订单处理
-        // 查询兑换比例
-        $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); // 该用户兑得的算力
+      
+        $params = $this->request->post();
+        $validate = \think\Loader::validate('Teac');
+        if(!$validate->scene('sell_order')->check($params)) $this->error($validate->getError());
         // 启动事务
         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) {
@@ -336,252 +133,22 @@ class Teac extends Api
         }
     }
 
-    //重算团队业绩和直推人数
-    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()
+    * 求购出售
+    */
+    public function getBuyOrder()
     {
-        $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'];
-        }
-
+        $this->success('ok', config('teac_trade'));
     }
 
-    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()
-    {
-        $num =rand(9000,10000);
-        dump($num/10000/1000);
-        $body = (new MyBscApi())->getInfoByTransactionHash('0xc3fc59faa9a1a9ff4fa1516b7df10570876a87993c397f6cd33ce3446641b5b0');
-        dump($body);
-    }
-    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()
+    /**
+    * 获取配置
+    */
+    public function getConfig()
     {
-        $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);
+        $this->success('ok', config('teac_trade'));
     }
+   
 }

+ 9 - 52
application/api/logic/MarketLogic.php

@@ -9,7 +9,7 @@ use think\Loader ;
 use app\common\model\ProductOrder;
 use app\common\model\ProductLists;
 use app\common\model\ProductTransfer;
-use app\common\model\ProductMarket;
+
 
 //自由市场
 class MarketLogic
@@ -18,32 +18,7 @@ class MarketLogic
       // 添加市场寄售订单
       public static function createTransferOrder(float $price, int $productId, int $areaId, string $orderNo, int $userId, array $params)
       {
-            //获取市场价
-            $minPrice = ProductTransfer::getTransferMinPrice($productId);
-            if($price < $minPrice || empty($minPrice)) $minPrice = $price;
-
-            //添加市场
-            $rows = ProductMarket::where('product_id', $productId)->find();
-            if(empty($rows)){
-                  ProductMarket::create([
-                  'product_id' => $productId, 
-                  'type_id'    => ProductLists::getProductTypeById($productId), 
-                  'price'      => $minPrice,'status' => ProductMarket::Normal]);
-            }else{
-
-                  $isUpdate = false;    
-                  //更新市场状态
-                  if($rows->status != ProductMarket::Normal ){
-                        $rows->status = ProductMarket::Normal;
-                        $isUpdate = true;
-                  }
-                  //更新最低价
-                  if($rows->price != $minPrice){
-                        $rows->price = $minPrice;
-                        $isUpdate = true;
-                  }
-                  if($isUpdate) $rows->save();
-            }
+          
             //添加寄售订单
             $fee = getConfig('transfer_fee');
             $feeAmount = bcmul($price, $fee, 2) ;
@@ -52,33 +27,15 @@ class MarketLogic
 
 
 
-      //取消寄售更新最低价
+      //取消寄售更新
       public static function cancelTransferOrder(int $orderId, int $userId, $orderInfo)
       {
-            //市场
-            $market = ProductMarket::where('product_id', $orderInfo['product_id'])->find();
-            if($market){
-                  $isUpdate = false;
-                  //是否全部取消
-                  $rows  = ProductTransfer::where('order_id', $orderId)->find();
-                  $count = ProductTransfer::where('product_id', $orderInfo['product_id'])->where('status', ProductTransfer::Normal)->count();
-                  if($count == 1){
-                        $isUpdate = true;
-                        $market->status = ProductMarket::Hidden;
-                  }else{
-                        //取消最小价格
-                        if($rows->price < $market->price){
-                              $isUpdate = true;
-                              $market->price = ProductTransfer::getTransferMinPriceByProduct($orderInfo['product_id'], $rows->price);
-                        }
-                  }
-                  //市场状态
-                  if($isUpdate) $market->save();
-      
-                  //转让列表取消
-                  $rows->status = ProductTransfer::Stop;
-                  $rows->save();
-            }
+            //转让
+            $rows  = ProductTransfer::where('order_id', $orderId)->find();
+           
+            //转让列表取消
+            $rows->status = ProductTransfer::Stop;
+            $rows->save();
             //新增记录
             return ProductOrder::setCreateOrder($orderInfo['order_id'], $orderInfo, ProductOrder::Popular, $userId, $orderInfo['from_user'], getOrderSN('R'.$orderInfo['order_id']), 0, $orderInfo->popular_price);
       }

+ 155 - 0
application/api/logic/TeacLogin.php

@@ -0,0 +1,155 @@
+<?php
+
+namespace app\api\logic;
+
+use app\api\controller\Teac;
+use app\common\model\ParametersModel;
+use app\common\model\ServersModel;
+use app\common\model\TeacTrade;
+use fast\Http;
+use think\Loader;
+use Exception;
+use finfo;
+use think\Cache;
+use think\Env;
+use think\Log;
+
+/**
+ * Teac交易
+ */
+class TeacLogin
+{
+    
+     
+
+ 
+
+    /**
+     * 发布求购信息
+     */
+    public static  function setCreateOrder(int $uid, float $price, int $stock, int $typeId = TeacTrade::Buying):float
+    {
+        
+        $rows = TeacTrade::where('status', TeacTrade::Normal)->find();
+        if($rows)  throw new Exception(__("你有未完成的求购订单、不能重复发布"));
+
+        //添加订单信息
+        return TeacTrade::setUserCreateOrder($uid, $typeId, $price, $stock, bcmul($price, $stock, 2));
+
+
+    }
+
+      /**
+       * 发布出售
+       * @$address  查询地址
+       * @$from_to  是查询付款交易(from),还剩收款交易(to),默认from
+       */
+      public function setCreateSellOrder(string $from, string $to, int $start_block, int $end_block = 99999999)
+      {
+        if(empty($from) && empty($to)){
+            return _error('钱包地址不能都为空');
+        }
+
+     
+
+
+ 
+      }
+
+      /**
+       * 获取哈希地址成功状态
+       * @param $orderInfo
+       * @return array|string
+       */
+      public function getHashStatus($tx_hash):array
+      {
+        if (empty($tx_hash)) {
+            return _error('hash值不能为空');
+        }
+
+        $url = "https://api.bscscan.com/api?module=transaction&action=gettxreceiptstatus";
+        $url .= "&apikey=" . $this->bsc_api_key;
+        $url .= "&txhash=" . $tx_hash;
+
+        $body = Http::get($url);
+        if (empty($body)) {
+            return _error('状态api返回内容为空');
+        }
+        // 转成数组
+        $rsArr = json_decode($body, true);
+        if (empty($rsArr) || !is_array($rsArr)) {
+            return _error('状态api返回数据异常,json转换失败');
+        }
+
+        if ($rsArr['status'] != '1') {
+            return _error('状态api返回status不为1,当前值为:' . $rsArr['status']);
+        }
+
+        if ($rsArr['result']['status'] != 1) {
+            return _error('状态api返回result中的status不为1,当前值为:' . $rsArr['result']['status']);
+        }
+
+        return _success();
+      }
+
+      /**
+       * 根据时间戳获取最近的区块高度     
+       * api接口返回数据格式
+       * @param $orderInfo
+       * @return array|string
+       */
+      public function getBlockNoByTime($time):array
+      {
+        if(!Cache::has('block_' . $time)){
+            if (empty($time)) {
+                return _error('时间戳不能为空');
+            }
+
+            //https://api.bscscan.com/api?module=block&action=getblocknobytime&timestamp=1601510400&closest=before&apikey=YourApiKeyToken
+
+            $url = "https://api.bscscan.com/api?module=block&action=getblocknobytime&";
+            $url .= "&closest=before";//closest 值还有个参数 after 控制返回接近时间戳之前还是之后的区块高度
+            $url .= "&apikey=" . $this->bsc_api_key;
+            $url .= "&timestamp=" . $time;
+            dump($url);
+            $body = Http::get($url);
+            if (empty($body)) {
+                return _error('获取区块高度api返回内容为空');
+            }
+            // 转成数组
+            $rsArr = json_decode($body, true);
+            if (empty($rsArr) || !is_array($rsArr)) {
+                return _error('获取区块高度api返回数据异常,json转换失败');
+            }
+
+            if ($rsArr['status'] != '1') {
+                return _error($rsArr['message'] . ' -- ' . $rsArr['result']);
+            }
+
+
+            Cache::set('block_' . $time, _success($rsArr['result']), 3600);
+            }
+            //获取开始预约前的区块高度
+            return Cache::get('block_' . $time);
+      }
+
+      public function getBlcokNoByCache($time){
+            if(!Cache::has('block')){
+                  $get_block = (new BscApi())->getBlockNoByTime($start_time);
+                  if($get_block['code'] == 0){
+                  Log::info($get_block['msg'] . date('Y-m-d H:i:s'));
+                  dump('获取区块高度有误');
+                  dump($get_block);
+                  return;
+                  }
+                  Cache::set('block', $get_block['data'], 3600);
+            }
+            //获取开始预约前的区块高度
+            $start_block = Cache::get('block');
+      }
+
+    
+
+
+  
+}

+ 1 - 1
application/api/logic/WelfareLoginc.php

@@ -11,7 +11,7 @@ use app\common\model\ProductOrder;
 use app\common\model\UserModel;
 use think\Db;
 use think\Log;
-use think\Exception;
+use Exception;
 /**
  *  空投福利
  */

+ 51 - 0
application/api/validate/Teac.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace app\api\validate;
+
+use think\Validate;
+
+class Teac extends Validate
+{
+    /**
+     * 验证规则
+     */
+    protected $rule = [
+      'market_id'     => 'require',
+      'product_id'    => 'require',
+      'transfer_id'   => 'require',
+      'price'     => 'require|number|gt:0',
+      'stock'           => 'require|number|gt:0',
+      'buying_id'     => 'require|number|gt:0',
+      'order_id'      => 'require|number',
+      'address'    => 'require',
+      'price'      => 'require|number|gt:0',
+    ];
+    
+    /**
+     * 提示消息
+     */
+    protected $message = [
+
+      'market_id.require'   => '订单ID有误',
+      'product_id.require'  => '产品ID有误', //
+      'transfer_id.require' => '参数ID有误',
+      'price'           => '价格有误',
+      'stock'                 => '数量有误',
+      'buying_id'           => '参数有误',
+      'order_id'            => '参数有误',
+      'phone.mobile'       => '手机号有误',
+      'address.require'    => '请填写地址',
+    ];
+    
+    /**
+     * 验证场景
+     */
+    protected $scene = [
+       
+        'buying'     => ['price', 'stock'],
+        'sell'       => ['price', 'stock'],
+        'sellbuying'   => ['buying_id', 'order_id'],
+        'cancelbuying' => ['buying_id'],
+    ];
+  
+}

+ 0 - 247
application/common/logic/TeacLogin.php

@@ -1,247 +0,0 @@
-<?php
-
-namespace app\common\logic;
-use app\common\model\OfflineRechargeRecordModel;
-use app\common\model\OfflineRechargeVerifyModel;
-use app\common\model\ParametersModel;
-use app\common\model\ServersModel;
-use app\common\model\UserModel;
-use fast\Http;
-use fast\RechargeOrderType;
-use fast\RechargeStatus;
-use fast\RechargeType;
-use think\Cache;
-use think\Env;
-use think\Log;
-
-/**
- * Teac交易
- */
-class TeacLogin
-{
-    
-     
-
- 
-
-    /**
-     * 根据哈希查看交易详情
-     *
-     * 此接口为抓取币安浏览器页面html代码而来
-     * 访问地址:https://bscscan.com/tx/0x48351c4c215645f2404741343c9be17b0ce494d70a7dba1bf11d1f5c2311de57
-     */
-    public function getInfoByTransactionHash($tx_hash = '0x48351c4c215645f2404741343c9be17b0ce494d70a7dba1bf11d1f5c2311de57')
-    {
-        if(empty($tx_hash)){
-            return _error('hash不能为空');
-        }
-        // 读取远程页面地址
-        $url = "https://bscscan.com/tx/" . $tx_hash;
-        dump($url);
-        // 使用 file_get_contents 函数读取远程页面
-        //$html = file_get_contents($url);
-        $html = Http::get($url);
-
-        if(empty($html)){
-            return _error('bscscan.com访问失败');
-        }
-//        dump($html);
-
-        $dom = new \DOMDocument();
-        libxml_use_internal_errors(true);//关掉错误提醒
-        $dom->loadHTML($html);
-        libxml_clear_errors();
-
-        $get_html_value = $dom->getElementById('spanTxHash');
-        if(empty($get_html_value)){
-            return _error('当前页面没找到hash');
-        }
-        $resp['hash'] = $get_html_value->nodeValue;
-
-        //$get_html_value = '<a class="text-break me-2" href="/address/' . $this->contract_address . '">' . $this->contract_address . '</a>';
-        //$get_html_value = '<a class="me-1" href="/token/' . $this->contract_address . '" target="_parent">BSC-USD</a>';
-        $get_html_value = '<a data-highlight-value data-highlight-target="' . $this->contract_address . '" class="d-flex align-items-center gap-0.5" href="/token/' . $this->contract_address . '">';
-
-        if (!(strstr($html, $get_html_value))) {
-            Log::error('合约地址和配置信息不相符:' . $tx_hash);
-            return _error('合约地址和配置信息不相符');
-        }
-
-        $xpath = new \DOMXPath($dom);
-
-        $get_html_value = $xpath->query('//span[@class="badge bg-success bg-opacity-10 border border-success border-opacity-25 text-green-600 fw-medium text-start text-wrap py-1.5 px-2"]');
-        if ($get_html_value->length > 0 && $get_html_value->item(0)->nodeValue == 'Success') {
-            $resp['pay_status'] = 1;
-        } else {
-            return _error('交易失败');
-        }
-
-        $get_html_value = $xpath->query('//span[@class="me-1"]');
-        if ($get_html_value->length > 0) {
-            $amount = $get_html_value->item(1)->nodeValue;//所有 span class='me-1' 的元素中,第二个就是额度,超过1000会有 逗号分割
-            $resp['amount'] = str_replace(',', "", $amount);
-        } else {
-            return _error('当前页面没找到交易额度');
-        }
-
-        $get_html_value = $dom->getElementById('chunk_decodeori_0_1');
-        if(empty($get_html_value)){
-            return _error('当前页面没找到from_address');
-        }
-        $resp['from_address'] = strtolower($get_html_value->nodeValue);//转小写
-
-        $get_html_value = $dom->getElementById('chunk_decodeori_0_2');
-        if(empty($get_html_value)){
-            return _error('当前页面没找到to_address');
-        }
-        $resp['to_address'] = strtolower($get_html_value->nodeValue);
-        return _success($resp);
-    }
-
-      /**
-       * 根据钱包地址查询交易记录
-       *
-       * @$address  查询地址
-       * @$from_to  是查询付款交易(from),还剩收款交易(to),默认from
-       */
-      public function getTransactionRecordsByAddress(string $from, string $to, int $start_block, int $end_block = 99999999)
-      {
-        if(empty($from) && empty($to)){
-            return _error('钱包地址不能都为空');
-        }
-
-        $from = strtolower($from);
-        $to = strtolower($to);
-
-        $address = $from;
-        if(empty($from)){
-            $address =$to;
-        }
-
-        // 读取远程页面地址
-        $url = "https://api.bscscan.com/api?module=account&action=tokentx&contractaddress=" . $this->contract_address;
-        $url .= "&page=1&offset=10000&endblock=" . $end_block ."&apikey=" . $this->bsc_api_key;
-        $url .= "&startblock=" . $start_block . "&address=" . $address;
-        Log::log($url);
-        $body = Http::get($url);
-        if (empty($body)) {
-            Log::log('api返回内容为空');
-            return _error('api返回内容为空');
-        }
-
-        // 转成数组
-        $rsArr = json_decode($body, true);
-        if (empty($rsArr) || !is_array($rsArr)) {
-            Log::log('api返回数据异常,json decode失败');
-            return _error('api返回数据异常');
-        }
-
-        if ($rsArr['status'] != '1') {
-            if($rsArr['message'] == 'No transactions found'){
-                Log::log('无交易记录:' . $rsArr['message']);
-                return _success();
-            }
-            Log::log('api返回status不为1,错误信息:' . $rsArr['message']);
-            return _error('api返回status不为1,错误信息:' . $rsArr['message']);
-        }
-
-        return _success($success_arr);
-      }
-
-      /**
-       * 获取哈希地址成功状态
-       * @param $orderInfo
-       * @return array|string
-       */
-      public function getHashStatus($tx_hash):array
-      {
-        if (empty($tx_hash)) {
-            return _error('hash值不能为空');
-        }
-
-        $url = "https://api.bscscan.com/api?module=transaction&action=gettxreceiptstatus";
-        $url .= "&apikey=" . $this->bsc_api_key;
-        $url .= "&txhash=" . $tx_hash;
-
-        $body = Http::get($url);
-        if (empty($body)) {
-            return _error('状态api返回内容为空');
-        }
-        // 转成数组
-        $rsArr = json_decode($body, true);
-        if (empty($rsArr) || !is_array($rsArr)) {
-            return _error('状态api返回数据异常,json转换失败');
-        }
-
-        if ($rsArr['status'] != '1') {
-            return _error('状态api返回status不为1,当前值为:' . $rsArr['status']);
-        }
-
-        if ($rsArr['result']['status'] != 1) {
-            return _error('状态api返回result中的status不为1,当前值为:' . $rsArr['result']['status']);
-        }
-
-        return _success();
-      }
-
-      /**
-       * 根据时间戳获取最近的区块高度     
-       * api接口返回数据格式
-       * @param $orderInfo
-       * @return array|string
-       */
-      public function getBlockNoByTime($time):array
-      {
-        if(!Cache::has('block_' . $time)){
-            if (empty($time)) {
-                return _error('时间戳不能为空');
-            }
-
-            //https://api.bscscan.com/api?module=block&action=getblocknobytime&timestamp=1601510400&closest=before&apikey=YourApiKeyToken
-
-            $url = "https://api.bscscan.com/api?module=block&action=getblocknobytime&";
-            $url .= "&closest=before";//closest 值还有个参数 after 控制返回接近时间戳之前还是之后的区块高度
-            $url .= "&apikey=" . $this->bsc_api_key;
-            $url .= "&timestamp=" . $time;
-            dump($url);
-            $body = Http::get($url);
-            if (empty($body)) {
-                return _error('获取区块高度api返回内容为空');
-            }
-            // 转成数组
-            $rsArr = json_decode($body, true);
-            if (empty($rsArr) || !is_array($rsArr)) {
-                return _error('获取区块高度api返回数据异常,json转换失败');
-            }
-
-            if ($rsArr['status'] != '1') {
-                return _error($rsArr['message'] . ' -- ' . $rsArr['result']);
-            }
-
-
-            Cache::set('block_' . $time, _success($rsArr['result']), 3600);
-            }
-            //获取开始预约前的区块高度
-            return Cache::get('block_' . $time);
-      }
-
-      public function getBlcokNoByCache($time){
-            if(!Cache::has('block')){
-                  $get_block = (new BscApi())->getBlockNoByTime($start_time);
-                  if($get_block['code'] == 0){
-                  Log::info($get_block['msg'] . date('Y-m-d H:i:s'));
-                  dump('获取区块高度有误');
-                  dump($get_block);
-                  return;
-                  }
-                  Cache::set('block', $get_block['data'], 3600);
-            }
-            //获取开始预约前的区块高度
-            $start_block = Cache::get('block');
-      }
-
-    
-
-
-  
-}

+ 0 - 31
application/common/model/LedgerSmhChangeModel.php

@@ -1,31 +0,0 @@
-<?php
-
-namespace app\common\model;
-
-use think\Model;
-
-class LedgerSmhChangeModel extends Model
-{
-
-    protected $name = "ledger_smh_change";
-    const SysSend           = 400;
-    const Exchange          = 401;
-    const WithdrawCash      = 402;
-    const WithdrawReturn    = 403;
-    const TeamBonus         = 404;
-    const SameLevel         = 405;
-
-    /*
-     * 支付状态
-     * 0未支付 100支付中 200支付成功 400支付失败
-     */
-    public $pay_status = [
-        '-1'                    => '全部',
-        self::SysSend           => '今日产出',
-        self::Exchange          => '兑换',
-        self::WithdrawCash      => '提现',
-        self::WithdrawReturn    => '提现退回',
-        self::TeamBonus         => '团队奖励',
-        self::SameLevel         => '平级奖励',
-    ];
-}

+ 0 - 13
application/common/model/LedgerUsdtChangeModel.php

@@ -1,13 +0,0 @@
-<?php
-
-namespace app\common\model;
-
-use think\Model;
-
-class LedgerUsdtChangeModel extends Model
-{
-
-    protected $name = "ledger_usdt_change";
-
-
-}

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

@@ -41,6 +41,11 @@ class LedgerWalletModel extends Model
         return self::where('user_id', $userID)->value('buying');
     }
 
+    public static function getWalletTeac(int $userID)
+    {
+        return self::where('user_id', $userID)->value('teac');
+    }
+
     public static function getWalletTotalChaBao($userID)
     {
         return self::where('user_id', $userID)->value('token + frozen');
@@ -139,7 +144,7 @@ class LedgerWalletModel extends Model
 
         // 余额不足的判断
         if ($amount < 0 && $available[$asset] < -$amount) {
-            throw new Exception($asset . '余额不足');
+            throw new Exception(Asset::getAssetName($asset) . '余额不足');
         }
 
         $newAmount    = bcadd($available[$asset], $amount, 6); // 新余额

+ 24 - 1
application/common/model/ProductLists.php

@@ -3,7 +3,7 @@
 namespace app\common\model;
 
 use think\Model;
-
+use app\common\library\Auth;
 
 class ProductLists extends Model
 {
@@ -64,6 +64,29 @@ class ProductLists extends Model
     {
         return $this->hasOne('ProductPopular', 'product_id', 'id', [], 'INNER')->order('start_time')->setEagerlyType(0);
     }
+
+
+    //寄售
+    public function producttransfer()
+    {   
+        $map = [];
+        $transfer = input('post.transfer_id/d', 0);
+        if($transfer > 0) $map['id'] = $transfer;
+        $order = 'id desc';
+        if(input('post.sort') == 1) $order = 'price desc';
+        if(input('post.sort') == 2) $order = 'price asc';
+        return $this->hasMany('ProductTransfer', 'product_id', 'id', [], 'LEFT')->where($map)->where('status', self::Normal)->order($order);
+    }
+
+       
+    //收藏
+    public function collect()
+    {   
+        
+        return $this->hasOne('UserCollect', 'product_id', 'id', [], 'LEFT')->where('user_id', Auth::instance()->getUser()['id']);
+    }
+
+        
     
     //获取产品分类
     public static function getProductTypeById(int $productId)

+ 95 - 0
application/common/model/TeacTrade.php

@@ -0,0 +1,95 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+
+//Teac求购
+class TeacTrade extends Model
+{
+
+    protected $name = "teac_trade";
+
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+
+    // 定义时间戳字段名
+    protected $createTime = 'create_time';
+    protected $updateTime = 'update_time';
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+        'create_time_text',
+        'update_time_text'
+    ];
+
+    //状态
+    const Normal        = 1;
+    const Closure       = 0;
+    const Complete      = 2;
+    
+    //类型
+    const Sell        = 1; //出售
+    const Buying      = 2; //求购
+
+    /*
+     * 支付状态
+     *  '状态1 正常 2 已出售 0关闭
+     */
+    public $status_list = [
+        '-1'                 => '全部',
+        self::Normal         => '正常',
+        self::Closure        => '已取消',
+        self::Complete       => '已完成',
+    ];
+
+
+    //添加订单信息
+    public static function setUserCreateOrder(int $uid, int $typeId, float $price, int $stock, float $frozen)
+    {
+        $total_price = bcmul($price, $stock, 2);
+        self::create([
+            'user_id' => $uid,
+            'type_id' => $typeId,
+            'price'   => $price,
+            'stock'   => $stock,
+            'total_price'=> $total_price,
+            'fee'     => bcmul($total_price, config('market_transfer.serve_fee'), 2),
+            'frozen'  => $frozen,
+        ]); 
+        return $total_price;
+    }
+
+    
+    //用户 user_id
+    public function users()
+    {
+        return $this->hasOne('UserModel', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+    public function getCreateTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getUpdateTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+    protected function setCreateTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setUpdateTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+}

+ 20 - 20
application/common/model/UserCollect.php

@@ -13,27 +13,27 @@ use think\Request;
 class UserCollect extends Model
 {
 
-      protected $name = "user_collect";
+    protected $name = "user_collect";
 
-  
-   
-      //设置用户收藏
-      public static function setUserCollect(int $uid, int $marketId)
-      {
-           $rows = self::where('user_id', $uid)->where('market_id', $marketId)->find();
-           if($rows){
-               return $rows->delete();
-           }else{
-               return self::create(['user_id'=>$uid, 'market_id'=>$marketId]);
-           }
-      }
-
-
-      //用户
-      public function users()
-      {
-          return $this->hasOne('UserModel', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
-      }
+
+
+    //设置用户收藏
+    public static function setUserCollect(int $uid, int $marketId)
+    {
+        $rows = self::where('user_id', $uid)->where('product_id', $marketId)->find();
+        if($rows){
+            return $rows->delete();
+        }else{
+            return self::create(['user_id'=>$uid, 'product_id'=>$marketId]);
+        }
+    }
+
+
+    //用户
+    public function users()
+    {
+        return $this->hasOne('UserModel', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
+    }
   
 
 }

+ 9 - 47
application/common/model/ProductMarket.php → application/common/model/UserTeac.php

@@ -3,16 +3,13 @@
 namespace app\common\model;
 
 use think\Model;
-use think\Request;
-use app\common\library\Auth;
 
-class ProductMarket extends Model
+//用户Teac交易记录
+class UserTeac extends Model
 {
 
-    // 表名
-    protected $table = 'product_market';
+    protected $name = "user_teac";
 
-    
     // 自动写入时间戳字段
     protected $autoWriteTimestamp = 'int';
 
@@ -21,52 +18,20 @@ class ProductMarket extends Model
     protected $updateTime = 'update_time';
     protected $deleteTime = false;
 
-
     // 追加属性
     protected $append = [
         'create_time_text',
         'update_time_text'
     ];
-    
-    //状态 normal, hidden
-    const Hidden           = 0;
-    const Normal           = 1;
-
-
- 
 
-    //收藏
-    public function collect()
-    {   
-     
-        return $this->hasOne('UserCollect', 'market_id', 'id', [], 'LEFT')->where('user_id', Auth::instance()->getUser()['id']);
-    }
- 
-
-   
-
-    //产品
-    public function products()
-    {   
-        $header = Request::instance()->header('Accept-Language');
-        $lan    = !empty($header)? substr($header, 0, 2):'zh' ;
-        return $this->hasOne('ProductLists', 'id', 'product_id', [], 'LEFT')->field('id,'.$lan .'_name as name,thum,details');
-    }
-
-
-    //寄售
-    public function producttransfer()
-    {   
-        $map = [];
-        $transfer = input('post.transfer_id/d', 0);
-        if($transfer > 0) $map['id'] = $transfer;
-        $order = 'price asc';
-        if(input('post.sort') == 1) $order = 'price desc';
-        return $this->hasMany('ProductTransfer', 'product_id', 'product_id', [], 'LEFT')->where($map)->where('status', self::Normal)->order($order);
+    
+    //用户 user_id
+    public function users()
+    {
+        return $this->hasOne('UserModel', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
     }
 
 
-
     public function getCreateTimeTextAttr($value, $data)
     {
         $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
@@ -80,7 +45,6 @@ class ProductMarket extends Model
         return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
     }
 
-
     protected function setCreateTimeAttr($value)
     {
         return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
@@ -90,6 +54,4 @@ class ProductMarket extends Model
     {
         return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
     }
-
-
-}
+}

+ 1 - 1
application/common/model/UserWelfare.php

@@ -4,7 +4,7 @@ namespace app\common\model;
 
 use think\Model;
 
-
+//新人福利配置信息
 class UserWelfare extends Model
 {
 

+ 11 - 0
application/config.php

@@ -333,4 +333,15 @@ return [
         'zh_serve_agree'      => 217, //中文服务协议id
         'en_serve_agree'      => 218, //英文协议id
     ],
+    //Teac配置
+    'teac_trade' => [
+        'sell_min_price'         => 100,    //最小出售价格
+        'sell_min_num'           => 10,    //最小出售数量
+        'sell_serve_fee'         => 0.045, //出售服务费
+        'buy_min_price'          => 100,    //最小求购价格
+        'buy_min_num'            => 10,    //最小求购数量
+        'buy_serve_fee'          => 0.045, //求购服务费
+        'sell_desc'              => "出售说明",
+        'buy_desc'               => "求购说明",   //求购说明
+    ],
 ];

+ 26 - 0
extend/fast/Asset.php

@@ -54,4 +54,30 @@ class Asset
      */
     const FROZEN = 'frozen';
 
+
+    public static function getAssetName($assetType)
+    {
+        switch ($assetType) {
+            case self::POWER:
+                return '总算力';
+            case self::USDT:
+                return 'USDT';
+            case self::TOKEN:
+                return '茶宝';
+            case self::TEAC:
+                return 'Teac';
+            case self::RENTAL_POWER:
+                return '服务器算力';
+            case self::BUYING:
+                return '求购锁定金额';
+            case self::SMH:
+                return 'SMH';
+            case self::FROZEN:
+                return '标记金额';
+            default:
+                return '未知';
+        }   
+
+    }
+
 }

+ 1 - 0
public/assets/js/backend/general/announcement.js

@@ -31,6 +31,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'img_url', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                         {field: 'weigh', title: __('Weigh'), operate: false},
                         {field: 'status', title: __('Status'), searchList: {"1":__('上架'),"2":__('下架')}, formatter: Table.api.formatter.toggle},
+                        {field: 'is_show', title: __('推荐'), searchList: {'0':__('否'), '1':__('是')}, formatter: Table.api.formatter.toggle},
                         {field: 'to_lang', title: __('所属语言'), operate: false,  searchList: {'zh':__('中文'), 'en':__('英文')}, formatter: Table.api.formatter.flag},
                         {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                         {field: 'updatetime', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},