afa 6 months ago
parent
commit
0a989ffd1d

+ 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();

+ 39 - 71
application/api/controller/Teac.php

@@ -14,40 +14,28 @@ use fast\Asset;
 use Exception;
 use fast\RechargeStatus;
 use think\Db;
-
+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 getBuyingList()
+    public function getTeacList(TeacTrade $teacTrade)
     {
         
-        $params = $this->request->post();
-        $validate = \think\Loader::validate('Teac');
-        if(!$validate->scene('buying')->check($params)) $this->error($validate->getError());
-        halt(11);
+        $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);
     }
 
 
@@ -59,8 +47,8 @@ class Teac extends Api
         $params = $this->request->post();
         $validate = \think\Loader::validate('Teac');
         if(!$validate->scene('buying')->check($params)) $this->error($validate->getError());
-        
-        if(config('teac_trade.sell_min_price') > $params['price']) $this->error('价格不能低于'.config('teac_trade.sell_min_price'));
+        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('您的钱包茶宝余额不足');
@@ -85,24 +73,26 @@ class Teac extends Api
 
 
     //发布出售
-    public function setSell()
+    public function setSell(LedgerWalletModel $ledgerWalletModel, TeacLogin $teacLogin)
     {
+        $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'));
 
-        $chabao = $ledgerWalletModel->getWalletChaBao($this->auth->id);
-        if($chabao < bcmul($params['price'], $params['stock'], 2)) $this->error('您的钱包茶宝余额不足');
+        $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']);
+            $order_price = $teacLogin::setCreateOrder($this->auth->id, $params['price'],  $params['stock'], TeacTrade::Sell);
 
             //冻结资产
-            $ledgerWalletModel->changeWalletAccount($this->auth->id,  Asset::TOKEN, -$order_price, LedgerTokenChangeModel::Buying, $this->auth->id);
+            $ledgerWalletModel->changeWalletAccount($this->auth->id,  Asset::TEAC, -$order_price, LedgerTokenChangeModel::Buying, $this->auth->id);
 
             Db::commit();
             $this->success('订单创建成功');
@@ -114,58 +104,26 @@ class Teac extends Api
 
 
     /**
-     * 手段向某会员报单算力
+     * 出售购买
      * @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) {
@@ -175,8 +133,18 @@ class Teac extends Api
         }
     }
 
+
+    /**
+    * 求购出售
+    */
+    public function getBuyOrder()
+    {
+        $this->success('ok', config('teac_trade'));
+    }
+
+
     /**
-    *获取配置
+    * 获取配置
     */
     public function getConfig()
     {

+ 6 - 38
application/api/logic/TeacLogin.php

@@ -27,65 +27,33 @@ class TeacLogin
     /**
      * 发布求购信息
      */
-    public static  function setCreateOrder(int $uid, float $price, int $stock)
+    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, TeacTrade::Buying, $price, $stock, bcmul($price, $stock, 2));
+        return TeacTrade::setUserCreateOrder($uid, $typeId, $price, $stock, bcmul($price, $stock, 2));
 
 
     }
 
       /**
-       * 根据钱包地址查询交易记录
+       * 发布出售
        * @$address  查询地址
        * @$from_to  是查询付款交易(from),还剩收款交易(to),默认from
        */
-      public function getTransactionRecordsByAddress(string $from, string $to, int $start_block, int $end_block = 99999999)
+      public function setCreateSellOrder(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);
+ 
       }
 
       /**

+ 2 - 4
application/api/validate/Teac.php

@@ -42,10 +42,8 @@ class Teac extends Validate
      */
     protected $scene = [
        
-        'announcement' => ['product_id'],
-        'transferlock' => ['transfer_id'],
-        'buying'       => ['price', 'stock'],
-        'buying_info'  => ['buying_id'],
+        'buying'     => ['price', 'stock'],
+        'sell'       => ['price', 'stock'],
         'sellbuying'   => ['buying_id', 'order_id'],
         'cancelbuying' => ['buying_id'],
     ];

+ 5 - 0
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');

+ 4 - 2
application/config.php

@@ -335,9 +335,11 @@ return [
     ],
     //Teac配置
     'teac_trade' => [
-        'sell_min_price'         => 10,    //最小出售价格
+        'sell_min_price'         => 100,    //最小出售价格
+        'sell_min_num'           => 10,    //最小出售数量
         'sell_serve_fee'         => 0.045, //出售服务费
-        'buy_min_price'          => 10,    //最小求购价格
+        'buy_min_price'          => 100,    //最小求购价格
+        'buy_min_num'            => 10,    //最小求购数量
         'buy_serve_fee'          => 0.045, //求购服务费
         'sell_desc'              => "出售说明",
         'buy_desc'               => "求购说明",   //求购说明

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

@@ -31,7 +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: '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},