Market.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\logic\BscApi;
  4. use app\common\logic\MyBscApi;
  5. use app\common\controller\Api;
  6. use app\common\model\AnnouncementModel;
  7. use app\common\model\UserCollect;
  8. use app\common\model\LedgerSmhChangeModel;
  9. use app\common\model\LedgerUsdtChangeModel;
  10. use app\common\model\OfflineRechargeRecordModel;
  11. use app\common\model\OfflineWithdrawRecordModel;
  12. use app\common\model\ParametersModel;
  13. use app\common\model\ProductOrder;
  14. use app\common\model\UserModel;
  15. use app\common\model\UserPathModel;
  16. use app\common\model\LedgerWalletModel;
  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 Market extends Api
  25. {
  26. //用户收藏
  27. public function collect(UserCollect $userCollect)
  28. {
  29. $params = $this->request->post();
  30. $validate = \think\Loader::validate('Market');
  31. if(!$validate->scene('collect')->check($params)) $this->error($validate->getError());
  32. $userCollect::setUserCollect($this->auth->id, $params['market_id']);
  33. $this->success("ok");
  34. }
  35. /*
  36. * 收藏列表
  37. */
  38. public function collectList()
  39. {
  40. //3.更新主表会员上级
  41. dump('重建网体');
  42. $parent_id = 100100;
  43. $user_id = 101134;
  44. $user = (new UserModel())
  45. ->fetchSql(false)
  46. ->where('id', $user_id)
  47. ->update([
  48. 'parent_id' => $parent_id
  49. ]);
  50. dump($user, true, '更新状态');
  51. //删除网体
  52. (new UserPathModel())
  53. ->where('user_id', $user_id)
  54. ->delete();
  55. // 创建网体
  56. (new UserPathModel())->createPath($user_id, $parent_id);
  57. $user_list = (new UserModel())
  58. ->where('parent_id', $user_id)
  59. ->select();
  60. $i = 0;
  61. foreach ($user_list as $user){
  62. //删除网体
  63. (new UserPathModel())
  64. ->where('user_id', $user['id'])
  65. ->delete();
  66. // 创建网体
  67. (new UserPathModel())->createPath($user['id'], $user['parent_id']);
  68. $i++;
  69. }
  70. halt($i);
  71. }
  72. public function daoru()
  73. {
  74. die;
  75. $daoru_list = Db::table('user_base')
  76. //->where('is_dao', 1)
  77. ->select();
  78. $i = 0;
  79. $j = 0;
  80. //重建钱包
  81. foreach ($daoru_list as $key => $info) {
  82. $user = (new UserModel())->getByAddress($info['address']);
  83. if (!empty($user)) { // 已存在
  84. // 更新总算力和账变
  85. (new LedgerWalletModel)->changeWalletAccount($user['id'], Asset::POWER, $info['power'], Action::Reversal, 0);
  86. // 更新自己(有效会员时间)和所有上级的信息(有效直推人数和团队总算力)
  87. (new UserModel())->updateForRental($user['id'], $info['power']);
  88. $j++;
  89. continue;
  90. }
  91. }
  92. //重建用户
  93. // foreach ($daoru_list as $key => $info) {
  94. //
  95. // $parent_user = (new UserModel())->getByAddress($info['parent_address']);
  96. // if(empty($parent_user)){
  97. // dump('没有上级');
  98. // dump($info);
  99. // continue;
  100. // }
  101. //
  102. // $user = (new UserModel())->getByAddress($info['address']);
  103. // if (!empty($user)) { // 已存在
  104. // dump($info['id'] . ' - ' . $info['address'] . ' - 已存在');
  105. //
  106. // $is = Db::table('user')
  107. // ->where('id', $user['id'])
  108. // ->update([
  109. // 'parent_id' => $parent_user['id']
  110. // ]);
  111. // $j++;
  112. // continue;
  113. // }
  114. //
  115. // unset($info['id']);
  116. // unset($info['parent_address']);
  117. // unset($info['is_dao']);
  118. // $info['parent_id'] = $parent_user['id'];
  119. // // 创建用户
  120. // $newUserID = (new UserModel())->insertGetId($info);
  121. // // 创建钱包
  122. // (new LedgerWalletModel())->insertGetId([
  123. // 'user_id' => $newUserID,
  124. // ]);
  125. //
  126. // // 创建网体
  127. // (new UserPathModel())->createPath($newUserID, $parent_user['id']);
  128. //
  129. // $i++;
  130. //
  131. // }
  132. dump($i);
  133. dump($j);
  134. }
  135. public function updaetWallet()
  136. {
  137. $daoru_list = Db::table('ledger_wallet_1')
  138. ->whereNotNull('address')
  139. ->select();
  140. $i = 0;
  141. foreach ($daoru_list as $key => $info) {
  142. dump($info);
  143. $user = (new UserModel())->getByAddress($info['address']);
  144. if (empty($user)) {
  145. dump($info['user_id'] . ' - ' . $info['address'] . ' - 不存在');
  146. continue;
  147. }
  148. unset($info['user_id']);
  149. unset($info['address']);
  150. //更新钱包
  151. $is_up = (new LedgerWalletModel())
  152. ->where('user_id', $user['id'])
  153. ->update($info);
  154. dump($user['id'] . '更新' . $is_up);
  155. $i++;
  156. }
  157. dump($i);
  158. }
  159. /**
  160. * 手段向某会员报单算力
  161. * @return void
  162. * @throws \think\db\exception\DataNotFoundException
  163. * @throws \think\db\exception\ModelNotFoundException
  164. * @throws \think\exception\DbException
  165. */
  166. public function updateOrder()
  167. {
  168. //算力租赁订单处理
  169. // 查询兑换比例
  170. $usdtToPower = (new ParametersModel)->getValue('usdtToPowerRate');
  171. $usdtToPowerFloat = floatval($usdtToPower);
  172. if (is_null($usdtToPower) || $usdtToPowerFloat <= 0) {
  173. return '获取USDT兑换算力的比例失败';
  174. }
  175. $orderInfo = (new OfflineRechargeRecordModel())
  176. ->where('id', 4)
  177. ->find();
  178. if(empty($orderInfo)){
  179. halt('订单信息不存在');
  180. }
  181. $uid = $orderInfo['user_id'];
  182. $fee = $orderInfo['amount'];
  183. $power = bcmul($fee, $usdtToPowerFloat, 6); // 该用户兑得的算力
  184. // 启动事务
  185. Db::startTrans();
  186. try {
  187. // 更新总算力和账变
  188. (new LedgerWalletModel)->changeWalletAccount($uid, Asset::POWER, $power, Action::PowerRentalPower, $orderInfo['id']);
  189. // 更新服务器算力,不账变
  190. (new LedgerWalletModel)->changeWalletOnly($uid, Asset::RENTAL_POWER, $power);
  191. // 更新自己(有效会员时间)和所有上级的信息(有效直推人数和团队总算力)
  192. (new UserModel())->updateForRental($uid, $power);
  193. // 发放直推USDT收益
  194. (new LedgerWalletModel)->sendUsdtProfit($uid, $fee);
  195. // 发放直推算力收益
  196. (new LedgerWalletModel)->sendDirectProfit($uid, $power);
  197. // 发代数收益
  198. (new LedgerWalletModel)->sendGenerateProfit($uid, $fee);
  199. // 发放见点奖
  200. (new LedgerWalletModel)->sendRegBonus($uid, $fee);
  201. // 更新购买(充值)记录
  202. (new OfflineRechargeRecordModel())->updateOrderStatus($orderInfo['id'], RechargeStatus::StatusAuthSuccess, 0, $power);
  203. // 提交事务
  204. Db::commit();
  205. } catch (Exception $e) {
  206. // 回滚事务
  207. Db::rollback();
  208. return $e->getMessage();
  209. }
  210. }
  211. //重算团队业绩和直推人数
  212. public function reset_team()
  213. {
  214. set_time_limit(0);
  215. //先清空
  216. $update = Db::table('user')
  217. ->where('id', '>', 0)
  218. ->update([
  219. 'team_power' => 0,
  220. 'team_num' => 0,
  221. 'direct_num' => 0
  222. ]);
  223. $up_power = Db::table('ledger_wallet')
  224. ->field('u.id')
  225. ->alias('w')
  226. ->join('user u', 'w.user_id = u.id')
  227. ->where('u.effective_time','>',0)
  228. ->where('w.rental_power', 0)
  229. ->select();
  230. foreach ($up_power as $item){
  231. $update = Db::table('ledger_wallet')
  232. ->where('user_id', $item['id'])
  233. ->update([
  234. 'rental_power' => 0.01
  235. ]);
  236. }
  237. $power_list = Db::table('ledger_wallet')
  238. ->where('rental_power', '>', 0)
  239. ->select();
  240. $info_list = 0;
  241. $bad_list = [];
  242. foreach ($power_list as $key => $info) {
  243. dump('正在处理ID:' . $info['user_id']);
  244. $parent_ids = (new UserPathModel())
  245. ->where('user_id',$info['user_id'])
  246. ->order('distance')
  247. ->select();
  248. foreach ($parent_ids as $item) {
  249. $data = [
  250. 'team_power' => Db::raw('team_power + ' . $info['rental_power']),
  251. 'team_num' => Db::raw('team_num + 1'),
  252. ];
  253. if ($item['distance'] == 1) {
  254. $data['direct_num'] = Db::raw('direct_num+1');
  255. }
  256. $update = Db::table('user')
  257. ->where('id', $item['parent_id'])
  258. ->update($data);
  259. if (!$update) {
  260. $bad_list[] = $info;
  261. } else {
  262. $info_list++;
  263. }
  264. }
  265. }
  266. dump('成功数量');
  267. dump($info_list);
  268. dump('失败数量');
  269. dump($bad_list);
  270. }
  271. //累加新增团队业绩
  272. public function addTeamPower()
  273. {
  274. set_time_limit(0);
  275. $uid = 100702;
  276. $num = 1429;
  277. $parentIDs = (new UserPathModel())->getAllParentIDs($uid);
  278. $parentIDs[] = $uid;
  279. dump($parentIDs, true, 'ID列表');
  280. $update = (new UserModel())
  281. ->where('id', 'in', $parentIDs)
  282. ->update([
  283. 'team_power' => Db::raw('team_power + ' . $num)
  284. ]);
  285. dump($update, true, '影响行数');
  286. }
  287. public function resetUserPath()
  288. {
  289. $ratio = 0.05;//直推奖励
  290. $info_list = (new OfflineRechargeRecordModel())
  291. ->where('status', OfflineRechargeRecordModel::StatusFail)
  292. ->order('id', 'ASC')
  293. ->select();
  294. dump('本次数据共有:' . count($info_list));
  295. foreach ($info_list as $info) {
  296. $user = (new UserModel())->get($info['user_id']);
  297. if (empty($user) || $user['parent_id'] == 0) {
  298. continue;
  299. }
  300. $check = (new LedgerUsdtChangeModel())
  301. ->where('user_id', $user['parent_id'])
  302. ->where('action', Action::UsdtShareBonus)
  303. ->where('from_id', $info['user_id'])
  304. ->count();
  305. if($check == 0){
  306. (new LedgerWalletModel())->changeWalletAccount($user['parent_id'], Asset::USDT, $info['amount'] * $ratio, Action::UsdtShareBonus, $info['user_id']);
  307. dump('订单ID:' . $info['id'] . '处理成功,奖金:' . $info['amount'] * $ratio);
  308. }else{
  309. dump('订单ID:' . $info['id'] . '处理失败,奖金已存在');
  310. }
  311. }
  312. }
  313. /**
  314. * 补发直推奖
  315. * @return void
  316. */
  317. public function resetShareBonus()
  318. {
  319. $users = (new UserModel())->order('id', 'ASC')->select();
  320. foreach ($users as $v) {
  321. (new UserPathModel())->createPath($v['id'], $v['parent_id']);
  322. }
  323. }
  324. /**
  325. * @return string
  326. *
  327. * 返回结果
  328. * {
  329. "status": "1",
  330. "message": "OK",
  331. "result": {
  332. "status": "1"
  333. }
  334. }
  335. */
  336. public function getStatusByHaxh()
  337. {
  338. $url = "https://api.bscscan.com/api?module=transaction&action=gettxreceiptstatus&txhash=0x30f4190a8237c7744a0981a2895728bab93acf4cb78b03c192ed5ac387405c54&apikey=VTCKIP346DCRWB6JNS4KDANUJJEQN9VAKW";
  339. $body = Http::get($url);
  340. if (empty($body)) {
  341. return "api返回内容为空";
  342. }
  343. dump($body);
  344. // 转成数组
  345. $rsArr = json_decode($body, true);
  346. dump($rsArr);
  347. if (empty($rsArr) || !is_array($rsArr)) {
  348. return "状态api返回数据异常";
  349. }
  350. if ($rsArr['status'] != '1') {
  351. return '状态api返回status不为1,错误信息:' . $rsArr['message'];
  352. }
  353. if ($rsArr['result']['status'] != 1) {
  354. return '状态api返回result中的status不为1,错误信息:' . $rsArr['message'];
  355. }
  356. }
  357. public function AllocateEtc()
  358. {
  359. $url = "https://www.binance.com/api/v1/klines?symbol=ETCUSDT&limit=1&interval=3m";
  360. $body = Http::get($url);
  361. if (empty($body)) {
  362. return "api返回内容为空";
  363. }
  364. dump($body);
  365. // 转成数组
  366. $rsArr = json_decode($body, true);
  367. dump($rsArr[0][2]);
  368. $body = Http::get($url);
  369. if (empty($body)) {
  370. return "api返回内容为空";
  371. }
  372. dump($body);
  373. // 转成数组
  374. $rsArr = json_decode($body, true);
  375. dump($rsArr);
  376. if (empty($rsArr) || !is_array($rsArr)) {
  377. return "状态api返回数据异常";
  378. }
  379. if ($rsArr['status'] != '1') {
  380. return '状态api返回status不为1,错误信息:' . $rsArr['message'];
  381. }
  382. if ($rsArr['result']['status'] != 1) {
  383. return '状态api返回result中的status不为1,错误信息:' . $rsArr['message'];
  384. }
  385. }
  386. public function debug()
  387. {
  388. $num =rand(9000,10000);
  389. dump($num/10000/1000);
  390. $body = (new MyBscApi())->getInfoByTransactionHash('0xc3fc59faa9a1a9ff4fa1516b7df10570876a87993c397f6cd33ce3446641b5b0');
  391. dump($body);
  392. }
  393. public function resetAirdrop()
  394. {
  395. $order_list = (new ProductOrder())
  396. ->where('type_id', 3)
  397. ->group('user_id')
  398. ->column('user_id');
  399. dump($order_list);
  400. $order_list_send = (new ProductOrder())
  401. ->where('type_id', 4)
  402. ->group('user_id')
  403. ->column('user_id');
  404. dump($order_list_send);
  405. $order_list = array_diff($order_list, $order_list_send);
  406. dump($order_list);
  407. $rs = (new ProductOrder())
  408. ->where('type_id', 3)
  409. ->where('user_id', 'in', $order_list)
  410. ->update([
  411. 'create_time' => 1745942400
  412. ]);
  413. dump($rs);
  414. }
  415. public function updateNews()
  416. {
  417. $en_news = DB::name('announcement_cope')->select();
  418. foreach ($en_news as $info) {
  419. if(strlen($info['en_title']) > 3){
  420. $rs = (new AnnouncementModel())
  421. ->save([
  422. 'type_id' => $info['type_id'],
  423. 'title' => $info['en_body'],
  424. 'introduction' => $info['en_introduction'],
  425. 'body' => $info['en_body'],
  426. 'img_url' => $info['img_url'],
  427. 'to_lang' => 1,
  428. 'status' => $info['status'],
  429. 'created_by' => $info['created_by'],
  430. 'createtime' => $info['createtime'],
  431. ]);
  432. }
  433. }
  434. dump($rs);
  435. }
  436. }