QianBaoWithdrawService.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace App\Services;
  3. use App\Constants\StepStatus;
  4. use App\Models\Bank;
  5. use App\Models\Config;
  6. use App\Models\Wallet;
  7. use Illuminate\Support\Facades\Cache;
  8. class QianBaoWithdrawService
  9. {
  10. //1.钱宝提现
  11. static function qbApply($chatId, $messageId)
  12. {
  13. $three_payment_switch = Config::where('field', 'three_payment_switch')->first()->val;
  14. if ($three_payment_switch != 1) {
  15. $res = WalletService::getBalance($chatId);
  16. $res['message_id'] = $messageId;
  17. return $res;
  18. }
  19. $wallet = Wallet::where('member_id', $chatId)->first();
  20. $temp = floatval($wallet->available_balance);
  21. $text = "请发送提现金额\n";
  22. $text .= "💰 当前余额{$temp} RMB\n";
  23. Cache::put(get_step_key($chatId), StepStatus::INPUT_WITHDRAW_QB_MONEY);
  24. return [
  25. 'chat_id' => $chatId,
  26. 'text' => $text,
  27. 'message_id' => $messageId,
  28. ];
  29. }
  30. //2.输入钱宝提现金额
  31. static function inputQbAmount($chatId, $amount, $messageId)
  32. {
  33. if (!preg_match('/^\d+(\.\d{1,2})?$/', $amount)) {
  34. return [
  35. 'chat_id' => $chatId,
  36. 'text' => "金额输入不正确,请发送提现数字",
  37. 'reply_to_message_id' => $messageId
  38. ];
  39. }
  40. $amount = floatval($amount);
  41. $wallet = Wallet::where('member_id', $chatId)->first();
  42. $temp = floatval($wallet->available_balance);
  43. if ($amount > $temp) {
  44. return [
  45. 'chat_id' => $chatId,
  46. 'text' => "⚠️可用余额不足,请重试",
  47. 'reply_to_message_id' => $messageId
  48. ];
  49. }
  50. if ($amount < 100) {
  51. return [
  52. 'chat_id' => $chatId,
  53. 'text' => "⚠️提现不能少于100 RMB,请重试",
  54. 'reply_to_message_id' => $messageId
  55. ];
  56. }
  57. if ($amount > 49999) {
  58. return [
  59. 'chat_id' => $chatId,
  60. 'text' => "⚠️最多提现 49999 RMB,请重试",
  61. 'reply_to_message_id' => $messageId
  62. ];
  63. }
  64. Cache::put("{$chatId}_WITHDRAW_MONEY", $amount);
  65. $list = Bank::where('member_id', $chatId)->get();
  66. $keyboard = [];
  67. foreach ($list as $item) {
  68. $keyboard[] = [['text' => "$item->card_no($item->bank_name)", 'callback_data' => "withdrawAddress@@choose_qb_{$item->id}"]];
  69. }
  70. $keyboard[] = [
  71. ['text' => '🏠 银行卡管理', 'callback_data' => "withdraw@@banks"],
  72. ['text' => '❌取消', 'callback_data' => "message@@close"]
  73. ];
  74. $text = "请直接选择下面的地址\n";
  75. $text .= "⚠️提示:请务必确认提现地址正确无误,\n否则资金丢失将无法找回请自负!";
  76. Cache::put("{$chatId}_WITHDRAW_QB_MONEY", $amount);
  77. Cache::put(get_step_key($chatId), StepStatus::CHOOSE_WITHDRAW_QB_ADDRESS);
  78. return [
  79. 'chat_id' => $chatId,
  80. 'text' => $text,
  81. 'reply_to_message_id' => $messageId,
  82. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  83. ];
  84. }
  85. //3.选择银行卡号
  86. static function chooseBank($chatId, $firstName, $messageId, $id)
  87. {
  88. $amount = Cache::get("{$chatId}_WITHDRAW_QB_MONEY", '');
  89. if (!$amount) return WalletService::getBalance($chatId);
  90. $bank = Bank::where('id', $id)->first();
  91. // PaymentOrderService::createPayout($chatId, $amount, $bank->channel, $bank->bank_name, $bank->account, $bank->card_no);
  92. $text = "提交成功\n";
  93. $text .= "结果将在稍后通知您,请留意通知!!!";
  94. return [
  95. 'chat_id' => $chatId,
  96. 'text' => $text,
  97. ];
  98. }
  99. //银行卡管理
  100. static function banks($chatId, $messageId)
  101. {
  102. $text = "🏠 银行卡管理\n";
  103. $text .= "--------------------------\n";
  104. $list = Bank::where('member_id', $chatId)
  105. ->get();
  106. $keyboard = [];
  107. foreach ($list as $item) {
  108. $keyboard[] = [['text' => "$item->card_no($item->bank_name)", 'callback_data' => "withdrawAddress@@bank_detail{$item->id}"]];
  109. }
  110. if (count($list) < 5) {
  111. $keyboard[] = [['text' => "➕ 添加银行卡", 'callback_data' => "withdrawAddress@@bang_add"]];
  112. }
  113. $keyboard[] = [['text' => "↩️返回", 'callback_data' => "withdraw@@home"]];
  114. return [
  115. 'chat_id' => $chatId,
  116. 'text' => $text,
  117. 'message_id' => $messageId,
  118. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  119. ];
  120. }
  121. }