| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace App\Http\Controllers\api;
- use App\Services\WalletService;
- use App\Services\ConfigService;
- use App\Models\Config;
- use App\Models\Recharge;
- use App\Services\Payment\SanJinService;
- use Illuminate\Validation\ValidationException;
- use Exception;
- /**
- * 充值提现接口
- */
- class Wallet extends BaseController
- {
- //获取三斤充值通道(微信、支付宝、扫码充值)
- public function getChannel()
- {
- $data = SanJinService::getChannel();
- $list = [];
- foreach($data as $k => $v) {
- $list[] = [
- 'label' => lang($v),
- 'value' => $k,
- ];
- }
- return $this->success([
- 'list' => $list,
- ]);
- }
- /**
- * 获取充值二维码(USDT充值)
- */
- function scan()
- {
- $member_id = request()->user->member_id;
- $type = 'TRC20';
- $receivingType = ConfigService::getVal("receiving_type");
- //自动充值
- if ($receivingType == 1) {
- $res = WalletService::getRechargeImageAddress($member_id);
- $address = $res['address'];
- $qrCode = $res['full_path'];
- } else {
- //手动充值
- if ($type === "TRC20") {
- $address = Config::where('field', 'receiving_address')->first()->val;
- } elseif ($type === "ERC20") {
- $address = Config::where('field', 'receiving_address_erc20')->first()->val;
- } else {
- return $this->error(lang('充值类型错误'));
- }
- $res = WalletService::getPlatformImageAddress($address);
- $res['net'] = $type;
- $qrCode = $res['full_path'];
- }
-
- return $this->success([
- 'qrcode' => $qrCode,
- // 'photo' => InputFile::create($qrCode),
- ]);
- }
- /**
- * 提交充值凭证
- */
- public function recharge()
- {
- try {
- $params = request()->validate([
- 'net' => ['required', 'string'],
- 'amount' => ['required', 'float'],
- 'toAddress' => ['required', 'string'],
- 'image' => ['required', 'url'],
- ]);
- $member_id = '';
- $recharge = new Recharge();
- $recharge->member_id = $member_id;
- $recharge->net = $params['net'];
- $recharge->coin = "USDT";
- $recharge->amount = $params['amount'];
- $recharge->to_address = $params['toAddress'];
- $recharge->status = 0;
- $recharge->type = 2;
- $recharge->image = $params['image'];
- $recharge->save();
- } catch (ValidationException $e) {
- return $this->error($e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
|