QianBaoWithdrawService.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. /**
  92. * @description: 创建代付订单
  93. * @param {*} $memberId 会员
  94. * @param {*} $amount 金额
  95. * @param {*} $channel 提现通道 DF001 支付宝转卡/DF002 支付宝转支付宝
  96. * @param {*} $bank_name 银行名称/支付宝
  97. * @param {*} $account 姓名
  98. * @param {*} $card_no 银行卡号/支付宝账号
  99. * @return {*}
  100. */
  101. $result = PaymentOrderService::createPayout($chatId, $amount, $bank->channel, $bank->bank_name, $bank->account, $bank->card_no);
  102. return [
  103. ];
  104. }
  105. //银行卡管理
  106. static function banks($chatId, $messageId)
  107. {
  108. $text = "🏠 银行卡管理\n";
  109. $text .= "--------------------------\n";
  110. $list = Bank::where('member_id', $chatId)
  111. ->get();
  112. $keyboard = [];
  113. foreach ($list as $item) {
  114. $keyboard[] = [['text' => "$item->card_no($item->bank_name)", 'callback_data' => "withdrawAddress@@bank_detail{$item->id}"]];
  115. }
  116. if (count($list) < 5) {
  117. $keyboard[] = [['text' => "➕ 添加银行卡", 'callback_data' => "withdrawAddress@@bang_add"]];
  118. }
  119. $keyboard[] = [['text' => "↩️返回", 'callback_data' => "withdraw@@home"]];
  120. return [
  121. 'chat_id' => $chatId,
  122. 'text' => $text,
  123. 'message_id' => $messageId,
  124. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  125. ];
  126. }
  127. }