Test.php 19 KB

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