Test.php 18 KB

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