Wallet.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Http\Controllers\api;
  3. use App\Services\WalletService;
  4. use App\Services\ConfigService;
  5. use App\Models\Config;
  6. use App\Models\Recharge;
  7. use App\Services\Payment\SanJinService;
  8. use Illuminate\Validation\ValidationException;
  9. use Exception;
  10. /**
  11. * 充值提现接口
  12. */
  13. class Wallet extends BaseController
  14. {
  15. //获取三斤充值通道(微信、支付宝、扫码充值)
  16. public function getChannel()
  17. {
  18. $data = SanJinService::getChannel();
  19. $list = [];
  20. foreach($data as $k => $v) {
  21. $list[] = [
  22. 'label' => lang($v),
  23. 'value' => $k,
  24. ];
  25. }
  26. return $this->success([
  27. 'list' => $list,
  28. ]);
  29. }
  30. /**
  31. * 获取充值二维码(USDT充值)
  32. */
  33. function scan()
  34. {
  35. $member_id = request()->user->member_id;
  36. $type = 'TRC20';
  37. $receivingType = ConfigService::getVal("receiving_type");
  38. //自动充值
  39. if ($receivingType == 1) {
  40. $res = WalletService::getRechargeImageAddress($member_id);
  41. $address = $res['address'];
  42. $qrCode = $res['full_path'];
  43. } else {
  44. //手动充值
  45. if ($type === "TRC20") {
  46. $address = Config::where('field', 'receiving_address')->first()->val;
  47. } elseif ($type === "ERC20") {
  48. $address = Config::where('field', 'receiving_address_erc20')->first()->val;
  49. } else {
  50. return $this->error(lang('充值类型错误'));
  51. }
  52. $res = WalletService::getPlatformImageAddress($address);
  53. $res['net'] = $type;
  54. $qrCode = $res['full_path'];
  55. }
  56. return $this->success([
  57. 'qrcode' => $qrCode,
  58. // 'photo' => InputFile::create($qrCode),
  59. ]);
  60. }
  61. /**
  62. * 提交充值凭证
  63. */
  64. public function recharge()
  65. {
  66. try {
  67. $params = request()->validate([
  68. 'net' => ['required', 'string'],
  69. 'amount' => ['required', 'float'],
  70. 'toAddress' => ['required', 'string'],
  71. 'image' => ['required', 'url'],
  72. ]);
  73. $member_id = '';
  74. $recharge = new Recharge();
  75. $recharge->member_id = $member_id;
  76. $recharge->net = $params['net'];
  77. $recharge->coin = "USDT";
  78. $recharge->amount = $params['amount'];
  79. $recharge->to_address = $params['toAddress'];
  80. $recharge->status = 0;
  81. $recharge->type = 2;
  82. $recharge->image = $params['image'];
  83. $recharge->save();
  84. } catch (ValidationException $e) {
  85. return $this->error($e->validator->errors()->first());
  86. } catch (Exception $e) {
  87. return $this->error($e->getMessage());
  88. }
  89. }
  90. }