Wallet.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 App\Services\PaymentOrderService;
  9. use Illuminate\Validation\ValidationException;
  10. use Exception;
  11. /**
  12. * 充值提现接口
  13. */
  14. class Wallet extends BaseController
  15. {
  16. //获取三斤充值通道(微信、支付宝、扫码充值)
  17. public function getChannel()
  18. {
  19. $data = SanJinService::getChannel();
  20. $product = SanJinService::$PRODUCT;
  21. $list = [];
  22. foreach($data as $k => $v) {
  23. foreach($product as $pv) {
  24. if ($k == $pv['type']) {
  25. $config = $pv;
  26. }
  27. }
  28. $list[] = [
  29. 'label' => lang($v),
  30. 'value' => $k,
  31. 'config' => $config ?? [],
  32. ];
  33. }
  34. return $this->success([
  35. 'list' => $list,
  36. 'product' => $product,
  37. ]);
  38. }
  39. /**
  40. * 创建代收订单
  41. */
  42. public function createPay()
  43. {
  44. try {
  45. $params = request()->validate([
  46. 'amount' => ['required', 'float'],
  47. 'payment_type' => ['required', 'string'],
  48. ]);
  49. $member_id = request()->user->member_id;
  50. $res = PaymentOrderService::createPay($member_id, $params['amount'], $params['payment_type']);
  51. return $this->success($res);
  52. } catch (\Exception $e) {
  53. return $this->error($e->getMessage());
  54. }
  55. }
  56. /**
  57. * 获取充值二维码(USDT充值)
  58. */
  59. public function scan()
  60. {
  61. $member_id = request()->user->member_id;
  62. $type = 'TRC20';
  63. $receivingType = ConfigService::getVal("receiving_type");
  64. //自动充值
  65. if ($receivingType == 1) {
  66. $res = WalletService::getRechargeImageAddress($member_id);
  67. $address = $res['address'];
  68. $qrCode = $res['full_path'];
  69. } else {
  70. //手动充值
  71. if ($type === "TRC20") {
  72. $address = Config::where('field', 'receiving_address')->first()->val;
  73. } elseif ($type === "ERC20") {
  74. $address = Config::where('field', 'receiving_address_erc20')->first()->val;
  75. } else {
  76. return $this->error(lang('充值类型错误'));
  77. }
  78. $res = WalletService::getPlatformImageAddress($address);
  79. $res['net'] = $type;
  80. $qrCode = $res['full_path'];
  81. }
  82. return $this->success([
  83. 'qrcode' => $qrCode,
  84. // 'photo' => InputFile::create($qrCode),
  85. ]);
  86. }
  87. /**
  88. * 提交充值凭证
  89. */
  90. public function recharge()
  91. {
  92. try {
  93. $params = request()->validate([
  94. 'net' => ['required', 'string'],
  95. 'amount' => ['required', 'float'],
  96. 'toAddress' => ['required', 'string'],
  97. 'image' => ['required', 'url'],
  98. ]);
  99. $member_id = '';
  100. $recharge = new Recharge();
  101. $recharge->member_id = $member_id;
  102. $recharge->net = $params['net'];
  103. $recharge->coin = "USDT";
  104. $recharge->amount = $params['amount'];
  105. $recharge->to_address = $params['toAddress'];
  106. $recharge->status = 0;
  107. $recharge->type = 2;
  108. $recharge->image = $params['image'];
  109. $recharge->save();
  110. } catch (ValidationException $e) {
  111. return $this->error($e->validator->errors()->first());
  112. } catch (Exception $e) {
  113. return $this->error($e->getMessage());
  114. }
  115. }
  116. }