| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614 |
- <?php
- namespace app\api\controller;
- use app\common\logic\BscApi;
- use app\common\logic\MyBscApi;
- use app\common\logic\TeamRewards;
- use app\common\model\LedgerPowerChangeModel;
- 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\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 Test
- {
- public function copy_user()
- {
- //从主表复制到备份表
- //$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();
- $i = 0;
- foreach ($user_list as $user){
- $is = Db::table('user_1')
- ->insert($user);
- $i++;
- }
- halt($i);
- $user_list = Db::name('user_1')
- ->whereNull('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);
- // //从备份表中除掉不要的数据
- // $user_list = Db::query("SELECT * FROM `user_1` where id in (SELECT user_id from user_path where parent_id = 100277) or id = 100277");
- // $i = 0;
- // foreach ($user_list as $user){
- // $is = Db::table('user_1')
- // ->where('id', $user['id'])
- // ->delete();
- // $i++;
- // }
- // halt($i);
- //从备份表中根据上级ID,更新每个用户的上级钱包地址和钱包地址
- $user_list = Db::table('user_1')
- ->select();
- $i = 0;
- $is = Db::table('ledger_wallet_1')
- ->where('user_id', '>', 0)
- ->update([
- 'address' => null
- ]);
- $parent_arr[100115] = '0xc3e8f8179fad209304ada21708acdcf3834c448c';
- foreach ($user_list as $user){
- $parent_arr[$user['id']] = $user['address'];
- }
- foreach ($user_list as $user){
- $is = Db::table('ledger_wallet_1')
- ->where('user_id', $user['id'])
- ->update([
- 'address' => $user['address']
- ]);
- if(isset($parent_arr[$user['id']])){
- $is = Db::table('user_1')
- ->where('id', $user['id'])
- ->update([
- 'parent_address' => $parent_arr[$user['parent_id']]
- ]);
- $i++;
- }else{
- dump($user['id'] . '--无上级');
- }
- }
- halt($i);
- }
- /*
- * 更新上级
- */
- public function change_parent()
- {
- //1.从主表复制到备份表,需手动插入上级信息
- // dump('从主表复制到备份表');
- // $user_list = Db::name('user')
- // ->fetchSql(false)
- // ->field('u.*,p.distance')
- // ->alias('u')
- // ->join('user_path p', 'u.id = p.user_id')
- // ->where('p.parent_id', 101985)
- // //->where('u.id','>', 103931)
- // ->select();
- //
- // $i = 0;
- // foreach ($user_list as $user){
- // $is = Db::table('user_1')
- // ->insert($user);
- // $i++;
- // }
- // halt($i);
- //*2.更新备份表上级地址
- // dump('更新上级地址');
- // $user_list = Db::name('user_1')
- // ->whereNull('parent_address')
- // ->select();
- // $i = 0;
- // foreach ($user_list as $user){
- // $parent_info = (new UserModel())
- // ->where('id', $user['parent_id'])
- // ->find();
- // if(!empty($parent_info)){
- // $is = Db::table('user_1')
- // ->where('id', $user['id'])
- // ->update([
- // 'parent_address' => $parent_info['address']
- // ]);
- // $i++;
- // }
- // }
- // halt($i);
- //3.更新主表会员上级
- dump('重建网体');
- $user_list = Db::table('user_1')
- ->order('distance')
- ->select();
- $i = 0;
- foreach ($user_list as $user){
- $parent_info = (new UserModel())
- ->where('address', $user['parent_address'])
- ->find();
- if(!empty($parent_info)){
- $is = Db::table('user')
- ->where('id', $user['id'])
- ->update([
- 'parent_id' => $parent_info['id']
- ]);
- //删除网体
- (new UserPathModel())
- ->where('user_id', $user['id'])
- ->delete();
- // 创建网体
- (new UserPathModel())->createPath($user['id'], $parent_info['id']);
- $i++;
- } else{
- dump($user['id'] . '--无上级');
- }
- }
- halt($i);
- }
- /*
- * 更新上级
- *
- * 更改给定ID的上级,并把它的直推一并更改
- */
- public function resetParent()
- {
- //3.更新主表会员上级
- dump('重建网体');
- $parent_id = 100100;
- $user_id = 101134;
- $user = (new UserModel())
- ->fetchSql(false)
- ->where('id', $user_id)
- ->update([
- 'parent_id' => $parent_id
- ]);
- dump($user, true, '更新状态');
- //删除网体
- (new UserPathModel())
- ->where('user_id', $user_id)
- ->delete();
- // 创建网体
- (new UserPathModel())->createPath($user_id, $parent_id);
- $user_list = (new UserModel())
- ->where('parent_id', $user_id)
- ->select();
- $i = 0;
- foreach ($user_list as $user){
- //删除网体
- (new UserPathModel())
- ->where('user_id', $user['id'])
- ->delete();
- // 创建网体
- (new UserPathModel())->createPath($user['id'], $user['parent_id']);
- $i++;
- }
- halt($i);
- }
- /**
- 导入数据表生成 sql
- CREATE TABLE dao_ru AS SELECT
- u.id,
- u.parent_id,
- u.address,
- u.team_power,
- u.team_num,
- w.power,
- w.rental_power,
- w.usdt
- FROM
- `user` u
- LEFT JOIN ledger_wallet w ON u.id = w.user_id
- WHERE
- id IN ( SELECT user_id FROM `user_path` WHERE parent_id = 1012 )
- OR id = 1012
- ORDER BY
- id
- */
- public function daoru()
- {
- die;
- $daoru_list = Db::table('user_base')
- //->where('is_dao', 1)
- ->select();
- $i = 0;
- $j = 0;
- //重建钱包
- foreach ($daoru_list as $key => $info) {
- $user = (new UserModel())->getByAddress($info['address']);
- if (!empty($user)) { // 已存在
- // 更新总算力和账变
- (new LedgerWalletModel)->changeWalletAccount($user['id'], Asset::POWER, $info['power'], Action::Reversal, 0);
- // 更新自己(有效会员时间)和所有上级的信息(有效直推人数和团队总算力)
- (new UserModel())->updateForRental($user['id'], $info['power']);
- $j++;
- continue;
- }
- }
- //重建用户
- // foreach ($daoru_list as $key => $info) {
- //
- // $parent_user = (new UserModel())->getByAddress($info['parent_address']);
- // if(empty($parent_user)){
- // dump('没有上级');
- // dump($info);
- // continue;
- // }
- //
- // $user = (new UserModel())->getByAddress($info['address']);
- // if (!empty($user)) { // 已存在
- // dump($info['id'] . ' - ' . $info['address'] . ' - 已存在');
- //
- // $is = Db::table('user')
- // ->where('id', $user['id'])
- // ->update([
- // 'parent_id' => $parent_user['id']
- // ]);
- // $j++;
- // continue;
- // }
- //
- // unset($info['id']);
- // unset($info['parent_address']);
- // unset($info['is_dao']);
- // $info['parent_id'] = $parent_user['id'];
- // // 创建用户
- // $newUserID = (new UserModel())->insertGetId($info);
- // // 创建钱包
- // (new LedgerWalletModel())->insertGetId([
- // 'user_id' => $newUserID,
- // ]);
- //
- // // 创建网体
- // (new UserPathModel())->createPath($newUserID, $parent_user['id']);
- //
- // $i++;
- //
- // }
- dump($i);
- dump($j);
- }
- public function updaetWallet()
- {
- $daoru_list = Db::table('ledger_wallet_1')
- ->whereNotNull('address')
- ->select();
- $i = 0;
- foreach ($daoru_list as $key => $info) {
- dump($info);
- $user = (new UserModel())->getByAddress($info['address']);
- if (empty($user)) {
- dump($info['user_id'] . ' - ' . $info['address'] . ' - 不存在');
- continue;
- }
- unset($info['user_id']);
- unset($info['address']);
- //更新钱包
- $is_up = (new LedgerWalletModel())
- ->where('user_id', $user['id'])
- ->update($info);
- dump($user['id'] . '更新' . $is_up);
- $i++;
- }
- dump($i);
- }
- /**
- * 手段向某会员报单算力
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function updateOrder()
- {
- //算力租赁订单处理
- // 查询兑换比例
- $usdtToPower = (new ParametersModel)->getValue('usdtToPowerRate');
- $usdtToPowerFloat = floatval($usdtToPower);
- if (is_null($usdtToPower) || $usdtToPowerFloat <= 0) {
- return '获取USDT兑换算力的比例失败';
- }
- $orderInfo = (new OfflineRechargeRecordModel())
- ->where('id', 4)
- ->find();
- if(empty($orderInfo)){
- halt('订单信息不存在');
- }
- $uid = $orderInfo['user_id'];
- $fee = $orderInfo['amount'];
- $power = bcmul($fee, $usdtToPowerFloat, 6); // 该用户兑得的算力
- // 启动事务
- Db::startTrans();
- try {
- // 更新总算力和账变
- (new LedgerWalletModel)->changeWalletAccount($uid, Asset::POWER, $power, Action::PowerRentalPower, $orderInfo['id']);
- // 更新服务器算力,不账变
- (new LedgerWalletModel)->changeWalletOnly($uid, Asset::RENTAL_POWER, $power);
- // 更新自己(有效会员时间)和所有上级的信息(有效直推人数和团队总算力)
- (new UserModel())->updateForRental($uid, $power);
- // 发放直推USDT收益
- (new LedgerWalletModel)->sendUsdtProfit($uid, $fee);
- // 发放直推算力收益
- (new LedgerWalletModel)->sendDirectProfit($uid, $power);
- // 发代数收益
- (new LedgerWalletModel)->sendGenerateProfit($uid, $fee);
- // 发放见点奖
- (new LedgerWalletModel)->sendRegBonus($uid, $fee);
- // 更新购买(充值)记录
- (new OfflineRechargeRecordModel())->updateOrderStatus($orderInfo['id'], RechargeStatus::StatusAuthSuccess, 0, $power);
- // 提交事务
- Db::commit();
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- return $e->getMessage();
- }
- }
- //重算团队业绩和直推人数
- public function reset_team()
- {
- set_time_limit(0);
- //先清空
- $update = Db::table('user')
- ->where('id', '>', 0)
- ->update([
- 'team_power' => 0,
- 'team_num' => 0,
- 'direct_num' => 0
- ]);
- $up_power = Db::table('ledger_wallet')
- ->field('u.id')
- ->alias('w')
- ->join('user u', 'w.user_id = u.id')
- ->where('u.effective_time','>',0)
- ->where('w.rental_power', 0)
- ->select();
- foreach ($up_power as $item){
- $update = Db::table('ledger_wallet')
- ->where('user_id', $item['id'])
- ->update([
- 'rental_power' => 0.01
- ]);
- }
- $power_list = Db::table('ledger_wallet')
- ->where('rental_power', '>', 0)
- ->select();
- $info_list = 0;
- $bad_list = [];
- foreach ($power_list as $key => $info) {
- dump('正在处理ID:' . $info['user_id']);
- $parent_ids = (new UserPathModel())
- ->where('user_id',$info['user_id'])
- ->order('distance')
- ->select();
- foreach ($parent_ids as $item) {
- $data = [
- 'team_power' => Db::raw('team_power + ' . $info['rental_power']),
- 'team_num' => Db::raw('team_num + 1'),
- ];
- if ($item['distance'] == 1) {
- $data['direct_num'] = Db::raw('direct_num+1');
- }
- $update = Db::table('user')
- ->where('id', $item['parent_id'])
- ->update($data);
- if (!$update) {
- $bad_list[] = $info;
- } else {
- $info_list++;
- }
- }
- }
- dump('成功数量');
- dump($info_list);
- dump('失败数量');
- dump($bad_list);
- }
- //累加新增团队业绩
- public function addTeamPower()
- {
- set_time_limit(0);
- $uid = 100702;
- $num = 1429;
- $parentIDs = (new UserPathModel())->getAllParentIDs($uid);
- $parentIDs[] = $uid;
- dump($parentIDs, true, 'ID列表');
- $update = (new UserModel())
- ->where('id', 'in', $parentIDs)
- ->update([
- 'team_power' => Db::raw('team_power + ' . $num)
- ]);
- dump($update, true, '影响行数');
- }
- public function resetUserPath()
- {
- $ratio = 0.05;//直推奖励
- $info_list = (new OfflineRechargeRecordModel())
- ->where('status', OfflineRechargeRecordModel::StatusFail)
- ->order('id', 'ASC')
- ->select();
- dump('本次数据共有:' . count($info_list));
- foreach ($info_list as $info) {
- $user = (new UserModel())->get($info['user_id']);
- if (empty($user) || $user['parent_id'] == 0) {
- continue;
- }
- $check = (new LedgerUsdtChangeModel())
- ->where('user_id', $user['parent_id'])
- ->where('action', Action::UsdtShareBonus)
- ->where('from_id', $info['user_id'])
- ->count();
- if($check == 0){
- (new LedgerWalletModel())->changeWalletAccount($user['parent_id'], Asset::USDT, $info['amount'] * $ratio, Action::UsdtShareBonus, $info['user_id']);
- dump('订单ID:' . $info['id'] . '处理成功,奖金:' . $info['amount'] * $ratio);
- }else{
- dump('订单ID:' . $info['id'] . '处理失败,奖金已存在');
- }
- }
- }
- /**
- * 补发直推奖
- * @return void
- */
- public function resetShareBonus()
- {
- $users = (new UserModel())->order('id', 'ASC')->select();
- foreach ($users as $v) {
- (new UserPathModel())->createPath($v['id'], $v['parent_id']);
- }
- }
- /**
- * @return string
- *
- * 返回结果
- * {
- "status": "1",
- "message": "OK",
- "result": {
- "status": "1"
- }
- }
- */
- public function getStatusByHaxh()
- {
- $url = "https://api.bscscan.com/api?module=transaction&action=gettxreceiptstatus&txhash=0x30f4190a8237c7744a0981a2895728bab93acf4cb78b03c192ed5ac387405c54&apikey=VTCKIP346DCRWB6JNS4KDANUJJEQN9VAKW";
- $body = Http::get($url);
- if (empty($body)) {
- return "api返回内容为空";
- }
- dump($body);
- // 转成数组
- $rsArr = json_decode($body, true);
- dump($rsArr);
- if (empty($rsArr) || !is_array($rsArr)) {
- return "状态api返回数据异常";
- }
- if ($rsArr['status'] != '1') {
- return '状态api返回status不为1,错误信息:' . $rsArr['message'];
- }
- if ($rsArr['result']['status'] != 1) {
- return '状态api返回result中的status不为1,错误信息:' . $rsArr['message'];
- }
- }
- public function AllocateEtc()
- {
- $url = "https://www.binance.com/api/v1/klines?symbol=ETCUSDT&limit=1&interval=3m";
- $body = Http::get($url);
- if (empty($body)) {
- return "api返回内容为空";
- }
- dump($body);
- // 转成数组
- $rsArr = json_decode($body, true);
- dump($rsArr[0][2]);
- $body = Http::get($url);
- if (empty($body)) {
- return "api返回内容为空";
- }
- dump($body);
- // 转成数组
- $rsArr = json_decode($body, true);
- dump($rsArr);
- if (empty($rsArr) || !is_array($rsArr)) {
- return "状态api返回数据异常";
- }
- if ($rsArr['status'] != '1') {
- return '状态api返回status不为1,错误信息:' . $rsArr['message'];
- }
- if ($rsArr['result']['status'] != 1) {
- return '状态api返回result中的status不为1,错误信息:' . $rsArr['message'];
- }
- }
- public function debug()
- {
- $num =rand(9000,10000);
- dump($num/10000/1000);
- $body = (new MyBscApi())->getInfoByTransactionHash('0xc3fc59faa9a1a9ff4fa1516b7df10570876a87993c397f6cd33ce3446641b5b0');
- dump($body);
- }
- }
|