Test.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\logic\BscApi;
  4. use app\common\logic\MyBscApi;
  5. use app\common\logic\TeamRewards;
  6. use app\common\model\AnnouncementModel;
  7. use app\common\model\LedgerSmhChangeModel;
  8. use app\common\model\LedgerUsdtChangeModel;
  9. use app\common\model\OfflineRechargeRecordModel;
  10. use app\api\logic\MarketLogic;
  11. use app\common\model\ParametersModel;
  12. use app\common\model\ProductOrder;
  13. use app\common\model\UserModel;
  14. use app\common\model\UserPathModel;
  15. use app\common\model\LedgerWalletModel;
  16. use app\common\model\ProductTransfer;
  17. use fast\Action;
  18. use fast\Asset;
  19. use fast\Http;
  20. use fast\RechargeStatus;
  21. use think\Db;
  22. use think\Log;
  23. use think\Model;
  24. class Test
  25. {
  26. //取消寄售
  27. public function copy_user(ProductTransfer $productTransfer, ProductOrder $productOrder, MarketLogic $marketLogic)
  28. {
  29. $list = $productTransfer::where('status', ProductTransfer::Normal)->where('order_no', '')->select();
  30. $i = 0;
  31. foreach ($list as $item) {
  32. $check_pro = $productOrder
  33. ->where('id', $item['order_id'])
  34. ->find();
  35. if (!empty($check_pro)) {
  36. if($check_pro['type_id'] == 1 && $check_pro['status'] == 2){
  37. $i++;
  38. //取消转让订单
  39. $productOrder->where('id', $item['order_id'])->update(['status'=> 1]);
  40. //修改:类型状态
  41. $item->status = 0;
  42. $item->save();
  43. }else{
  44. dump('订单:' . $item['order_id'] . '的type_id为:' . $check_pro['type_id'] . ',status为:' . $check_pro['status']);
  45. }
  46. }else{
  47. dump('订单:' . $item['order_id'] . '无此订单');
  48. }
  49. }
  50. dump('完成了' . $i . '个订单');
  51. }
  52. /*
  53. * 更新上级
  54. */
  55. public function change_parent()
  56. {
  57. //1.从主表复制到备份表,需手动插入上级信息
  58. // dump('从主表复制到备份表');
  59. // $user_list = Db::name('user')
  60. // ->fetchSql(false)
  61. // ->field('u.*,p.distance')
  62. // ->alias('u')
  63. // ->join('user_path p', 'u.id = p.user_id')
  64. // ->where('p.parent_id', 101985)
  65. // //->where('u.id','>', 103931)
  66. // ->select();
  67. //
  68. // $i = 0;
  69. // foreach ($user_list as $user){
  70. // $is = Db::table('user_1')
  71. // ->insert($user);
  72. // $i++;
  73. // }
  74. // halt($i);
  75. //*2.更新备份表上级地址
  76. // dump('更新上级地址');
  77. // $user_list = Db::name('user_1')
  78. // ->whereNull('parent_address')
  79. // ->select();
  80. // $i = 0;
  81. // foreach ($user_list as $user){
  82. // $parent_info = (new UserModel())
  83. // ->where('id', $user['parent_id'])
  84. // ->find();
  85. // if(!empty($parent_info)){
  86. // $is = Db::table('user_1')
  87. // ->where('id', $user['id'])
  88. // ->update([
  89. // 'parent_address' => $parent_info['address']
  90. // ]);
  91. // $i++;
  92. // }
  93. // }
  94. // halt($i);
  95. //3.更新主表会员上级
  96. dump('重建网体');
  97. $user_list = Db::table('user_1')
  98. ->order('distance')
  99. ->select();
  100. $i = 0;
  101. foreach ($user_list as $user){
  102. $parent_info = (new UserModel())
  103. ->where('address', $user['parent_address'])
  104. ->find();
  105. if(!empty($parent_info)){
  106. $is = Db::table('user')
  107. ->where('id', $user['id'])
  108. ->update([
  109. 'parent_id' => $parent_info['id']
  110. ]);
  111. //删除网体
  112. (new UserPathModel())
  113. ->where('user_id', $user['id'])
  114. ->delete();
  115. // 创建网体
  116. (new UserPathModel())->createPath($user['id'], $parent_info['id']);
  117. $i++;
  118. } else{
  119. dump($user['id'] . '--无上级');
  120. }
  121. }
  122. halt($i);
  123. }
  124. /*
  125. * 更新上级
  126. *
  127. * 更改给定ID的上级,并把它的直推一并更改
  128. */
  129. public function resetParent()
  130. {
  131. //3.更新主表会员上级
  132. dump('重建网体');
  133. $parent_id = 100100;
  134. $user_id = 101134;
  135. $user = (new UserModel())
  136. ->fetchSql(false)
  137. ->where('id', $user_id)
  138. ->update([
  139. 'parent_id' => $parent_id
  140. ]);
  141. dump($user, true, '更新状态');
  142. //删除网体
  143. (new UserPathModel())
  144. ->where('user_id', $user_id)
  145. ->delete();
  146. // 创建网体
  147. (new UserPathModel())->createPath($user_id, $parent_id);
  148. $user_list = (new UserModel())
  149. ->where('parent_id', $user_id)
  150. ->select();
  151. $i = 0;
  152. foreach ($user_list as $user){
  153. //删除网体
  154. (new UserPathModel())
  155. ->where('user_id', $user['id'])
  156. ->delete();
  157. // 创建网体
  158. (new UserPathModel())->createPath($user['id'], $user['parent_id']);
  159. $i++;
  160. }
  161. halt($i);
  162. }
  163. /**
  164. 导入数据表生成 sql
  165. CREATE TABLE dao_ru AS SELECT
  166. u.id,
  167. u.parent_id,
  168. u.address,
  169. u.team_power,
  170. u.team_num,
  171. w.power,
  172. w.rental_power,
  173. w.usdt
  174. FROM
  175. `user` u
  176. LEFT JOIN ledger_wallet w ON u.id = w.user_id
  177. WHERE
  178. id IN ( SELECT user_id FROM `user_path` WHERE parent_id = 1012 )
  179. OR id = 1012
  180. ORDER BY
  181. id
  182. */
  183. public function daoru()
  184. {
  185. die;
  186. $daoru_list = Db::table('user_base')
  187. //->where('is_dao', 1)
  188. ->select();
  189. $i = 0;
  190. $j = 0;
  191. //重建钱包
  192. foreach ($daoru_list as $key => $info) {
  193. $user = (new UserModel())->getByAddress($info['address']);
  194. if (!empty($user)) { // 已存在
  195. // 更新总算力和账变
  196. (new LedgerWalletModel)->changeWalletAccount($user['id'], Asset::POWER, $info['power'], Action::Reversal, 0);
  197. // 更新自己(有效会员时间)和所有上级的信息(有效直推人数和团队总算力)
  198. (new UserModel())->updateForRental($user['id'], $info['power']);
  199. $j++;
  200. continue;
  201. }
  202. }
  203. //重建用户
  204. // foreach ($daoru_list as $key => $info) {
  205. //
  206. // $parent_user = (new UserModel())->getByAddress($info['parent_address']);
  207. // if(empty($parent_user)){
  208. // dump('没有上级');
  209. // dump($info);
  210. // continue;
  211. // }
  212. //
  213. // $user = (new UserModel())->getByAddress($info['address']);
  214. // if (!empty($user)) { // 已存在
  215. // dump($info['id'] . ' - ' . $info['address'] . ' - 已存在');
  216. //
  217. // $is = Db::table('user')
  218. // ->where('id', $user['id'])
  219. // ->update([
  220. // 'parent_id' => $parent_user['id']
  221. // ]);
  222. // $j++;
  223. // continue;
  224. // }
  225. //
  226. // unset($info['id']);
  227. // unset($info['parent_address']);
  228. // unset($info['is_dao']);
  229. // $info['parent_id'] = $parent_user['id'];
  230. // // 创建用户
  231. // $newUserID = (new UserModel())->insertGetId($info);
  232. // // 创建钱包
  233. // (new LedgerWalletModel())->insertGetId([
  234. // 'user_id' => $newUserID,
  235. // ]);
  236. //
  237. // // 创建网体
  238. // (new UserPathModel())->createPath($newUserID, $parent_user['id']);
  239. //
  240. // $i++;
  241. //
  242. // }
  243. dump($i);
  244. dump($j);
  245. }
  246. public function updaetWallet()
  247. {
  248. $daoru_list = Db::table('ledger_wallet_1')
  249. ->whereNotNull('address')
  250. ->select();
  251. $i = 0;
  252. foreach ($daoru_list as $key => $info) {
  253. dump($info);
  254. $user = (new UserModel())->getByAddress($info['address']);
  255. if (empty($user)) {
  256. dump($info['user_id'] . ' - ' . $info['address'] . ' - 不存在');
  257. continue;
  258. }
  259. unset($info['user_id']);
  260. unset($info['address']);
  261. //更新钱包
  262. $is_up = (new LedgerWalletModel())
  263. ->where('user_id', $user['id'])
  264. ->update($info);
  265. dump($user['id'] . '更新' . $is_up);
  266. $i++;
  267. }
  268. dump($i);
  269. }
  270. /**
  271. * 手段向某会员报单算力
  272. * @return void
  273. * @throws \think\db\exception\DataNotFoundException
  274. * @throws \think\db\exception\ModelNotFoundException
  275. * @throws \think\exception\DbException
  276. */
  277. public function updateOrder()
  278. {
  279. //算力租赁订单处理
  280. // 查询兑换比例
  281. $usdtToPower = (new ParametersModel)->getValue('usdtToPowerRate');
  282. $usdtToPowerFloat = floatval($usdtToPower);
  283. if (is_null($usdtToPower) || $usdtToPowerFloat <= 0) {
  284. return '获取USDT兑换算力的比例失败';
  285. }
  286. $orderInfo = (new OfflineRechargeRecordModel())
  287. ->where('id', 4)
  288. ->find();
  289. if(empty($orderInfo)){
  290. halt('订单信息不存在');
  291. }
  292. $uid = $orderInfo['user_id'];
  293. $fee = $orderInfo['amount'];
  294. $power = bcmul($fee, $usdtToPowerFloat, 6); // 该用户兑得的算力
  295. // 启动事务
  296. Db::startTrans();
  297. try {
  298. // 更新总算力和账变
  299. (new LedgerWalletModel)->changeWalletAccount($uid, Asset::POWER, $power, Action::PowerRentalPower, $orderInfo['id']);
  300. // 更新服务器算力,不账变
  301. (new LedgerWalletModel)->changeWalletOnly($uid, Asset::RENTAL_POWER, $power);
  302. // 更新自己(有效会员时间)和所有上级的信息(有效直推人数和团队总算力)
  303. (new UserModel())->updateForRental($uid, $power);
  304. // 发放直推USDT收益
  305. (new LedgerWalletModel)->sendUsdtProfit($uid, $fee);
  306. // 发放直推算力收益
  307. (new LedgerWalletModel)->sendDirectProfit($uid, $power);
  308. // 发代数收益
  309. (new LedgerWalletModel)->sendGenerateProfit($uid, $fee);
  310. // 发放见点奖
  311. (new LedgerWalletModel)->sendRegBonus($uid, $fee);
  312. // 更新购买(充值)记录
  313. (new OfflineRechargeRecordModel())->updateOrderStatus($orderInfo['id'], RechargeStatus::StatusAuthSuccess, 0, $power);
  314. // 提交事务
  315. Db::commit();
  316. } catch (Exception $e) {
  317. // 回滚事务
  318. Db::rollback();
  319. return $e->getMessage();
  320. }
  321. }
  322. //重算团队业绩和直推人数
  323. public function reset_team()
  324. {
  325. set_time_limit(0);
  326. //先清空
  327. $update = Db::table('user')
  328. ->where('id', '>', 0)
  329. ->update([
  330. 'team_power' => 0,
  331. 'team_num' => 0,
  332. 'direct_num' => 0
  333. ]);
  334. $up_power = Db::table('ledger_wallet')
  335. ->field('u.id')
  336. ->alias('w')
  337. ->join('user u', 'w.user_id = u.id')
  338. ->where('u.effective_time','>',0)
  339. ->where('w.rental_power', 0)
  340. ->select();
  341. foreach ($up_power as $item){
  342. $update = Db::table('ledger_wallet')
  343. ->where('user_id', $item['id'])
  344. ->update([
  345. 'rental_power' => 0.01
  346. ]);
  347. }
  348. $power_list = Db::table('ledger_wallet')
  349. ->where('rental_power', '>', 0)
  350. ->select();
  351. $info_list = 0;
  352. $bad_list = [];
  353. foreach ($power_list as $key => $info) {
  354. dump('正在处理ID:' . $info['user_id']);
  355. $parent_ids = (new UserPathModel())
  356. ->where('user_id',$info['user_id'])
  357. ->order('distance')
  358. ->select();
  359. foreach ($parent_ids as $item) {
  360. $data = [
  361. 'team_power' => Db::raw('team_power + ' . $info['rental_power']),
  362. 'team_num' => Db::raw('team_num + 1'),
  363. ];
  364. if ($item['distance'] == 1) {
  365. $data['direct_num'] = Db::raw('direct_num+1');
  366. }
  367. $update = Db::table('user')
  368. ->where('id', $item['parent_id'])
  369. ->update($data);
  370. if (!$update) {
  371. $bad_list[] = $info;
  372. } else {
  373. $info_list++;
  374. }
  375. }
  376. }
  377. dump('成功数量');
  378. dump($info_list);
  379. dump('失败数量');
  380. dump($bad_list);
  381. }
  382. //累加新增团队业绩
  383. public function addTeamPower()
  384. {
  385. set_time_limit(0);
  386. $uid = 100702;
  387. $num = 1429;
  388. $parentIDs = (new UserPathModel())->getAllParentIDs($uid);
  389. $parentIDs[] = $uid;
  390. dump($parentIDs, true, 'ID列表');
  391. $update = (new UserModel())
  392. ->where('id', 'in', $parentIDs)
  393. ->update([
  394. 'team_power' => Db::raw('team_power + ' . $num)
  395. ]);
  396. dump($update, true, '影响行数');
  397. }
  398. public function resetUserPath()
  399. {
  400. $ratio = 0.05;//直推奖励
  401. $info_list = (new OfflineRechargeRecordModel())
  402. ->where('status', OfflineRechargeRecordModel::StatusFail)
  403. ->order('id', 'ASC')
  404. ->select();
  405. dump('本次数据共有:' . count($info_list));
  406. foreach ($info_list as $info) {
  407. $user = (new UserModel())->get($info['user_id']);
  408. if (empty($user) || $user['parent_id'] == 0) {
  409. continue;
  410. }
  411. $check = (new LedgerUsdtChangeModel())
  412. ->where('user_id', $user['parent_id'])
  413. ->where('action', Action::UsdtShareBonus)
  414. ->where('from_id', $info['user_id'])
  415. ->count();
  416. if($check == 0){
  417. (new LedgerWalletModel())->changeWalletAccount($user['parent_id'], Asset::USDT, $info['amount'] * $ratio, Action::UsdtShareBonus, $info['user_id']);
  418. dump('订单ID:' . $info['id'] . '处理成功,奖金:' . $info['amount'] * $ratio);
  419. }else{
  420. dump('订单ID:' . $info['id'] . '处理失败,奖金已存在');
  421. }
  422. }
  423. }
  424. /**
  425. * 补发直推奖
  426. * @return void
  427. */
  428. public function resetShareBonus()
  429. {
  430. $users = (new UserModel())->order('id', 'ASC')->select();
  431. foreach ($users as $v) {
  432. (new UserPathModel())->createPath($v['id'], $v['parent_id']);
  433. }
  434. }
  435. /**
  436. * @return string
  437. *
  438. * 返回结果
  439. * {
  440. "status": "1",
  441. "message": "OK",
  442. "result": {
  443. "status": "1"
  444. }
  445. }
  446. */
  447. public function getStatusByHaxh()
  448. {
  449. $url = "https://api.bscscan.com/api?module=transaction&action=gettxreceiptstatus&txhash=0x30f4190a8237c7744a0981a2895728bab93acf4cb78b03c192ed5ac387405c54&apikey=VTCKIP346DCRWB6JNS4KDANUJJEQN9VAKW";
  450. $body = Http::get($url);
  451. if (empty($body)) {
  452. return "api返回内容为空";
  453. }
  454. dump($body);
  455. // 转成数组
  456. $rsArr = json_decode($body, true);
  457. dump($rsArr);
  458. if (empty($rsArr) || !is_array($rsArr)) {
  459. return "状态api返回数据异常";
  460. }
  461. if ($rsArr['status'] != '1') {
  462. return '状态api返回status不为1,错误信息:' . $rsArr['message'];
  463. }
  464. if ($rsArr['result']['status'] != 1) {
  465. return '状态api返回result中的status不为1,错误信息:' . $rsArr['message'];
  466. }
  467. }
  468. public function AllocateEtc()
  469. {
  470. $url = "https://www.binance.com/api/v1/klines?symbol=ETCUSDT&limit=1&interval=3m";
  471. $body = Http::get($url);
  472. if (empty($body)) {
  473. return "api返回内容为空";
  474. }
  475. dump($body);
  476. // 转成数组
  477. $rsArr = json_decode($body, true);
  478. dump($rsArr[0][2]);
  479. $body = Http::get($url);
  480. if (empty($body)) {
  481. return "api返回内容为空";
  482. }
  483. dump($body);
  484. // 转成数组
  485. $rsArr = json_decode($body, true);
  486. dump($rsArr);
  487. if (empty($rsArr) || !is_array($rsArr)) {
  488. return "状态api返回数据异常";
  489. }
  490. if ($rsArr['status'] != '1') {
  491. return '状态api返回status不为1,错误信息:' . $rsArr['message'];
  492. }
  493. if ($rsArr['result']['status'] != 1) {
  494. return '状态api返回result中的status不为1,错误信息:' . $rsArr['message'];
  495. }
  496. }
  497. public function debug()
  498. {
  499. $num =rand(9000,10000);
  500. dump($num/10000/1000);
  501. $body = (new MyBscApi())->getInfoByTransactionHash('0xc3fc59faa9a1a9ff4fa1516b7df10570876a87993c397f6cd33ce3446641b5b0');
  502. dump($body);
  503. }
  504. public function resetAirdrop()
  505. {
  506. $order_list = (new ProductOrder())
  507. ->where('type_id', 3)
  508. ->group('user_id')
  509. ->column('user_id');
  510. dump($order_list);
  511. $order_list_send = (new ProductOrder())
  512. ->where('type_id', 4)
  513. ->group('user_id')
  514. ->column('user_id');
  515. dump($order_list_send);
  516. $order_list = array_diff($order_list, $order_list_send);
  517. dump($order_list);
  518. $rs = (new ProductOrder())
  519. ->where('type_id', 3)
  520. ->where('user_id', 'in', $order_list)
  521. ->update([
  522. 'create_time' => 1745942400
  523. ]);
  524. dump($rs);
  525. }
  526. public function updateNews()
  527. {
  528. $en_news = DB::name('announcement_cope')->select();
  529. foreach ($en_news as $info) {
  530. if(strlen($info['en_title']) > 3){
  531. $rs = (new AnnouncementModel())
  532. ->save([
  533. 'type_id' => $info['type_id'],
  534. 'title' => $info['en_body'],
  535. 'introduction' => $info['en_introduction'],
  536. 'body' => $info['en_body'],
  537. 'img_url' => $info['img_url'],
  538. 'to_lang' => 1,
  539. 'status' => $info['status'],
  540. 'created_by' => $info['created_by'],
  541. 'createtime' => $info['createtime'],
  542. ]);
  543. }
  544. }
  545. dump($rs);
  546. }
  547. }