QianBaoWithdrawService.php 25 KB

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