WithdrawService.php 25 KB

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