QianBaoWithdrawService.php 27 KB

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