QianBaoWithdrawService.php 26 KB

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