QianBaoWithdrawService.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. use Telegram\Bot\Api;
  9. class QianBaoWithdrawService
  10. {
  11. /**
  12. * @param Api $telegram
  13. * @param $data
  14. * @param $chatId
  15. * @param $firstName
  16. * @param $messageId
  17. * @throws \Telegram\Bot\Exceptions\TelegramSDKException
  18. */
  19. static function init(Api $telegram, $data, $chatId, $firstName, $messageId)
  20. {
  21. //点击钱宝提现按钮
  22. if ($data === "withdraw@@qb_apply") {
  23. $res = QianBaoWithdrawService::qbApply($chatId, $messageId);
  24. $telegram->editMessageText($res);
  25. }
  26. //选择银行卡号
  27. $pattern = "/^withdrawAddress@@choose_qb_\d+$/";
  28. if (preg_match($pattern, $data)) {
  29. $id = preg_replace('/^withdrawAddress@@choose_qb_/', '', $data);
  30. $res = QianBaoWithdrawService::chooseBank($chatId, $id);
  31. $telegram->deleteMessage([
  32. 'chat_id' => $chatId,
  33. 'message_id' => $messageId,
  34. ]);
  35. $telegram->sendMessage($res);
  36. }
  37. //银行卡管理
  38. if ($data === 'withdraw@@banks') {
  39. $res = QianBaoWithdrawService::banks($chatId, $messageId);
  40. $telegram->editMessageText($res);
  41. }
  42. //添加银行卡
  43. if ($data === "withdrawAddress@@bank_add") {
  44. $res = QianBaoWithdrawService::addBank($chatId, $messageId);
  45. $telegram->editMessageText($res);
  46. }
  47. }
  48. //1.钱宝提现
  49. static function qbApply($chatId, $messageId)
  50. {
  51. $three_payment_switch = Config::where('field', 'three_payment_switch')->first()->val;
  52. if ($three_payment_switch != 1) {
  53. $res = WalletService::getBalance($chatId);
  54. $res['message_id'] = $messageId;
  55. return $res;
  56. }
  57. $wallet = Wallet::where('member_id', $chatId)->first();
  58. $temp = floatval($wallet->available_balance);
  59. $text = "请发送提现金额\n";
  60. $text .= "💰 当前余额{$temp} RMB\n";
  61. Cache::put(get_step_key($chatId), StepStatus::INPUT_WITHDRAW_QB_MONEY);
  62. return [
  63. 'chat_id' => $chatId,
  64. 'text' => $text,
  65. 'message_id' => $messageId,
  66. ];
  67. }
  68. //2.输入钱宝提现金额
  69. static function inputQbAmount($chatId, $amount, $messageId)
  70. {
  71. if (!preg_match('/^\d+(\.\d{1,2})?$/', $amount)) {
  72. return [
  73. 'chat_id' => $chatId,
  74. 'text' => "金额输入不正确,请发送提现数字",
  75. 'reply_to_message_id' => $messageId
  76. ];
  77. }
  78. $amount = floatval($amount);
  79. $wallet = Wallet::where('member_id', $chatId)->first();
  80. $temp = floatval($wallet->available_balance);
  81. if ($amount > $temp) {
  82. return [
  83. 'chat_id' => $chatId,
  84. 'text' => "⚠️可用余额不足,请重试",
  85. 'reply_to_message_id' => $messageId
  86. ];
  87. }
  88. if ($amount < 100) {
  89. return [
  90. 'chat_id' => $chatId,
  91. 'text' => "⚠️提现不能少于100 RMB,请重试",
  92. 'reply_to_message_id' => $messageId
  93. ];
  94. }
  95. if ($amount > 49999) {
  96. return [
  97. 'chat_id' => $chatId,
  98. 'text' => "⚠️最多提现 49999 RMB,请重试",
  99. 'reply_to_message_id' => $messageId
  100. ];
  101. }
  102. Cache::put("{$chatId}_WITHDRAW_MONEY", $amount);
  103. $list = Bank::where('member_id', $chatId)->get();
  104. $keyboard = [];
  105. foreach ($list as $item) {
  106. $keyboard[] = [['text' => "$item->card_no($item->bank_name)", 'callback_data' => "withdrawAddress@@choose_qb_{$item->id}"]];
  107. }
  108. $keyboard[] = [
  109. ['text' => '🏠 银行卡管理', 'callback_data' => "withdraw@@banks"],
  110. ['text' => '❌取消', 'callback_data' => "message@@close"]
  111. ];
  112. $text = "请直接选择下面的地址\n";
  113. $text .= "⚠️提示:请务必确认提现地址正确无误,\n否则资金丢失将无法找回请自负!";
  114. Cache::put("{$chatId}_WITHDRAW_QB_MONEY", $amount);
  115. Cache::put(get_step_key($chatId), StepStatus::CHOOSE_WITHDRAW_QB_ADDRESS);
  116. return [
  117. 'chat_id' => $chatId,
  118. 'text' => $text,
  119. 'reply_to_message_id' => $messageId,
  120. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  121. ];
  122. }
  123. //3.选择银行卡号
  124. static function chooseBank($chatId, $id)
  125. {
  126. $amount = Cache::get("{$chatId}_WITHDRAW_QB_MONEY", '');
  127. if (!$amount) return WalletService::getBalance($chatId);
  128. $bank = Bank::where('id', $id)->first();
  129. // PaymentOrderService::createPayout($chatId, $amount, $bank->channel, $bank->bank_name, $bank->account, $bank->card_no);
  130. $text = "提交成功\n";
  131. $text .= "结果将在稍后通知您,请留意通知!!!";
  132. return [
  133. 'chat_id' => $chatId,
  134. 'text' => $text,
  135. ];
  136. }
  137. //银行卡管理
  138. static function banks($chatId, $messageId)
  139. {
  140. $text = "🏠 银行卡管理\n";
  141. $text .= "--------------------------\n";
  142. $list = Bank::where('member_id', $chatId)
  143. ->get();
  144. $keyboard = [];
  145. foreach ($list as $item) {
  146. $keyboard[] = [['text' => "$item->card_no($item->bank_name)", 'callback_data' => "withdrawAddress@@bank_detail{$item->id}"]];
  147. }
  148. if (count($list) < 5) {
  149. $keyboard[] = [['text' => "➕ 添加银行卡", 'callback_data' => "withdrawAddress@@bank_add"]];
  150. }
  151. $keyboard[] = [['text' => "↩️返回", 'callback_data' => "withdraw@@home"]];
  152. return [
  153. 'chat_id' => $chatId,
  154. 'text' => $text,
  155. 'message_id' => $messageId,
  156. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  157. ];
  158. }
  159. static function addBank($chatId, $messageId)
  160. {
  161. $text = "请选择 提现通道\n";
  162. $keyboard = [
  163. [
  164. ['text' => '银行卡', 'callback_data' => "withdrawAddress@@bank_choose_channel_DF001"]
  165. ],
  166. [
  167. ['text' => '支付宝', 'callback_data' => "withdrawAddress@@bank_choose_channel_DF002"]
  168. ],
  169. [
  170. ['text' => '❌取消', 'callback_data' => "message@@close"]
  171. ]
  172. ];
  173. return [
  174. 'chat_id' => $chatId,
  175. 'text' => $text,
  176. 'message_id' => $messageId,
  177. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  178. ];
  179. }
  180. }