afa 7 сар өмнө
parent
commit
1207cd289b

+ 1 - 7
application/admin/command/Task.php

@@ -87,15 +87,9 @@ class Task extends Command
                       
                   }
                   $row->details = json_encode($detail, JSON_UNESCAPED_UNICODE);
-                  $row->save();
-
-
-              
-      
-                  
+                  $row->save();   
             }
             
-
       }
 
 

+ 491 - 0
application/api/controller/Market.php

@@ -0,0 +1,491 @@
+<?php
+
+
+namespace app\api\controller;
+
+use app\common\logic\BscApi;
+use app\common\logic\MyBscApi;
+use app\common\controller\Api;
+use app\common\model\AnnouncementModel;
+use app\common\model\UserCollect;
+use app\common\model\LedgerSmhChangeModel;
+use app\common\model\LedgerUsdtChangeModel;
+use app\common\model\OfflineRechargeRecordModel;
+use app\common\model\OfflineWithdrawRecordModel;
+use app\common\model\ParametersModel;
+use app\common\model\ProductOrder;
+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 fast\RechargeStatus;
+use think\Db;
+use think\Log;
+use think\Model;
+
+class Market extends Api
+{
+
+
+      //用户收藏
+      public function collect(UserCollect $userCollect)
+      {
+    
+            $params = $this->request->post();
+            $validate = \think\Loader::validate('Market');
+            if(!$validate->scene('collect')->check($params)) $this->error($validate->getError());
+     
+            $userCollect::setUserCollect($this->auth->id, $params['transfer_id']);
+            $this->success("ok");
+      }
+
+
+
+    
+
+    /*
+     * 收藏列表
+     */
+    public function collectList()
+    {
+        //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);
+    }
+   
+    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()
+    {
+        $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()
+    {
+        $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);
+    }
+}

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

@@ -175,7 +175,7 @@ class Order extends Api
 
             // 生成订单
             $popularPrice = empty($popular_order->popular_price)? $order_info->price: $popular_order->popular_price;
-            $productOrder::setCreateOrder($params['order_id'], $order_info, $productOrder::Transfer, $this->auth->id, $order_info['user_id'], getOrderSN('R'.$params['order_id']), $order_info['fees'], $popularPrice);
+            $productOrder::setCreateOrder($params['order_id'], $order_info, $productOrder::Transfer, $this->auth->id, $order_info['user_id'], $popular_order->order_no, $order_info['fees'], $popularPrice);
            
             //扣除余额记录 
             $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$order_info['price'], LedgerTokenChangeModel::Payment, $order_info['user_id']);
