Wallet.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. ]);
  37. }
  38. /**
  39. * 创建代收订单
  40. */
  41. public function createPay()
  42. {
  43. try {
  44. $params = request()->validate([
  45. 'amount' => ['required', 'numeric', 'min:0.01'],
  46. 'payment_type' => ['required', 'string'],
  47. ]);
  48. $member_id = request()->user->member_id;
  49. $res = PaymentOrderService::createPay($member_id, $params['amount'], $params['payment_type']);
  50. return $this->success($res);
  51. } catch (\Exception $e) {
  52. return $this->error($e->getMessage());
  53. }
  54. }
  55. /**
  56. * 获取充值二维码(USDT充值)
  57. */
  58. public function scan()
  59. {
  60. try {
  61. $member_id = request()->user->member_id;
  62. $params = request()->validate([
  63. 'amount' => ['required', 'numeric', 'min:0.01'],
  64. 'type' => ['required', 'string'],
  65. ]);
  66. $receivingType = ConfigService::getVal("receiving_type");
  67. //自动充值
  68. if ($receivingType == 1) {
  69. $res = WalletService::getRechargeImageAddress($member_id);
  70. $address = $res['address'];
  71. $qrCode = $res['full_path'];
  72. } else {
  73. //手动充值
  74. if ($params['type'] === "TRC20") {
  75. $address = Config::where('field', 'receiving_address')->first()->val;
  76. } elseif ($params['type'] === "ERC20") {
  77. $address = Config::where('field', 'receiving_address_erc20')->first()->val;
  78. } else {
  79. return $this->error(lang('充值类型错误'));
  80. }
  81. $res = WalletService::getPlatformImageAddress($address);
  82. $res['net'] = $params['type'];
  83. $qrCode = $res['full_path'];
  84. }
  85. return $this->success([
  86. 'qrcode' => $qrCode,
  87. // 'photo' => InputFile::create($qrCode),
  88. ]);
  89. } catch (\Exception $e) {
  90. return $this->error($e->getMessage());
  91. }
  92. }
  93. /**
  94. * 提交充值凭证
  95. */
  96. public function recharge()
  97. {
  98. try {
  99. $params = request()->validate([
  100. 'net' => ['required', 'string'],
  101. 'amount' => ['required', 'numeric', 'min:0.01'],
  102. 'toAddress' => ['required', 'string'],
  103. 'image' => ['required', 'url'],
  104. ]);
  105. $member_id = '';
  106. $recharge = new Recharge();
  107. $recharge->member_id = $member_id;
  108. $recharge->net = $params['net'];
  109. $recharge->coin = "USDT";
  110. $recharge->amount = $params['amount'];
  111. $recharge->to_address = $params['toAddress'];
  112. $recharge->status = 0;
  113. $recharge->type = 2;
  114. $recharge->image = $params['image'];
  115. $recharge->save();
  116. } catch (ValidationException $e) {
  117. return $this->error($e->validator->errors()->first());
  118. } catch (Exception $e) {
  119. return $this->error($e->getMessage());
  120. }
  121. }
  122. }