WithdrawService.php 25 KB

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