QianBaoWithdrawService.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <?php
  2. namespace App\Services;
  3. use App\Constants\HttpStatus;
  4. use App\Constants\StepStatus;
  5. use App\Models\Bank;
  6. use App\Models\Config;
  7. use App\Models\PaymentOrder;
  8. use App\Models\Wallet;
  9. use App\Services\Payment\QianBaoService;
  10. use Exception;
  11. use Illuminate\Support\Facades\Cache;
  12. use Illuminate\Support\Facades\DB;
  13. use Telegram\Bot\Api;
  14. use Telegram\Bot\Exceptions\TelegramSDKException;
  15. class QianBaoWithdrawService
  16. {
  17. /**
  18. * @param Api $telegram
  19. * @param $data
  20. * @param $chatId
  21. * @param $firstName
  22. * @param $messageId
  23. * @throws TelegramSDKException
  24. */
  25. public static function init(Api $telegram, $data, $chatId, $firstName, $messageId): void
  26. {
  27. //点击钱宝提现按钮
  28. if ($data === "withdraw@@qb_show_channel") {
  29. $res = QianBaoWithdrawService::chooseType($chatId, $messageId);
  30. $telegram->editMessageText($res);
  31. }
  32. $pattern = "/^withdraw@@qb_choose_.*$/";
  33. if (preg_match($pattern, $data)) {
  34. $type = preg_replace('/^withdraw@@qb_choose_/', '', $data);
  35. $res = QianBaoWithdrawService::showBanks($chatId, $messageId, $type);
  36. $telegram->editMessageText($res);
  37. }
  38. //选择银行卡号
  39. $pattern = "/^withdrawAddress@@choose_qb_\d+$/";
  40. if (preg_match($pattern, $data)) {
  41. $id = preg_replace('/^withdrawAddress@@choose_qb_/', '', $data);
  42. $res = QianBaoWithdrawService::chooseBank($chatId, $id);
  43. $telegram->deleteMessage([
  44. 'chat_id' => $chatId,
  45. 'message_id' => $messageId,
  46. ]);
  47. $telegram->sendMessage($res);
  48. }
  49. //确认提现信息
  50. if ($data === "withdraw@@qb_confirm") {
  51. $res = QianBaoWithdrawService::confirm($chatId, $messageId);
  52. $telegram->editMessageText($res);
  53. }
  54. if ($data === "withdraw@@qb_apply") {
  55. $res = QianBaoWithdrawService::qbApply($chatId, $messageId);
  56. $telegram->editMessageText($res);
  57. }
  58. //钱宝账单
  59. $pattern = "/^withdraw@@bank_bill_\d+$/";
  60. if (preg_match($pattern, $data)) {
  61. $page = preg_replace('/^withdraw@@bank_bill_/', '', $data);
  62. if (empty($page) || $page < 1) $page = 1;
  63. $page = intval($page);
  64. $res = QianBaoWithdrawService::bill($chatId, $firstName, $messageId, $page);
  65. $telegram->editMessageText($res);
  66. }
  67. //银行卡管理
  68. $pattern = "/^withdraw@@management_.*$/";
  69. if (preg_match($pattern, $data)) {
  70. $channel = preg_replace('/^withdraw@@management_/', '', $data);
  71. $res = QianBaoWithdrawService::banks($chatId, $messageId, $channel);
  72. $telegram->editMessageText($res);
  73. }
  74. //添加银行卡
  75. // $pattern = "/^withdraw@@bank_add.*$/";
  76. // if (preg_match($pattern, $data)) {
  77. // $channel = preg_replace('/^withdraw@@bank_add/', '', $data);
  78. // $res = QianBaoWithdrawService::chooseChannel($chatId, $messageId,$channel);
  79. // $telegram->editMessageText($res);
  80. // }
  81. //银行卡详情
  82. $pattern = "/^withdrawAddress@@bank_detail\d+$/";
  83. if (preg_match($pattern, $data)) {
  84. $id = preg_replace('/^withdrawAddress@@bank_detail/', '', $data);
  85. $res = static::bankDetails($chatId, $messageId, $id);
  86. $telegram->editMessageText($res);
  87. }
  88. $pattern = "/^withdraw@@bank_del_\d+$/";
  89. if (preg_match($pattern, $data)) {
  90. $id = preg_replace('/^withdraw@@bank_del_/', '', $data);
  91. $res = static::bankDelete($chatId, $messageId, $id);
  92. $telegram->editMessageText($res);
  93. }
  94. $pattern = "/^withdrawAddress@@bank_choose_channel_.*$/";
  95. if (preg_match($pattern, $data)) {
  96. $channel = preg_replace('/^withdrawAddress@@bank_choose_channel_/', '', $data);
  97. $res = static::chooseChannel($chatId, $messageId, $channel);
  98. $telegram->editMessageText($res);
  99. }
  100. }
  101. public static function onMessage($chatId, $text, $messageId, $stepStatus): null|array
  102. {
  103. return match ($stepStatus) {
  104. StepStatus::QB_INPUT_ALIAS => QianBaoWithdrawService::inputAliAs($chatId, $text, $messageId),
  105. StepStatus::INPUT_WITHDRAW_QB_MONEY => QianBaoWithdrawService::inputQbAmount($chatId, $text, $messageId),
  106. StepStatus::QB_INPUT_BANK_NAME => QianBaoWithdrawService::inputBankName($chatId, $text, $messageId),
  107. StepStatus::QB_INPUT_CARD_NO => QianBaoWithdrawService::inputCardNo($chatId, $text, $messageId),
  108. StepStatus::QB_INPUT_ACCOUNT => QianBaoWithdrawService::inputAccount($chatId, $text, $messageId),
  109. default => null,
  110. };
  111. }
  112. private static function chooseType($chatId, $messageId)
  113. {
  114. $keyboard = [
  115. [
  116. ['text' => lang("USDT"), 'callback_data' => "withdraw@@apply"],
  117. ],
  118. [
  119. ['text' => lang("银行卡"), 'callback_data' => "withdraw@@qb_choose_bank"],
  120. ],
  121. [
  122. ['text' => lang("支付宝"), 'callback_data' => "withdraw@@qb_choose_aliPay"],
  123. ],
  124. [
  125. ['text' => lang("数字人民币"), 'callback_data' => "withdraw@@qb_choose_digital_RMB"],
  126. ],
  127. [
  128. ['text' => lang("返回"), 'callback_data' => "topUp@@home"],
  129. ],
  130. ];
  131. // $keyboard[] = [
  132. // ['text' => "提现账户管理", 'callback_data' => "withdraw@@banks"],
  133. // ];
  134. return [
  135. 'chat_id' => $chatId,
  136. 'text' => lang("请选择提现方式"),
  137. 'message_id' => $messageId,
  138. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  139. ];
  140. }
  141. private static function showBanks($chatId, $messageId, $type)
  142. {
  143. $channel = '';
  144. $card = "";
  145. $text = "";
  146. switch ($type) {
  147. case "bank":
  148. $card = lang("银行卡");
  149. $text = lang("请选择提现的银行卡");
  150. $channel = 'DF001';
  151. break;
  152. case "aliPay":
  153. $card = lang("支付宝");
  154. $text = lang("请选择提现的支付宝");
  155. $channel = "DF002";
  156. break;
  157. case "digital_RMB":
  158. $card = lang("数字人民币");
  159. $text = lang("请选择提现的账户");
  160. $channel = "DF005";
  161. break;
  162. }
  163. $list = Bank::where('member_id', $chatId)->where('channel', $channel)->get();
  164. $keyboard = [];
  165. foreach ($list as $item) {
  166. $keyboard[] = [['text' => $item->getAlias(), 'callback_data' => "withdrawAddress@@choose_qb_{$item->getId()}"]];
  167. }
  168. $keyboard[] = [
  169. ['text' => "{$card}" . lang("管理"), 'callback_data' => "withdraw@@management_{$channel}"],
  170. ['text' => lang("返回"), 'callback_data' => "withdraw@@qb_show_channel"]];
  171. return [
  172. 'chat_id' => $chatId,
  173. 'text' => $text,
  174. 'message_id' => $messageId,
  175. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  176. ];
  177. }
  178. //钱宝账单
  179. private static function bill($chatId, $firstName, $messageId, $page = 1, $limit = 5)
  180. {
  181. $list = PaymentOrder::where('member_id', $chatId)
  182. ->where('type', 2)
  183. ->orderByDesc('created_at')
  184. ->forPage($page, $limit)
  185. ->get();
  186. $count = PaymentOrder::where('member_id', $chatId)
  187. ->where('type', 2)
  188. ->count();
  189. $text = "👤 {$firstName}({$chatId}) " . lang('钱宝提现记录') . "\n\n";
  190. foreach ($list as $item) {
  191. $amount = floatval($item->amount);
  192. $amount = $item->type == 2 ? "➖ {$amount}" : "➕ $amount";
  193. $text .= "-------------------------------------\n";
  194. $text .= "{$amount} \n";
  195. $text .= lang("订单号") . ":{$item->order_no}\n";
  196. $text .= lang('银行') . ":{$item->bank_name}\n";
  197. $text .= lang("姓名") . ":{$item->account}\n";
  198. $text .= lang("卡号") . ":{$item->card_no}\n";
  199. $status = [lang('待处理'), lang('处理中'), lang('成功'), lang('失败')];
  200. $text .= lang("状态") . ":{$status[$item->status]}\n";
  201. if ($item->remark) {
  202. $text .= lang("说明") . ":{$item->remark}\n";
  203. }
  204. $text .= lang('日期') . ":{$item->created_at}\n";
  205. }
  206. if ($page > 1) {
  207. $keyboard[] = [
  208. ['text' => lang("👆上一页"), 'callback_data' => "withdraw@@bank_bill_" . ($page - 1)]
  209. ];
  210. }
  211. $allPage = ceil($count / $limit);
  212. if ($allPage > $page) {
  213. if ($page > 1) {
  214. $keyboard[count($keyboard) - 1][] = ['text' => lang("👇下一页"), 'callback_data' => "withdraw@@bank_bill_" . ($page + 1)];
  215. } else {
  216. $keyboard[] = [
  217. ['text' => lang("👇下一页"), 'callback_data' => "withdraw@@bank_bill_" . ($page + 1)]
  218. ];
  219. }
  220. }
  221. $keyboard[] = [
  222. ['text' => lang("返回"), 'callback_data' => "topUp@@home"]
  223. ];
  224. return [
  225. 'chat_id' => $chatId,
  226. 'text' => $text,
  227. 'message_id' => $messageId,
  228. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  229. ];
  230. }
  231. //1.钱宝提现
  232. private static function qbApply($chatId, $messageId)
  233. {
  234. $three_payment_switch = Config::where('field', 'three_payment_switch')->first()->val;
  235. if ($three_payment_switch != 1) {
  236. $res = WalletService::getBalance($chatId);
  237. $res['message_id'] = $messageId;
  238. return $res;
  239. }
  240. $wallet = Wallet::where('member_id', $chatId)->first();
  241. $temp = floatval($wallet->available_balance);
  242. $text = lang("请发送提现金额") . "\n";
  243. $text .= "💰 " . lang("当前余额") . "{$temp} RMB\n";
  244. // Cache::put(get_step_key($chatId), StepStatus::INPUT_WITHDRAW_QB_MONEY);
  245. return [
  246. 'chat_id' => $chatId,
  247. 'text' => $text,
  248. 'message_id' => $messageId,
  249. ];
  250. }
  251. //2.选择银行卡号
  252. private static function chooseBank($chatId, $id)
  253. {
  254. Cache::put(get_step_key($chatId), StepStatus::INPUT_WITHDRAW_QB_MONEY);
  255. Cache::put("{$chatId}_QB_BANK_ID", $id);
  256. return [
  257. 'chat_id' => $chatId,
  258. 'text' => lang("请输入提现的金额"),
  259. ];
  260. }
  261. //3.输入钱宝提现金额
  262. private static function inputQbAmount($chatId, $amount, $messageId)
  263. {
  264. if (!preg_match('/^\d+(\.\d{1,2})?$/', $amount)) {
  265. return [
  266. 'chat_id' => $chatId,
  267. 'text' => lang('金额输入不正确,请发送提现数字'),
  268. 'reply_to_message_id' => $messageId
  269. ];
  270. }
  271. $amount = floatval($amount);
  272. $wallet = Wallet::where('member_id', $chatId)->first();
  273. $temp = floatval($wallet->available_balance);
  274. if ($amount > $temp) {
  275. return [
  276. 'chat_id' => $chatId,
  277. 'text' => lang("可用余额不足,请重试"),
  278. 'reply_to_message_id' => $messageId
  279. ];
  280. }
  281. if ($amount < 100) {
  282. return [
  283. 'chat_id' => $chatId,
  284. 'text' => lang("提现不能少于100 RMB,请重试"),
  285. 'reply_to_message_id' => $messageId
  286. ];
  287. }
  288. if ($amount > 49999) {
  289. return [
  290. 'chat_id' => $chatId,
  291. 'text' => lang("最多提现 49999 RMB,请重试"),
  292. 'reply_to_message_id' => $messageId
  293. ];
  294. }
  295. $bankId = Cache::get("{$chatId}_QB_BANK_ID");
  296. $bank = Bank::where('id', $bankId)->first();
  297. $text = "";
  298. switch ($bank->getChannel()) {
  299. case "DF001":
  300. $text = lang('银行卡提现确认') . "\n";
  301. $text .= lang('开户行') . ":{$bank->getBankName()}\n";
  302. $text .= lang('姓名') . ":{$bank->getAccount()}\n";
  303. $text .= lang('提现账号') . ":{$bank->getCardNo()}\n";
  304. $text .= lang('提现金额') . ":{$amount}\n";
  305. break;
  306. case "DF002":
  307. $text = lang("支付宝提现确认") . "\n";
  308. $text .= lang('姓名') . ":{$bank->getAccount()}\n";
  309. $text .= lang('提现账号') . ":{$bank->getCardNo()}\n";
  310. $text .= lang('提现金额') . ":{$amount}\n";
  311. break;
  312. case "DF005":
  313. $text = lang('数字人民币提现确认') . "\n";
  314. $text .= lang('姓名') . ":{$bank->getAccount()}\n";
  315. $text .= lang('提现账号') . ":{$bank->getCardNo()}\n";
  316. $text .= lang('提现金额') . ":{$amount}\n";
  317. break;
  318. }
  319. $keyboard = [
  320. [
  321. ['text' => lang("确认"), 'callback_data' => 'withdraw@@qb_confirm']
  322. ],
  323. [
  324. ['text' => '❌取消', 'callback_data' => "message@@close"]
  325. ]];
  326. Cache::put("{$chatId}_WITHDRAW_QB_MONEY", $amount);
  327. return [
  328. 'chat_id' => $chatId,
  329. 'text' => $text,
  330. // 'reply_to_message_id' => $messageId,
  331. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  332. ];
  333. }
  334. private static function confirm($chatId, $messageId)
  335. {
  336. $id = Cache::get("{$chatId}_QB_BANK_ID");
  337. $bank = Bank::where('id', $id)->first();
  338. $amount = Cache::get("{$chatId}_WITHDRAW_QB_MONEY");
  339. //提现是否自动转到三方到账,否的话,需要后台审核,审核通过后才会进行第三方转账
  340. //目前客户要求手动到账,后续也可以做到config 表,从后台进行控制
  341. $isAutoDeposit = false;
  342. if ($isAutoDeposit) {
  343. $res = PaymentOrderService::autoCreatePayout($chatId, $amount, $bank->getChannel(), $bank->getBankName(), $bank->getAccount(), $bank->getCardNo());
  344. } else {
  345. $res = static::createOrder($chatId, $amount, $bank->getChannel(), $bank->getBankName(), $bank->getAccount(), $bank->getCardNo());
  346. }
  347. $res['message_id'] = $messageId;
  348. return $res;
  349. }
  350. //创建提现订单
  351. private static function createOrder($memberId, $amount, $channel, $bank_name, $account, $card_no)
  352. {
  353. DB::beginTransaction();
  354. $result['chat_id'] = $memberId;
  355. $default_amount = $amount;
  356. try {
  357. $wallet = WalletService::findOne(['member_id' => $memberId]);
  358. if (!$wallet) throw new Exception('钱包不存在', HttpStatus::CUSTOM_ERROR);
  359. $balance = $wallet->available_balance;
  360. if (bccomp($balance, $amount, 2) < 0) {
  361. throw new Exception("您的钱包余额不足!", HttpStatus::CUSTOM_ERROR);
  362. }
  363. $available_balance = bcsub($balance, $amount, 10);
  364. // 先预扣款(锁定资金)
  365. $wallet->available_balance = $available_balance;
  366. if (!$wallet->save()) throw new Exception('钱包更新失败!', HttpStatus::CUSTOM_ERROR);
  367. $data = [];
  368. $data['type'] = PaymentOrderService::TYPE_PAYOUT;
  369. $data['order_no'] = PaymentOrderService::createOrderNo('sj' . $data['type'] . '_', $memberId);
  370. $data['member_id'] = $memberId;
  371. $data['fee'] = $amount * 0.002 + 2;
  372. $data['amount'] = number_format($amount, 2, '.', '');
  373. $data['channel'] = $channel;
  374. $data['bank_name'] = $bank_name;
  375. $data['account'] = $account;
  376. $data['card_no'] = $card_no;
  377. $data['callback_url'] = QianBaoService::getNotifyUrl();
  378. $data['status'] = PaymentOrderService::STATUS_STAY;
  379. $data['remark'] = '提现费率:0.2%+2';
  380. // 创建待处理状态的提现记录
  381. $info = PaymentOrder::create($data);
  382. // 记录余额变动日志
  383. BalanceLogService::addLog(
  384. $memberId,
  385. $default_amount,
  386. $balance,
  387. $available_balance,
  388. '三方提现',
  389. $info->id,
  390. '钱宝提现费率:0.2%+2'
  391. );
  392. $balance = bcadd($available_balance, 0, 2);
  393. $text = "✅ 提现申请已提交!\n\n";
  394. $text .= "钱包余额:{$balance} RMB\n";
  395. $text .= "提现金额:{$default_amount} RMB\n";
  396. $text .= "⌛️请等待系统处理, 到账时间可能需要几分钟!\n";
  397. $result['text'] = $text;
  398. DB::commit();
  399. } //
  400. catch (Exception $e) {
  401. DB::rollBack();
  402. $result['text'] = "系统发生了错误,请联系管理员";
  403. if ($e->getCode() === HttpStatus::CUSTOM_ERROR) {
  404. $result['text'] = $e->getMessage();
  405. }
  406. }
  407. return $result;
  408. }
  409. //银行卡管理
  410. private static function banks($chatId, $messageId, $channel = ""): array
  411. {
  412. $text = '';
  413. switch ($channel) {
  414. case "DF001":
  415. $text = lang("银行卡列表") . "\n";
  416. break;
  417. case "DF002":
  418. $text = lang('支付宝账户列表') . "\n";
  419. break;
  420. case "DF005":
  421. $text = lang('数字人民币账户列表') . "\n";
  422. break;
  423. }
  424. $list = Bank::where('member_id', $chatId)
  425. ->where("channel", $channel)
  426. ->get();
  427. $keyboard = [];
  428. foreach ($list as $item) {
  429. $keyboard[] = [['text' => $item->getAlias(), 'callback_data' => "withdrawAddress@@bank_detail{$item->getId()}"]];
  430. }
  431. if (count($list) < 5) {
  432. $keyboard[] = [
  433. ['text' => lang("➕ 添加"), 'callback_data' => "withdrawAddress@@bank_choose_channel_{$channel}"],
  434. ['text' => lang("↩️返回"), 'callback_data' => "topUp@@home"]
  435. ];
  436. } else {
  437. $keyboard[] = [['text' => lang("↩️返回"), 'callback_data' => "topUp@@home"]];
  438. }
  439. return [
  440. 'chat_id' => $chatId,
  441. 'text' => $text,
  442. 'message_id' => $messageId,
  443. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  444. ];
  445. }
  446. //银行卡详情
  447. private static function bankDetails($chatId, $messageId, $id)
  448. {
  449. $bank = Bank::where('id', $id)
  450. ->where('member_id', $chatId)->first();
  451. switch ($bank->getChannel()) {
  452. case "DF001":
  453. $text = "*" . lang('银行卡管理') . "*\n\n";
  454. $text .= lang('姓名') . ":{$bank->getAccount()}\n";
  455. $text .= lang('银行') . ":{$bank->getAccount()}\n";
  456. $text .= lang('卡号') . ":{$bank->getCardNo()}\n";
  457. break;
  458. case "DF002":
  459. $text = "*" . lang('支付宝管理') . "*\n\n";
  460. $text .= lang('姓名') . ":{$bank->getAccount()}\n";
  461. $text .= lang('银行') . ":{$bank->getBankName()}\n";
  462. $text .= lang('账号') . ":{$bank->getCardNo()}\n";
  463. break;
  464. default:
  465. $text = "*" . lang('银行卡管理') . "*\n\n";
  466. $text .= lang('姓名') . ":{$bank->getAccount()}\n";
  467. $text .= lang('银行') . ":{$bank->getBankName()}\n";
  468. $text .= lang('卡号') . ":{$bank->getCardNo()}\n";
  469. break;
  470. }
  471. $keyboard = [
  472. [
  473. ['text' => lang('❌删除'), 'callback_data' => "withdraw@@bank_del_{$id}"],
  474. ['text' => lang('↩️返回列表'), 'callback_data' => "withdraw@@management_{$bank->getChannel()}"]
  475. ],
  476. ];
  477. return [
  478. 'chat_id' => $chatId,
  479. 'parse_mode' => 'MarkdownV2',
  480. 'text' => $text,
  481. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard]),
  482. 'message_id' => $messageId
  483. ];
  484. }
  485. //删除银行卡
  486. private static function bankDelete($chatId, $messageId, $id): array
  487. {
  488. $channel = Bank::where('id', $id)
  489. ->where('member_id', $chatId)->first()->getChannel();
  490. Bank::where('id', $id)->where('member_id', $chatId)->delete();
  491. return static::banks($chatId, $messageId, $channel);
  492. }
  493. //选择通道
  494. private static function chooseChannel($chatId, $messageId, $channel)
  495. {
  496. Cache::put("{$chatId}_QB_WITHDRAW_CHANNEL", $channel);
  497. switch ($channel) {
  498. case "DF001"://银行卡
  499. Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_BANK_NAME);
  500. return [
  501. 'chat_id' => $chatId,
  502. 'text' => lang("请输入开户银行卡开户名称"),
  503. 'message_id' => $messageId,
  504. ];
  505. case "DF002"://支付宝
  506. Cache::put("{$chatId}_QB_WITHDRAW_BANK_NAME", '支付宝');
  507. Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_CARD_NO);
  508. return [
  509. 'chat_id' => $chatId,
  510. 'text' => lang("请输入支付宝账号"),
  511. 'message_id' => $messageId,
  512. ];
  513. case "DF005"://数字人民币
  514. Cache::put("{$chatId}_QB_WITHDRAW_BANK_NAME", '数字人民币');
  515. Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_CARD_NO);
  516. return [
  517. 'chat_id' => $chatId,
  518. 'text' => lang("请输入数字人民币账号"),
  519. 'message_id' => $messageId,
  520. ];
  521. default:
  522. return [
  523. 'chat_id' => $chatId,
  524. 'text' => lang("选择通道错误"),
  525. 'message_id' => $messageId,
  526. ];
  527. }
  528. }
  529. //输入银行名称
  530. private static function inputBankName($chatId, $bankName, $messageId): array
  531. {
  532. Cache::put("{$chatId}_QB_WITHDRAW_BANK_NAME", $bankName);
  533. Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_CARD_NO);
  534. return [
  535. 'chat_id' => $chatId,
  536. 'text' => lang("请输入银行卡号"),
  537. 'message_id' => $messageId,
  538. ];
  539. }
  540. //输入卡号
  541. private static function inputCardNo($chatId, $cardNo, $messageId): array
  542. {
  543. $channel = Cache::get("{$chatId}_QB_WITHDRAW_CHANNEL");
  544. if ($channel === 'DF001' && !preg_match('/^\d+$/', $cardNo)) {
  545. return [
  546. 'chat_id' => $chatId,
  547. 'text' => lang("输入的银行卡号有误,请重新输入"),
  548. 'reply_to_message_id' => $messageId,
  549. ];
  550. }
  551. Cache::put("{$chatId}_QB_WITHDRAW_CARD_NO", $cardNo);
  552. Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_ACCOUNT);
  553. return [
  554. 'chat_id' => $chatId,
  555. 'text' => lang("请输入姓名"),
  556. 'message_id' => $messageId,
  557. ];
  558. }
  559. //输入姓名
  560. private static function inputAccount($chatId, $account, $messageId): array
  561. {
  562. Cache::put("{$chatId}_QB_ACCOUNT", $account);
  563. Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_ALIAS);
  564. $channel = Cache::get("{$chatId}_QB_WITHDRAW_CHANNEL");
  565. $text = lang("请输入别名");
  566. switch ($channel) {
  567. case "DF005":
  568. case "DF001":
  569. $text = lang('请输入账号别名');
  570. break;
  571. }
  572. return [
  573. 'chat_id' => $chatId,
  574. 'text' => $text,
  575. 'message_id' => $messageId,
  576. ];
  577. }
  578. //输入别名,并保存到数据库
  579. private static function inputAliAs($chatId, $alias, $messageId): array
  580. {
  581. $channel = Cache::get("{$chatId}_QB_WITHDRAW_CHANNEL");
  582. $cardNo = Cache::get("{$chatId}_QB_WITHDRAW_CARD_NO");
  583. $bankName = Cache::get("{$chatId}_QB_WITHDRAW_BANK_NAME");
  584. $account = Cache::get("{$chatId}_QB_ACCOUNT");
  585. Bank::create([
  586. 'member_id' => $chatId,
  587. 'account' => $account,
  588. 'channel' => $channel,
  589. 'card_no' => $cardNo,
  590. 'bank_name' => $bankName,
  591. 'alias' => $alias
  592. ]);
  593. Cache::delete(get_step_key($chatId));
  594. return static::banks($chatId, $messageId, $channel);
  595. }
  596. }