WithdrawService.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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. $serviceAccount = Config::where('field', 'service_customer')->first()->val;
  307. $activityUser = ActivityUserService::findOne([
  308. 'member_id' => $chatId,
  309. 'status' => 0
  310. ]);
  311. if ($activityUser) {
  312. $text = lang("您有未完成的活动") . "\n";
  313. $text .= lang("任何疑问都可以联系唯一客服") . ":@{$serviceAccount}";
  314. return [
  315. 'chat_id' => $chatId,
  316. 'text' => $text,
  317. 'message_id' => $messageId,
  318. ];
  319. }
  320. $serviceCharge = (new WithdrawService())->serviceCharge;
  321. $amount = Cache::get("{$chatId}_WITHDRAW_MONEY", '');
  322. $address = Cache::get("{$chatId}_WITHDRAW_ADDRESS", '');
  323. if (!$amount || !$address) return WithdrawService::index($chatId, $firstName, $messageId);
  324. $real = bcsub($amount, $serviceCharge, 10);
  325. $real = floatval($real);
  326. if ($amount <= $serviceCharge) {
  327. return [
  328. 'chat_id' => $chatId,
  329. 'text' => lang("⚠️提现不能少于") . "{$serviceCharge} USDT," . lang("请重试"),
  330. 'message_id' => $messageId
  331. ];
  332. }
  333. $wallet = Wallet::where('member_id', $chatId)->first();
  334. $temp = floatval($wallet->available_balance);
  335. // 汇率
  336. $rate = Config::where('field', 'exchange_rate_rmb')->first()->val ?? 1;
  337. $exchange_rate_difference = Config::where('field', 'exchange_rate_difference')->first()->val ?? 0;
  338. $rate = bcadd($rate, $exchange_rate_difference, 2);
  339. $rate_usdt_amount = bcdiv($temp, $rate, 2); // 钱包可用余额 折合USDT
  340. $rate_rmb_amount = bcmul($amount, $rate, 2); // 提现金额 折合RMB
  341. if ($amount > $rate_usdt_amount) {
  342. return [
  343. 'chat_id' => $chatId,
  344. 'text' => lang("⚠️可用余额不足,请重试"),
  345. 'message_id' => $messageId
  346. ];
  347. }
  348. $ru = RoomUser::where('member_id', $chatId)
  349. ->whereIn('status', [0, 1, 2, 3])
  350. ->first();
  351. if ($ru) {
  352. $text = lang("游戏未结算") . "\n";
  353. $text .= "⚠️ " . lang("您还有进行中的游戏,所有游戏结算后方可提现") . "\n";
  354. return [
  355. 'chat_id' => $chatId,
  356. 'text' => $text,
  357. 'message_id' => $messageId,
  358. 'reply_markup' => json_encode(['inline_keyboard' => [[
  359. ['text' => lang('进入房间'), 'callback_data' => "games@@home{$ru->room_id}"],
  360. ]]])
  361. ];
  362. }
  363. $wallet = Wallet::where('member_id', $chatId)->first();
  364. $changeAmount = bcmul(($amount * -1), $rate, 2);
  365. $beforeBalance = $wallet->available_balance;
  366. $afterBalance = bcsub($wallet->available_balance, $rate_rmb_amount, 2);
  367. $wallet->available_balance = $afterBalance;
  368. $wallet->save();
  369. $withdraw = Withdraw::create([
  370. 'member_id' => $chatId,
  371. 'amount' => $amount,
  372. 'service_charge' => $serviceCharge,
  373. 'to_account' => $real,
  374. 'address' => $address,
  375. 'exchange_rate' => $rate,
  376. 'status' => 0,
  377. 'after_balance' => $afterBalance
  378. ]);
  379. BalanceLogService::addLog($chatId, $changeAmount, $beforeBalance, $afterBalance, '提现', $withdraw->id, '');
  380. $temp = floatval($afterBalance);
  381. $text = "✅ " . lang("提现申请已提交!") . "\n\n";
  382. $text .= lang("钱包余额") . ":{$temp} RMB\n";
  383. $text .= lang("汇率") . ":1 USDT = {$rate} RMB\n";
  384. $text .= lang("剩余可用USDT余额") . ":" . number_format(bcdiv($temp, $rate, 2), 2) . " USDT\n";
  385. $text .= lang("提现金额") . ":{$amount} USDT\n";
  386. $text .= lang("实际到账") . ":{$real} USDT\n";
  387. $text .= lang("手续费") . ":{$serviceCharge} USDT\n\n";
  388. $text .= lang("⌛️请等待系统处理, 到账时间可能需要几分钟!") . "\n";
  389. Cache::delete(get_step_key($chatId));
  390. return [
  391. 'chat_id' => $chatId,
  392. 'text' => $text,
  393. 'message_id' => $messageId,
  394. ];
  395. }
  396. public static function chooseAddress($chatId, $firstName, $messageId, $id)
  397. {
  398. $serviceCharge = (new WithdrawService())->serviceCharge;
  399. $amount = Cache::get("{$chatId}_WITHDRAW_MONEY", '');
  400. if (!$amount) return WithdrawService::index($chatId, $firstName, $messageId);
  401. $amount = floatval($amount);
  402. $real = bcsub($amount, $serviceCharge, 10);
  403. $real = floatval($real);
  404. $address = Address::where('id', $id)
  405. ->where('member_id', $chatId)->first();
  406. $text = lang("请确认") . "\n\n";
  407. $text .= lang('手续费') . ":{$serviceCharge} USDT\n";
  408. $text .= lang("提现金额") . ":{$amount} USDT\n";
  409. $text .= lang("实际到账") . ":{$real} USDT\n";
  410. $text .= lang("提现地址") . ":{$address->address}\n";
  411. $keyboard = [
  412. [
  413. ['text' => lang('✅ 确认'), 'callback_data' => "withdrawAddress@@done"],
  414. ],
  415. [
  416. ['text' => lang('❌取消'), 'callback_data' => "message@@close"]
  417. ]
  418. ];
  419. Cache::put("{$chatId}_WITHDRAW_ADDRESS", $address->address);
  420. return [
  421. 'chat_id' => $chatId,
  422. 'text' => $text,
  423. 'message_id' => $messageId,
  424. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  425. ];
  426. }
  427. //用户输入提现金额(USDT)
  428. public static function inputAmount($chatId, $amount, $messageId)
  429. {
  430. if (!preg_match('/^-?\d+(\.\d+)?$/', $amount)) {
  431. return [[
  432. 'chat_id' => $chatId,
  433. 'text' => lang("金额输入不正确,请发送提现数字"),
  434. 'reply_to_message_id' => $messageId
  435. ]];
  436. }
  437. if ($amount < 20) {
  438. return [[
  439. 'chat_id' => $chatId,
  440. 'text' => lang("提现不能少于20 USDT,请重试"),
  441. 'reply_to_message_id' => $messageId
  442. ]];
  443. }
  444. $wallet = Wallet::where('member_id', $chatId)->first();
  445. $temp = floatval($wallet->available_balance);
  446. // 汇率
  447. $rate = Config::where('field', 'exchange_rate_rmb')->first()->val ?? 1;
  448. $rate_amount = bcdiv($temp, $rate, 2);
  449. $serviceCharge = Config::where('field', 'service_charge')->first()->val;
  450. $serviceCharge = floatval($serviceCharge);
  451. if ($amount <= $serviceCharge) {
  452. return [[
  453. 'chat_id' => $chatId,
  454. 'text' => lang("⚠️提现不能少于") . "{$serviceCharge} USDT," . lang('请重试'),
  455. 'reply_to_message_id' => $messageId
  456. ]];
  457. }
  458. if ($amount > $rate_amount) {
  459. return [[
  460. 'chat_id' => $chatId,
  461. 'text' => lang("可用余额不足,请重试"),
  462. 'reply_to_message_id' => $messageId
  463. ]];
  464. }
  465. $ru = RoomUser::where('member_id', $chatId)
  466. ->whereIn('status', [0, 1, 2, 3])
  467. ->first();
  468. if ($ru) {
  469. $text = lang('*游戏未结算*') . "\n";
  470. $text .= lang("⚠️ 您还有进行中的游戏,所有游戏结算后方可提现") . "\n";
  471. return [[
  472. 'chat_id' => $chatId,
  473. 'text' => $text,
  474. 'parse_mode' => 'MarkdownV2',
  475. 'reply_markup' => json_encode(['inline_keyboard' => [[
  476. ['text' => lang('进入房间'), 'callback_data' => "games@@home{$ru->room_id}"],
  477. ]]])
  478. ]];
  479. }
  480. $list = Address::where('member_id', $chatId)->get();
  481. $keyboard = [];
  482. foreach ($list as $item) {
  483. $keyboard[] = [['text' => $item->alias, 'callback_data' => "withdrawAddress@@choose{$item->id}"]];
  484. }
  485. $keyboard[] = [
  486. ['text' => lang("🏠 地址管理"), 'callback_data' => "withdraw@@address"],
  487. ['text' => lang('❌取消'), 'callback_data' => "message@@close"]
  488. ];
  489. $text = lang('请直接选择下面的地址') . "\n";
  490. $text .= lang("⚠️提示:请务必确认提现地址正确无误,\n否则资金丢失将无法找回请自负!");
  491. Cache::put("{$chatId}_WITHDRAW_MONEY", $amount);
  492. Cache::put(get_step_key($chatId), StepStatus::CHOOSE_WITHDRAW_ADDRESS);
  493. return [[
  494. 'chat_id' => $chatId,
  495. 'text' => $text,
  496. 'reply_to_message_id' => $messageId,
  497. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  498. ]];
  499. }
  500. //申请提现
  501. public static function apply($chatId, $messageId)
  502. {
  503. $wallet = Wallet::where('member_id', $chatId)->first();
  504. // 汇率
  505. $rate = Config::where('field', 'exchange_rate_rmb')->first()->val ?? 1;
  506. $exchange_rate_difference = Config::where('field', 'exchange_rate_difference')->first()->val ?? 0;
  507. $rate = bcadd($rate, $exchange_rate_difference, 2);
  508. $temp = floatval($wallet->available_balance);
  509. $amount = bcdiv($temp, $rate, 2);
  510. $serviceCharge = static::getServiceCharge();
  511. $text = lang("请发送提现金额");
  512. $text .= " (USDT)";
  513. $text .= "\n💰 " . lang('当前余额') . ":{$temp} RMB ({$amount} USDT)\n";
  514. $text .= "⚠️" . lang('汇率') . ":1 USDT = {$rate} RMB\n";
  515. $text .= "⚠️ " . lang('提现将收取') . "{$serviceCharge}" . lang('U作为手续费') . "\n";
  516. // $keyboard = [[
  517. // ['text' => "🔙返回", 'callback_data' => "withdraw@@home"],
  518. // ]];
  519. Cache::put(get_step_key($chatId), StepStatus::INPUT_WITHDRAW_MONEY);
  520. return [
  521. 'chat_id' => $chatId,
  522. 'text' => $text,
  523. 'message_id' => $messageId,
  524. // 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  525. ];
  526. }
  527. //提现管理
  528. public static function index($chatId, $firstName, $messageId = null)
  529. {
  530. $wallet = Wallet::where('member_id', $chatId)->first();
  531. $text = "👤 {$firstName}({$chatId})\n\n";
  532. $text .= "💰钱包余额\n";
  533. $temp = floatval($wallet->available_balance);
  534. $text .= "USDT:{$temp}\n";
  535. $text .= "--------------------------\n";
  536. $serviceAccount = Config::where('field', 'service_account')->first()->val;
  537. $keyboard = [
  538. [
  539. ['text' => '➕ 提现', 'callback_data' => "withdraw@@apply"],
  540. ['text' => '🧾 账单', 'callback_data' => "withdraw@@bill"]
  541. ],
  542. [
  543. ['text' => lang("🏠 地址管理"), 'callback_data' => "withdraw@@address"],
  544. ['text' => lang('👩 客服帮助'), 'url' => "https://t.me/{$serviceAccount}"]
  545. ],
  546. [
  547. ['text' => lang('❌取消'), 'callback_data' => "message@@close"],
  548. ]
  549. ];
  550. return [
  551. 'chat_id' => $chatId,
  552. 'text' => $text,
  553. 'message_id' => $messageId,
  554. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  555. ];
  556. }
  557. public static function setStatus($id, $status, $remark)
  558. {
  559. $w = WithdrawService::findOne(['id' => $id, 'status' => 0]);
  560. if (!$w) return 0;
  561. // 汇率
  562. $rate = $w->exchange_rate ?? 1;
  563. if ($status == 1) {
  564. $w->status = 1;
  565. $w->save();
  566. } else if ($status == 2) {
  567. $rate_rmb_amount = bcmul($w->amount, $rate, 2); // 提现金额 折合RMB
  568. $w->status = 2;
  569. $w->remark = $remark;
  570. $w->save();
  571. $wallet = WalletService::findOne(['member_id' => $w->member_id]);
  572. $afterBalance = bcadd($wallet->available_balance, $rate_rmb_amount, 10);
  573. BalanceLogService::addLog($w->member_id, $w->rate_rmb_amount, $wallet->available_balance, $afterBalance, '提现', $w->id, '');
  574. $wallet->available_balance = $afterBalance;
  575. $wallet->save();
  576. }
  577. $arr = ['⏳️申请中', '✅️成功', '❌️失败'];
  578. $text = "📢 提现结果通知\n\n";
  579. $temp = floatval($w->service_charge);
  580. $text .= "手续费:{$temp} USDT\n";
  581. $temp = floatval($w->amount);
  582. $text .= "提现金额:{$temp} USDT\n";
  583. $temp = floatval($w->to_account);
  584. $text .= "到账金额:{$temp} USDT\n";
  585. $text .= "提现地址:{$w->address}\n\n";
  586. $text .= "状态:{$arr[$w->status]}\n";
  587. if ($w->remark) $text .= "说明:{$w->remark}";
  588. WithdrawService::notify([
  589. 'chat_id' => $w->member_id,
  590. 'text' => $text,
  591. ]);
  592. return 1;
  593. }
  594. public static function batchReject()
  595. {
  596. $list = Withdraw::where('status', 0)->get();
  597. foreach ($list as $k => $v) {
  598. WithdrawService::setStatus($v->id, 2, '赠送彩金,提现需满足活动需求,提现只允许走rmb渠道');
  599. }
  600. }
  601. }