WithdrawService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. <?php
  2. namespace App\Services;
  3. use App\Constants\HttpStatus;
  4. use App\Constants\StepStatus;
  5. use App\Models\Address;
  6. use App\Models\BalanceLog;
  7. use App\Models\Bank;
  8. use App\Models\Config;
  9. use App\Models\RoomUser;
  10. use App\Models\User;
  11. use App\Models\Wallet;
  12. use App\Models\Withdraw;
  13. use Exception;
  14. use Illuminate\Support\Facades\Cache;
  15. use LaravelLang\Publisher\Console\Add;
  16. use Telegram\Bot\Api;
  17. use Telegram\Bot\Exceptions\TelegramSDKException;
  18. class WithdrawService
  19. {
  20. private $serviceCharge;
  21. public static function init(Api $telegram, $data, $chatId, $firstName, $messageId): void
  22. {
  23. switch ($data) {
  24. case "withdraw@@address"://地址管理
  25. $res = WithdrawService::getAddress($chatId, $messageId);
  26. $telegram->editMessageText($res);
  27. break;
  28. case "withdrawAddress@@done":
  29. $res = WithdrawService::done($chatId, $messageId, $firstName);
  30. $telegram->editMessageText($res);
  31. break;
  32. case "withdraw@@bill"://点击提现的账单按钮
  33. $res = WithdrawService::bill($chatId, $firstName, $messageId);
  34. $telegram->editMessageText($res);
  35. break;
  36. case "withdrawAddress@@add":
  37. $res = WithdrawService::addAddress($chatId, $messageId);
  38. $telegram->editMessageText($res);
  39. break;
  40. case "withdraw@@apply"://点击提现按钮
  41. $res = WithdrawService::apply($chatId, $messageId);
  42. $telegram->editMessageText($res);
  43. break;
  44. default:
  45. //选择提现地址
  46. $pattern = "/^withdrawAddress@@choose\d+$/";
  47. if (preg_match($pattern, $data)) {
  48. $id = preg_replace('/^withdrawAddress@@choose/', '', $data);
  49. $res = WithdrawService::chooseAddress($chatId, $firstName, $messageId, $id);
  50. $telegram->editMessageText($res);
  51. }
  52. //删除地址
  53. $pattern = "/^withdrawAddress@@del\d+$/";
  54. if (preg_match($pattern, $data)) {
  55. $id = preg_replace('/^withdrawAddress@@del/', '', $data);
  56. $res = WithdrawService::delAddress($chatId, $id, $messageId);
  57. $telegram->editMessageText($res);
  58. }
  59. //地址详情
  60. $pattern = "/^withdrawAddress@@detail\d+$/";
  61. if (preg_match($pattern, $data)) {
  62. $id = preg_replace('/^withdrawAddress@@detail/', '', $data);
  63. $res = WithdrawService::addressDetails($chatId, $messageId, $id);
  64. $telegram->editMessageText($res);
  65. }
  66. //提现账单,下一页
  67. $pattern = "/^withdrawBillNextPage@@\d+$/";
  68. if (preg_match($pattern, $data)) {
  69. $page = preg_replace('/^withdrawBillNextPage@@/', '', $data);
  70. $page = intval($page);
  71. $res = WithdrawService::bill($chatId, $firstName, $messageId, $page);
  72. $telegram->editMessageText($res);
  73. }
  74. break;
  75. }
  76. }
  77. public static function onMessage($chatId, $text, $messageId, $stepStatus)
  78. {
  79. switch ($stepStatus) {
  80. case StepStatus::INPUT_WITHDRAW_MONEY:
  81. $res = WithdrawService::inputAmount($chatId, $text, $messageId);
  82. $res = $res[0];
  83. break;
  84. case StepStatus::INPUT_ADDRESS_TRC20:
  85. $res = WithdrawService::inputAddress($chatId, $text, $messageId);
  86. break;
  87. case StepStatus::INPUT_ADDRESS_ALIAS:
  88. $res = WithdrawService::inputAlias($chatId, $text, $messageId);
  89. break;
  90. default:
  91. $res = null;
  92. break;
  93. }
  94. return $res;
  95. }
  96. public static function model(): string
  97. {
  98. return Withdraw::class;
  99. }
  100. public static function enum(): string
  101. {
  102. return '';
  103. }
  104. public static function getWhere(array $search = []): array
  105. {
  106. $where = [];
  107. if (isset($search['id']) && !empty($search['id'])) {
  108. $where[] = ['id', '=', $search['id']];
  109. }
  110. if (isset($search['member_id']) && !empty($search['member_id'])) {
  111. $where[] = ['member_id', '=', $search['member_id']];
  112. }
  113. if (isset($search['status']) && $search['status'] != '') {
  114. $where[] = ['status', '=', $search['status']];
  115. }
  116. return $where;
  117. }
  118. public static function findOne(array $search): ?Withdraw
  119. {
  120. return self::model()::where(self::getWhere($search))->first();
  121. }
  122. public static function findAll(array $search = [])
  123. {
  124. return self::model()::where(self::getWhere($search))->get();
  125. }
  126. public static function paginate(array $search = [])
  127. {
  128. $limit = isset($search['limit']) ? $search['limit'] : 10;
  129. $paginator = self::model()::where(self::getWhere($search))
  130. ->orderBy('created_at', 'desc')->paginate($limit);
  131. return ['total' => $paginator->total(), 'data' => $paginator->items()];
  132. }
  133. public function __construct()
  134. {
  135. $serviceCharge = Config::where('field', 'service_charge')->first()->val;
  136. $serviceCharge = floatval($serviceCharge);
  137. $this->serviceCharge = $serviceCharge;
  138. }
  139. public static function getServiceCharge(): float
  140. {
  141. $serviceCharge = Config::where('field', 'service_charge')->first()->val;
  142. return floatval($serviceCharge);
  143. }
  144. public static function notify($data)
  145. {
  146. try {
  147. $telegram = new Api(config('services.telegram.token'));
  148. $telegram->sendMessage($data);
  149. } catch (TelegramSDKException $e) {
  150. return false;
  151. }
  152. return true;
  153. }
  154. //提现账单
  155. public static function bill($chatId, $firstName, $messageId = null, $page = 1, $limit = 5)
  156. {
  157. $list = Withdraw::where('member_id', $chatId)
  158. ->orderBy('id', 'desc')
  159. ->forPage($page, $limit)
  160. ->get();
  161. $count = Withdraw::where('member_id', $chatId)
  162. ->whereIn('status', [0, 1])
  163. ->count();
  164. $status = [lang('等待放行'), lang('已到账'), lang("失败")];
  165. $text = "👤 {$firstName}({$chatId}) " . lang("钱包提现记录") . "\n\n";
  166. foreach ($list as $item) {
  167. $amount = floatval($item->amount);
  168. $balance = floatval($item->after_balance);
  169. $text .= "-------------------------------------\n";
  170. $text .= "➖ {$amount} USDT\n" . lang("余额") . ":{$balance} \n";
  171. $text .= lang("类别") . "类别:" . lang("提现") . "\n";
  172. $text .= lang("状态") . ":{$status[$item->status]}\n";
  173. if ($item->remark) {
  174. $text .= lang("说明") . ":{$item->remark}\n";
  175. }
  176. $text .= lang("日期") . ":{$item->created_at}\n";
  177. }
  178. if ($page > 1) {
  179. $keyboard[] = [
  180. ['text' => lang("👆上一页"), 'callback_data' => "withdrawBillNextPage@@" . ($page - 1)]
  181. ];
  182. }
  183. $allPage = ceil($count / $limit);
  184. if ($allPage > $page) {
  185. if ($page > 1) {
  186. $keyboard[count($keyboard) - 1][] = ['text' => lang("👇下一页"), 'callback_data' => "withdrawBillNextPage@@" . ($page + 1)];
  187. } else {
  188. $keyboard[] = [
  189. ['text' => lang("👇下一页"), 'callback_data' => "withdrawBillNextPage@@" . ($page + 1)]
  190. ];
  191. }
  192. }
  193. $keyboard[] = [
  194. ['text' => lang("↩️返回"), 'callback_data' => "withdraw@@home"]
  195. ];
  196. return [
  197. 'chat_id' => $chatId,
  198. 'text' => $text,
  199. 'message_id' => $messageId,
  200. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  201. ];
  202. }
  203. //删除地址
  204. public static function delAddress($chatId, $id, $messageId)
  205. {
  206. Address::where('id', $id)
  207. ->where('member_id', $chatId)->delete();
  208. return WithdrawService::getAddress($chatId, $messageId);
  209. }
  210. //地址详情
  211. public static function addressDetails($chatId, $messageId, $id)
  212. {
  213. $text = lang("*TRC20 地址管理*") . "\n\n";
  214. $address = Address::where('id', $id)
  215. ->where('member_id', $chatId)->first();
  216. $text .= lang("地址") . ":{$address->address}\n";
  217. $text .= lang("别名") . ":{$address->alias}";
  218. $keyboard = [
  219. [['text' => lang('❌删除该地址'), 'callback_data' => "withdrawAddress@@del{$id}"]],
  220. [['text' => lang('↩️返回列表'), 'callback_data' => 'withdraw@@address']]
  221. ];
  222. return [
  223. 'chat_id' => $chatId,
  224. 'parse_mode' => 'MarkdownV2',
  225. 'text' => $text,
  226. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard]),
  227. 'message_id' => $messageId
  228. ];
  229. }
  230. //输入别名
  231. public static function inputAlias($chatId, $alias, $messageId)
  232. {
  233. if (mb_strlen($alias) > 20) {
  234. return [
  235. 'chat_id' => $chatId,
  236. 'text' => lang("别名不能超过20个字,请重新输入"),
  237. 'reply_to_message_id' => $messageId,
  238. ];
  239. }
  240. $address = Cache::get("{$chatId}_address");
  241. $a = new Address();
  242. $a->address = $address;
  243. $a->alias = $alias;
  244. $a->member_id = $chatId;
  245. $a->save();
  246. Cache::delete("{$chatId}_address");
  247. Cache::delete(get_step_key($chatId));
  248. return self::getAddress($chatId, $messageId);
  249. }
  250. //用户输入TRC20地址
  251. public static function inputAddress($chatId, $address, $messageId)
  252. {
  253. if (!preg_match('/^T[a-zA-Z1-9]{33}$/', $address)) {
  254. return [
  255. 'chat_id' => $chatId,
  256. 'text' => lang("地址输入不正确,请重新输入TRC20地址"),
  257. 'reply_to_message_id' => $messageId,
  258. ];
  259. }
  260. Cache::put("{$chatId}_address", $address);
  261. Cache::put(get_step_key($chatId), StepStatus::INPUT_ADDRESS_ALIAS);
  262. return [
  263. 'chat_id' => $chatId,
  264. 'text' => lang("请输入地址别名,便于区分多个地址"),
  265. ];
  266. }
  267. //添加地址
  268. public static function addAddress($chatId, $messageId)
  269. {
  270. $text = lang('请输入新的TRC20地址') . "\n";
  271. $keyboard = [[
  272. ['text' => lang('❌取消'), 'callback_data' => "message@@close"],
  273. ]];
  274. Cache::put(get_step_key($chatId), StepStatus::INPUT_ADDRESS_TRC20);
  275. return [
  276. 'chat_id' => $chatId,
  277. 'text' => $text,
  278. 'message_id' => $messageId,
  279. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  280. ];
  281. }
  282. //地址管理
  283. public static function getAddress($chatId, $messageId)
  284. {
  285. $text = lang("🏠 地址管理");
  286. $text .= "\n--------------------------\n";
  287. $list = Address::where('member_id', $chatId)
  288. ->get();
  289. $keyboard = [];
  290. foreach ($list as $item) {
  291. $keyboard[] = [['text' => $item->alias, 'callback_data' => "withdrawAddress@@detail{$item->id}"]];
  292. }
  293. if (count($list) < 5) {
  294. $keyboard[] = [['text' => lang("➕ 添加地址"), 'callback_data' => "withdrawAddress@@add"]];
  295. }
  296. $keyboard[] = [['text' => lang("↩️返回"), 'callback_data' => "withdraw@@home"]];
  297. return [
  298. 'chat_id' => $chatId,
  299. 'text' => $text,
  300. 'message_id' => $messageId,
  301. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  302. ];
  303. }
  304. public static function done($chatId, $messageId, $firstName)
  305. {
  306. $serviceCharge = (new WithdrawService())->serviceCharge;
  307. $amount = Cache::get("{$chatId}_WITHDRAW_MONEY", '');
  308. $address = Cache::get("{$chatId}_WITHDRAW_ADDRESS", '');
  309. if (!$amount || !$address) return WithdrawService::index($chatId, $firstName, $messageId);
  310. $real = bcsub($amount, $serviceCharge, 10);
  311. $real = floatval($real);
  312. if ($amount <= $serviceCharge) {
  313. return [
  314. 'chat_id' => $chatId,
  315. 'text' => lang("⚠️提现不能少于") . "{$serviceCharge} USDT," . lang("请重试"),
  316. 'message_id' => $messageId
  317. ];
  318. }
  319. $wallet = Wallet::where('member_id', $chatId)->first();
  320. $temp = floatval($wallet->available_balance);
  321. // 汇率
  322. $rate = Config::where('field', 'exchange_rate_rmb')->first()->val ?? 1;
  323. $exchange_rate_difference = Config::where('field', 'exchange_rate_difference')->first()->val ?? 0;
  324. $rate = bcadd($rate, $exchange_rate_difference, 2);
  325. $rate_usdt_amount = bcdiv($temp, $rate, 2); // 钱包可用余额 折合USDT
  326. $rate_rmb_amount = bcmul($amount, $rate, 2); // 提现金额 折合RMB
  327. if ($amount > $rate_usdt_amount) {
  328. return [
  329. 'chat_id' => $chatId,
  330. 'text' => lang("⚠️可用余额不足,请重试"),
  331. 'message_id' => $messageId
  332. ];
  333. }
  334. $ru = RoomUser::where('member_id', $chatId)
  335. ->whereIn('status', [0, 1, 2, 3])
  336. ->first();
  337. if ($ru) {
  338. $text = lang("游戏未结算") . "\n";
  339. $text .= "⚠️ " . lang("您还有进行中的游戏,所有游戏结算后方可提现") . "\n";
  340. return [
  341. 'chat_id' => $chatId,
  342. 'text' => $text,
  343. 'message_id' => $messageId,
  344. 'reply_markup' => json_encode(['inline_keyboard' => [[
  345. ['text' => lang('进入房间'), 'callback_data' => "games@@home{$ru->room_id}"],
  346. ]]])
  347. ];
  348. }
  349. $wallet = Wallet::where('member_id', $chatId)->first();
  350. $changeAmount = bcmul(($amount * -1), $rate, 2);
  351. $beforeBalance = $wallet->available_balance;
  352. $afterBalance = bcsub($wallet->available_balance, $rate_rmb_amount, 2);
  353. $wallet->available_balance = $afterBalance;
  354. $wallet->save();
  355. $withdraw = Withdraw::create([
  356. 'member_id' => $chatId,
  357. 'amount' => $amount,
  358. 'service_charge' => $serviceCharge,
  359. 'to_account' => $real,
  360. 'address' => $address,
  361. 'exchange_rate' => $rate,
  362. 'status' => 0,
  363. 'after_balance' => $afterBalance
  364. ]);
  365. BalanceLogService::addLog($chatId, $changeAmount, $beforeBalance, $afterBalance, '提现', $withdraw->id, '');
  366. $temp = floatval($afterBalance);
  367. $text = "✅ " . lang("提现申请已提交!") . "\n\n";
  368. $text .= lang("钱包余额") . ":{$temp} RMB\n";
  369. $text .= lang("汇率") . ":1 USDT = {$rate} RMB\n";
  370. $text .= lang("剩余可用USDT余额") . ":" . number_format(bcdiv($temp, $rate, 2), 2) . " USDT\n";
  371. $text .= lang("提现金额") . ":{$amount} USDT\n";
  372. $text .= lang("实际到账") . ":{$real} USDT\n";
  373. $text .= lang("手续费") . ":{$serviceCharge} USDT\n\n";
  374. $text .= lang("⌛️请等待系统处理, 到账时间可能需要几分钟!") . "\n";
  375. Cache::delete(get_step_key($chatId));
  376. return [
  377. 'chat_id' => $chatId,
  378. 'text' => $text,
  379. 'message_id' => $messageId,
  380. ];
  381. }
  382. public static function chooseAddress($chatId, $firstName, $messageId, $id)
  383. {
  384. $serviceCharge = (new WithdrawService())->serviceCharge;
  385. $amount = Cache::get("{$chatId}_WITHDRAW_MONEY", '');
  386. if (!$amount) return WithdrawService::index($chatId, $firstName, $messageId);
  387. $amount = floatval($amount);
  388. $real = bcsub($amount, $serviceCharge, 10);
  389. $real = floatval($real);
  390. $address = Address::where('id', $id)
  391. ->where('member_id', $chatId)->first();
  392. $text = lang("请确认") . "\n\n";
  393. $text .= lang('手续费') . ":{$serviceCharge} USDT\n";
  394. $text .= lang("提现金额") . ":{$amount} USDT\n";
  395. $text .= lang("实际到账") . ":{$real} USDT\n";
  396. $text .= lang("提现地址") . ":{$address->address}\n";
  397. $keyboard = [
  398. [
  399. ['text' => lang('✅ 确认'), 'callback_data' => "withdrawAddress@@done"],
  400. ],
  401. [
  402. ['text' => lang('❌取消'), 'callback_data' => "message@@close"]
  403. ]
  404. ];
  405. Cache::put("{$chatId}_WITHDRAW_ADDRESS", $address->address);
  406. return [
  407. 'chat_id' => $chatId,
  408. 'text' => $text,
  409. 'message_id' => $messageId,
  410. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  411. ];
  412. }
  413. //用户输入提现金额(USDT)
  414. public static function inputAmount($chatId, $amount, $messageId)
  415. {
  416. if (!preg_match('/^-?\d+(\.\d+)?$/', $amount)) {
  417. return [[
  418. 'chat_id' => $chatId,
  419. 'text' => lang("金额输入不正确,请发送提现数字"),
  420. 'reply_to_message_id' => $messageId
  421. ]];
  422. }
  423. if ($amount < 20) {
  424. return [[
  425. 'chat_id' => $chatId,
  426. 'text' => lang("提现不能少于20 USDT,请重试"),
  427. 'reply_to_message_id' => $messageId
  428. ]];
  429. }
  430. $wallet = Wallet::where('member_id', $chatId)->first();
  431. $temp = floatval($wallet->available_balance);
  432. // 汇率
  433. $rate = Config::where('field', 'exchange_rate_rmb')->first()->val ?? 1;
  434. $rate_amount = bcdiv($temp, $rate, 2);
  435. $serviceCharge = Config::where('field', 'service_charge')->first()->val;
  436. $serviceCharge = floatval($serviceCharge);
  437. if ($amount <= $serviceCharge) {
  438. return [[
  439. 'chat_id' => $chatId,
  440. 'text' => lang("⚠️提现不能少于") . "{$serviceCharge} USDT," . lang('请重试'),
  441. 'reply_to_message_id' => $messageId
  442. ]];
  443. }
  444. if ($amount > $rate_amount) {
  445. return [[
  446. 'chat_id' => $chatId,
  447. 'text' => lang("可用余额不足,请重试"),
  448. 'reply_to_message_id' => $messageId
  449. ]];
  450. }
  451. $ru = RoomUser::where('member_id', $chatId)
  452. ->whereIn('status', [0, 1, 2, 3])
  453. ->first();
  454. if ($ru) {
  455. $text = lang('*游戏未结算*') . "\n";
  456. $text .= lang("⚠️ 您还有进行中的游戏,所有游戏结算后方可提现") . "\n";
  457. return [[
  458. 'chat_id' => $chatId,
  459. 'text' => $text,
  460. 'parse_mode' => 'MarkdownV2',
  461. 'reply_markup' => json_encode(['inline_keyboard' => [[
  462. ['text' => lang('进入房间'), 'callback_data' => "games@@home{$ru->room_id}"],
  463. ]]])
  464. ]];
  465. }
  466. $list = Address::where('member_id', $chatId)->get();
  467. $keyboard = [];
  468. foreach ($list as $item) {
  469. $keyboard[] = [['text' => $item->alias, 'callback_data' => "withdrawAddress@@choose{$item->id}"]];
  470. }
  471. $keyboard[] = [
  472. ['text' => lang("🏠 地址管理"), 'callback_data' => "withdraw@@address"],
  473. ['text' => lang('❌取消'), 'callback_data' => "message@@close"]
  474. ];
  475. $text = lang('请直接选择下面的地址') . "\n";
  476. $text .= lang("⚠️提示:请务必确认提现地址正确无误,\n否则资金丢失将无法找回请自负!");
  477. Cache::put("{$chatId}_WITHDRAW_MONEY", $amount);
  478. Cache::put(get_step_key($chatId), StepStatus::CHOOSE_WITHDRAW_ADDRESS);
  479. return [[
  480. 'chat_id' => $chatId,
  481. 'text' => $text,
  482. 'reply_to_message_id' => $messageId,
  483. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  484. ]];
  485. }
  486. //申请提现
  487. public static function apply($chatId, $messageId)
  488. {
  489. $wallet = Wallet::where('member_id', $chatId)->first();
  490. // 汇率
  491. $rate = Config::where('field', 'exchange_rate_rmb')->first()->val ?? 1;
  492. $exchange_rate_difference = Config::where('field', 'exchange_rate_difference')->first()->val ?? 0;
  493. $rate = bcadd($rate, $exchange_rate_difference, 2);
  494. $temp = floatval($wallet->available_balance);
  495. $amount = bcdiv($temp, $rate, 2);
  496. $serviceCharge = static::getServiceCharge();
  497. $text = lang("请发送提现金额");
  498. $text .= " (USDT)";
  499. $text .= "\n💰 " . lang('当前余额') . ":{$temp} RMB ({$amount} USDT)\n";
  500. $text .= "⚠️" . lang('汇率') . ":1 USDT = {$rate} RMB\n";
  501. $text .= "⚠️ " . lang('提现将收取') . "{$serviceCharge}" . lang('U作为手续费') . "\n";
  502. // $keyboard = [[
  503. // ['text' => "🔙返回", 'callback_data' => "withdraw@@home"],
  504. // ]];
  505. Cache::put(get_step_key($chatId), StepStatus::INPUT_WITHDRAW_MONEY);
  506. return [
  507. 'chat_id' => $chatId,
  508. 'text' => $text,
  509. 'message_id' => $messageId,
  510. // 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  511. ];
  512. }
  513. //提现管理
  514. public static function index($chatId, $firstName, $messageId = null)
  515. {
  516. $wallet = Wallet::where('member_id', $chatId)->first();
  517. $text = "👤 {$firstName}({$chatId})\n\n";
  518. $text .= "💰钱包余额\n";
  519. $temp = floatval($wallet->available_balance);
  520. $text .= "USDT:{$temp}\n";
  521. $text .= "--------------------------\n";
  522. $serviceAccount = Config::where('field', 'service_account')->first()->val;
  523. $keyboard = [
  524. [
  525. ['text' => '➕ 提现', 'callback_data' => "withdraw@@apply"],
  526. ['text' => '🧾 账单', 'callback_data' => "withdraw@@bill"]
  527. ],
  528. [
  529. ['text' => lang("🏠 地址管理"), 'callback_data' => "withdraw@@address"],
  530. ['text' => lang('👩 客服帮助'), 'url' => "https://t.me/{$serviceAccount}"]
  531. ],
  532. [
  533. ['text' => lang('❌取消'), 'callback_data' => "message@@close"],
  534. ]
  535. ];
  536. return [
  537. 'chat_id' => $chatId,
  538. 'text' => $text,
  539. 'message_id' => $messageId,
  540. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  541. ];
  542. }
  543. public static function setStatus($id, $status, $remark)
  544. {
  545. $w = WithdrawService::findOne(['id' => $id, 'status' => 0]);
  546. if (!$w) return;
  547. // 汇率
  548. $rate = $w->exchange_rate ?? 1;
  549. if ($status == 1) {
  550. $w->status = 1;
  551. $w->save();
  552. } else if ($status == 2) {
  553. $rate_rmb_amount = bcmul($w->amount, $rate, 2); // 提现金额 折合RMB
  554. $w->status = 2;
  555. $w->remark = $remark;
  556. $w->save();
  557. $wallet = WalletService::findOne(['member_id' => $w->member_id]);
  558. $afterBalance = bcadd($wallet->available_balance, $rate_rmb_amount, 10);
  559. BalanceLogService::addLog($w->member_id, $w->rate_rmb_amount, $wallet->available_balance, $afterBalance, '提现', $w->id, '');
  560. $wallet->available_balance = $afterBalance;
  561. $wallet->save();
  562. }
  563. $arr = ['⏳️申请中', '✅️成功', '❌️失败'];
  564. $text = "📢 提现结果通知\n\n";
  565. $temp = floatval($w->service_charge);
  566. $text .= "手续费:{$temp} USDT\n";
  567. $temp = floatval($w->amount);
  568. $text .= "提现金额:{$temp} USDT\n";
  569. $temp = floatval($w->to_account);
  570. $text .= "到账金额:{$temp} USDT\n";
  571. $text .= "提现地址:{$w->address}\n\n";
  572. $text .= "状态:{$arr[$w->status]}\n";
  573. if ($w->remark) $text .= "说明:{$w->remark}";
  574. WithdrawService::notify([
  575. 'chat_id' => $w->member_id,
  576. 'text' => $text,
  577. ]);
  578. }
  579. public static function batchReject()
  580. {
  581. $list = Withdraw::where('status', 0)->get();
  582. foreach ($list as $k => $v) {
  583. WithdrawService::setStatus($v->id, 2, '赠送彩金,提现需满足活动需求,提现只允许走rmb渠道');
  584. }
  585. }
  586. }