WithdrawService.php 23 KB

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