@@ -229,7 +229,7 @@ class Order extends Api
             if(bccomp($fees, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001);
            
             //添加记录
-            $productOrder::setCreateOrder($params['order_id'], $order_info, $productOrder::Giveaway, $user['id'], $this->auth->id, getOrderSN('R'.$params['order_id']), $fees, $order_info->popular_price);
+            $productOrder::setCreateOrder($params['order_id'], $order_info, $productOrder::Giveaway, $user['id'], $this->auth->id, $order_info->order_no, $fees, $order_info->popular_price);
 
             //对方Rwa+1
             if($order_info->popular_price > config('min_rwa_price')) $userModel::updateForRwaNum($user['id'], $userModel::getByParentId($user['id']), 1, '+');

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

@@ -0,0 +1,51 @@
+<?php
+
+namespace app\api\validate;
+
+use think\Validate;
+
+class Market extends Validate
+{
+    /**
+     * 验证规则
+     */
+    protected $rule = [
+      'transfer_id'=> 'require',
+      'product_id' => 'require',
+      'area_id'    => 'requireIf:type,1',
+      'num'        => 'requireIf:type,2|gt:0',
+      'name'       => 'require',
+      'type'       => 'require|in:1,2',
+      'phone'      => 'require|mobile',
+      'address'    => 'require',
+      'price'      => 'require|number|gt:0',
+    ];
+    /**
+     * 提示消息
+     */
+    protected $message = [
+
+      'transfer_id.require'=> '订单ID有误',
+      'product_id.require' => '产品ID有误', //
+      'area_id.require'    => '位置ID有误',
+      'area_id.require'    => '位置ID有误',
+      'num.require'        => '数量有误',
+      'type.require'       => '参数有误',
+      'price.gt'           => '转让金额有误',
+      'name.require'       => '姓名不能为空',
+      'phone.mobile'       => '手机号有误',
+      'address.require'    => '请填写地址',
+    ];
+    
+    /**
+     * 验证场景
+     */
+    protected $scene = [
+        'collect'  => ['transfer_id'],
+        'pick' => ['order_id'],
+        'tran' => ['price', 'order_id'],
+        'out'  => ['order_id'],
+        'giv'  => ['order_id', 'address'],
+    ];
+  
+}

+ 0 - 26
application/common/model/LedgerQubicChangeModel.php

@@ -1,26 +0,0 @@
-<?php
-
-namespace app\common\model;
-
-use think\Model;
-
-class LedgerQubicChangeModel extends Model
-{
-
-    protected $name = "ledger_qubic_change";
-    const SysSend           = 500;
-    const Exchange          = 501;
-    const WithdrawCash      = 502;
-    const WithdrawReturn    = 503;
-
-    /*
-     * 支付状态
-     */
-    public $aciton_name = [
-        '-1'                    => '全部',
-        self::SysSend           => '今日产出',
-        self::Exchange          => '兑换',
-        self::WithdrawCash      => '提现',
-        self::WithdrawReturn    => '提现退回',
-    ];
-}

+ 27 - 0
application/common/model/ProductBuying.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+class ProductBuying extends Model
+{
+
+    protected $name = "product_buying";
+
+    //1 正常 2 已出售 0 关闭
+    const Normal    = 1;
+    const SaleOut   = 2;
+    const Close     = 0;
+
+    /*
+     * 订单状态
+     */
+    public $aciton_name = [
+        '-1'                => '全部',
+        self::Normal        => '正常',
+        self::SaleOut       => '已出售',
+        self::Close         => '关闭',
+
+    ];
+}

+ 39 - 0
application/common/model/UserCollect.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace app\common\model;
+
+use fast\Asset;
+use fast\Http;
+use fast\Random;
+use think\Cache;
+use think\Log;
+use think\Model;
+use think\Request;
+
+class UserCollect extends Model
+{
+
+      protected $name = "user_collect";
+
+  
+   
+      //设置用户收藏
+      public static function setUserCollect(int $uid, int $transferId)
+      {
+           $rows = self::where('user_id', $uid)->where('transfer_id', $transferId)->find();
+           if($rows){
+               return $rows->delete();
+           }else{
+               return self::create(['user_id'=>$uid, 'transfer_id'=>$transferId]);
+           }
+      }
+
+
+      //用户
+      public function users()
+      {
+          return $this->hasOne('UserModel', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
+      }
+  
+
+}

+ 75 - 0
application/common/model/UserSynthesis.php

@@ -0,0 +1,75 @@
+<?php
+
+namespace app\common\model;
+
+use fast\Asset;
+use fast\Http;
+use fast\Random;
+use think\Cache;
+use think\Log;
+use think\Model;
+use think\Request;
+
+class UserSynthesis extends Model
+{
+
+      protected $name = "user_synthesis";
+
+      // 自动写入时间戳字段
+      protected $autoWriteTimestamp = 'int';
+
+      // 定义时间戳字段名
+      protected $createTime = 'create_time';
+      protected $updateTime = 'update_time';
+      protected $deleteTime = false;
+
+      // 追加属性
+      protected $append = [
+            'create_time_text',
+            'update_time_text',
+      ];
+
+   
+      //设置用户合成记录
+      public static function setUserSynthesisLog(int $uid, int $transferId)
+      {
+           $rows = self::where('user_id', $uid)->where('transfer_id', $transferId)->find();
+           if($rows){
+               return $rows->delete();
+           }else{
+               return self::create(['user_id'=>$uid, 'transfer_id'=>$transferId]);
+           }
+      }
+
+
+      //用户
+      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);
+      }
+
+}