Wallet.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Illuminate\Validation\ValidationException;
  8. use Exception;
  9. /**
  10. * 充值提现接口
  11. */
  12. class Wallet extends BaseController
  13. {
  14. /**
  15. * 获取充值二维码(微信、支付宝、扫码充值)
  16. */
  17. function scan()
  18. {
  19. $member_id = request()->user->member_id;
  20. $type = 'TRC20';
  21. $receivingType = ConfigService::getVal("receiving_type");
  22. //自动充值
  23. if ($receivingType == 1) {
  24. $res = WalletService::getRechargeImageAddress($member_id);
  25. $address = $res['address'];
  26. $qrCode = $res['full_path'];
  27. } else {
  28. //手动充值
  29. if ($type === "TRC20") {
  30. $address = Config::where('field', 'receiving_address')->first()->val;
  31. } else {//if ($type === "ERC20")
  32. $address = Config::where('field', 'receiving_address_erc20')->first()->val;
  33. }
  34. $res = WalletService::getPlatformImageAddress($address);
  35. $res['net'] = $type;
  36. $qrCode = $res['full_path'];
  37. }
  38. return $this->success([
  39. 'qrcode' => $qrCode,
  40. // 'photo' => InputFile::create($qrCode),
  41. ]);
  42. }
  43. /**
  44. * 提交充值凭证
  45. */
  46. public function recharge()
  47. {
  48. try {
  49. $params = request()->validate([
  50. 'net' => ['required', 'string'],
  51. 'amount' => ['required', 'float'],
  52. 'toAddress' => ['required', 'string'],
  53. 'image' => ['required', 'url'],
  54. ]);
  55. $member_id = '';
  56. $recharge = new Recharge();
  57. $recharge->member_id = $member_id;
  58. $recharge->net = $params['net'];
  59. $recharge->coin = "USDT";
  60. $recharge->amount = $params['amount'];
  61. $recharge->to_address = $params['toAddress'];
  62. $recharge->status = 0;
  63. $recharge->type = 2;
  64. $recharge->image = $params['image'];
  65. $recharge->save();
  66. } catch (ValidationException $e) {
  67. return $this->error($e->validator->errors()->first());
  68. } catch (Exception $e) {
  69. return $this->error($e->getMessage());
  70. }
  71. }
  72. }