wesmiler 2 년 전
부모
커밋
6778604b40
3개의 변경된 파일126개의 추가작업 그리고 152개의 파일을 삭제
  1. 12 0
      app/Services/Api/AcceptorService.php
  2. 104 152
      app/Services/Api/MemberService.php
  3. 10 0
      resources/lang/zh-cn/api.php

+ 12 - 0
app/Services/Api/AcceptorService.php

@@ -447,9 +447,15 @@ class AcceptorService extends BaseService
         $usdt = isset($info['usdt']) ? floatval($info['usdt']) : 0;
         $quota = isset($info['quota']) ? floatval($info['quota']) : 0;
         $status = isset($info['status']) ? $info['status'] : 0;
+        $tradeStatus = isset($info['trade_status']) ? $info['trade_status'] : 0;
         $acceptId = isset($info['accept_id']) ? $info['accept_id'] : 0;
         $userInfo = isset($info['member']) ? $info['member'] : [];
         if ($acceptId <= 0 || empty($info) || $status != 2) {
+            $this->error = 2039;
+            return false;
+        }
+
+        if (in_array($tradeStatus,[2,4])) {
             $this->error = 2015;
             return false;
         }
@@ -457,6 +463,7 @@ class AcceptorService extends BaseService
         // 提现账户
         $trcUrl = isset($userInfo['trc_url']) ? $userInfo['trc_url'] : '';
         if (empty($trcUrl)) {
+            $this->error = 2403;
             return false;
         }
 
@@ -466,6 +473,11 @@ class AcceptorService extends BaseService
         $orderNo = get_order_num('DP');
         if ($coinType == 1) {
             $payUsdt = $money;
+            if ($money > $usdt) {
+                $this->error = lang(2040, ['money' => $usdt]);
+                return false;
+            }
+
             $updateData = ['usdt' => DB::raw("usdt - {$money}"), 'update_time' => time()];
             if (!$this->model->where(['id' => $acceptId])->update($updateData)) {
                 DB::rollBack();

+ 104 - 152
app/Services/Api/MemberService.php

@@ -1183,237 +1183,189 @@ class MemberService extends BaseService
     {
         $money = isset($params['money'])? floatval($params['money']) : 0;
         $payPassword = isset($params['pay_password'])? trim($params['pay_password']) : '';
-        $payType = isset($params['pay_type']) && $params['pay_type']? intval($params['pay_type']) : 10;
-        $bankId = isset($params['bank_id']) && $params['bank_id']? intval($params['bank_id']) : 0;
-        $type = isset($params['type']) && $params['type']? intval($params['type']) : 1;
+        $userType = isset($params['user_type']) && $params['user_type']? intval($params['user_type']) : 1;
         if($money<=0){
-            $this->error = 2031;
+            $this->error = 2401;
             return false;
         }
 
-        if(!in_array($payType, [10,20,50])){
-            $this->error = 2425;
+        if(!in_array($userType,[1,2])){
+            $this->error = 2404;
             return false;
         }
 
         $userInfo = $this->model->with(['merchant'])
             ->where(['id'=> $userId,'mark'=>1])
-            ->select(['id','nickname','balance','pay_password','wxpay_qrcode','alipay_qrcode','status'])
+            ->select(['id','nickname','usdt','pay_password','status'])
             ->first();
         $status = isset($userInfo['status'])? $userInfo['status'] : 0;
-        $balance = isset($userInfo['balance'])? $userInfo['balance'] : 0;
+        $userUsdt = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
         $userPayPassword = isset($userInfo['pay_password'])? $userInfo['pay_password'] : '';
         $merchant = isset($userInfo['merchant'])? $userInfo['merchant'] : [];
-        $merchBalance = isset($merchant['balance'])? $merchant['balance'] : 0;
-        $merchPayPassword = isset($merchant['pay_password'])? $merchant['pay_password'] : '';
+        $merchantUsdt = isset($merchant['usdt'])? $merchant['usdt'] : 0;
+        $merchantId = isset($merchant['id'])? $merchant['id'] : 0;
+        $merchantTradeStatus = isset($merchant['trade_status'])? $merchant['trade_status'] : 0;
         if(empty($userInfo) || $status != 1){
             $this->error = 2024;
             return false;
         }
 
-        // 验证提现类型金额
-        $qrcode = '';
-        $account = '';
-        if($type == 2){
-            // 支付密码验证
-            if(empty($merchPayPassword)){
-                $this->error ='1042';
-                return false;
-            }
-            $payPassword = get_password($payPassword);
-            if($payPassword != $merchPayPassword){
-                $this->error ='1043';
-                return false;
-            }
-
-            if(empty($merchant)){
-                $this->error = 2646;
-                return false;
-            }
-
-            if($money>$merchBalance){
-                $this->error = 2647;
-                return false;
-            }
-
-            $wxpayQrcode = isset($merchant['wxpay_qrcode'])? $merchant['wxpay_qrcode'] : '';
-            $alipayQrcode = isset($merchant['alipay_qrcode'])? $merchant['alipay_qrcode'] : '';
-            if($payType == 10){
-                $qrcode = $wxpayQrcode;
-                if(empty($wxpayQrcode)){
-                    $this->error = 2649;
-                    return false;
-                }
-            }
-
-            if($payType == 20){
-                $qrcode = $alipayQrcode;
-                if(empty($alipayQrcode)) {
-                    $this->error = 2649;
-                    return false;
-                }
-            }
-
-        }else{
-            // 支付密码验证
-            if(empty($userPayPassword)){
-                $this->error ='1039';
-                return false;
-            }
-            $payPassword = get_password($payPassword);
-            if($payPassword != $userPayPassword){
-                $this->error ='1038';
-                return false;
-            }
-
-            if($money>$balance){
-                $this->error = 2648;
-                return false;
-            }
-
-            $wxpayQrcode = isset($userInfo['wxpay_qrcode'])? $userInfo['wxpay_qrcode'] : '';
-            $alipayQrcode = isset($userInfo['alipay_qrcode'])? $userInfo['alipay_qrcode'] : '';
-            if($payType == 10){
-                $qrcode = $wxpayQrcode;
-                if(empty($wxpayQrcode)) {
-                    $this->error = 2420;
-                    return false;
-                }
-            }
+        if($userType == 2 && (empty($merchant) || !in_array($merchantTradeStatus,[1,2]))){
+            $this->error = 2024;
+            return false;
+        }
 
-            if($payType == 20){
-                $qrcode = $alipayQrcode;
-                if(empty($alipayQrcode)){
-                    $this->error = 2421;
-                    return false;
-                }
-            }
+        // 提现金额验证
+        $accountUsdt = $userType==1? $userUsdt : $merchantUsdt;
+        if ($money > $accountUsdt) {
+            $this->error = web_lang(2402, ['money' => $accountUsdt]);
+            return false;
+        }
 
-            if($payType == 50){
-                $bankInfo = MemberBankModel::where(['id'=> $bankId,'mark'=>1])
-                    ->select(['realname','bank_name','bank_card'])
-                    ->first();
-                $bankInfo = $bankInfo? $bankInfo->toArray() : [];
-                $bankInfo = array_values($bankInfo);
-                if(empty($bankInfo)){
-                    $this->error = 2422;
-                    return false;
-                }else {
-                    $account = $bankInfo? implode(' ', $bankInfo) : '';
-                }
-            }
+        // 提现账户
+        $trcUrl = isset($userInfo['trc_url']) ? $userInfo['trc_url'] : '';
+        if (empty($trcUrl)) {
+            $this->error = 2403;
+            return false;
+        }
 
+        if($userPayPassword != get_password($payPassword)){
+            $this->error = 2038;
+            return false;
+        }
 
+        $cacheKey = "caches:member:withdraw:lock_{$userId}";
+        if(RedisService::get($cacheKey)){
+            $this->error = 1034;
+            return false;
         }
 
-        // 提现订单
+        DB::beginTransaction();
+        RedisService::set($cacheKey, $userInfo, rand(2,3));
+
+        // 提现记录
         $orderNo = get_order_num('DW');
         $data = [
             'order_no'=> $orderNo,
-            'user_id'=> $userId,
+            'user_id'=> $userType==1? $userId : $merchantId,
             'type'=> 2,
-            'user_type'=> $type,
+            'user_type'=> $userType,
+            'coin_type'=> 1,
             'money'=> $money,
-            'actual_money'=> 0,
-            'qrcode'=> $qrcode,
-            'account'=> $account,
-            'pay_type'=> $payType,
+            'actual_money'=> $money,
+            'trc_url'=> $trcUrl,
+            'pay_type'=> 20,
+            'date'=> date('Y-m-d'),
             'create_time'=> time(),
             'update_time'=> time(),
             'status'=> 1,
             'mark'=> 1,
         ];
 
-        // 提现记录
-        DB::beginTransaction();
         if(!$id = BalanceLogModel::insertGetId($data)){
             DB::rollBack();
-            $this->error = 2033;
+            $this->error = 2405;
             return false;
         }
 
         // 商户扣款
-        if($type == 2){
-            $updateData = ['balance'=>DB::raw("balance - {$money}"),'update_time'=> time()];
+        if($userType == 2){
+            $updateData = ['usdt'=>DB::raw("usdt - {$money}"),'update_time'=> time()];
             if(!MerchantModel::where(['user_id'=> $userId,'mark'=>1])->update($updateData)){
                 DB::rollBack();
-                $this->error = 2423;
+                $this->error = 2406;
                 return false;
             }
 
-            /*$log = [
-                'user_id' => 0,
-                'merch_id' => $merchant['id'],
+            // 明细
+            $log = [
+                'user_id' => $merchantId,
                 'source_uid' => $userId,
                 'source_order_no' => $orderNo,
-                'type' => 12,
-                'coin_type' => 4,
+                'type' => 5,
+                'coin_type' => 1,
                 'user_type'=> 2,
                 'money' => -$money,
-                'balance' => $merchBalance,
+                'actual_money' => -$money,
+                'balance' => $merchantUsdt,
                 'create_time' => time(),
                 'update_time' => time(),
-                'remark' => "商户余额提现",
+                'remark' => "商户账户余额提现",
                 'status' => 1,
                 'mark' => 1,
-            ];*/
+            ];
+
+            if (!AccountLogModel::insertGetId($log)) {
+                $this->error = 2407;
+                DB::rollBack();
+                return false;
+            }
         }
         // 用户扣款
         else{
-            $updateData = ['balance'=>DB::raw("balance - {$money}"),'update_time'=> time()];
+            $updateData = ['usdt'=>DB::raw("usdt - {$money}"),'update_time'=> time()];
             if(!MemberModel::where(['id'=> $userId,'mark'=>1])->update($updateData)){
                 DB::rollBack();
-                $this->error = 2423;
+                $this->error = 2406;
                 return false;
             }
 
-            /*$log = [
+            // 明细
+            $log = [
                 'user_id' => $userId,
-                'merch_id' => 0,
                 'source_uid' => 0,
                 'source_order_no' => $orderNo,
-                'type' => 11,
-                'coin_type' => 4,
+                'type' => 5,
+                'coin_type' => 1,
                 'user_type'=> 1,
                 'money' => -$money,
-                'balance' => $balance,
+                'actual_money' => -$money,
+                'balance' => $userUsdt,
                 'create_time' => time(),
                 'update_time' => time(),
-                'remark' => "账户余额提现",
+                'remark' => "USDT余额提现",
                 'status' => 1,
                 'mark' => 1,
-            ];*/
+            ];
+
+            if (!AccountLogModel::insertGetId($log)) {
+                $this->error = 2407;
+                DB::rollBack();
+                return false;
+            }
         }
 
-        // 推送消息
-        $pushData = [
-            'title' => '提现申请提交成功',
-            'body' => "您的提现申请已提交请耐心等候审核",
-            'type' => 3, // 1-公告通知,2-订单通知,3-交易通知,4-其他
-            'content' => [
-                'order_no' => ['name' => '订单号', 'text' => $orderNo],
-                'pay_time' => ['name' => '申请时间', 'text' => date('Y-m-d H:i:s')],
-                'pay_type' => ['name' => '付款方式', 'text' => $payType==10?'微信支付':($payType==20?'支付宝':'银行卡')],
-                'money' => ['name' => '提现金额', 'text' => $money],
-                'status' => ['name' => '状态', 'text' => '待审核'],
-            ],
-            'click_type' => 'payload',
-            'url' => '',
-        ];
+        DB::commit();
 
-        $merchId = isset($merchant['id'])? $merchant['id'] : 0;
-        if($type == 2 && $merchId){
-            PushService::make()->pushMessageByUser($merchId, $pushData, 2);
-        }else{
-            PushService::make()->pushMessageByUser($userId, $pushData);
+        // 站内消息
+        $dateTime = date('Y-m-d H:i:s');
+        $title = $userType == 1 ? 'USDT余额提现申请成功' : '商户余额提现申请成功';
+        $message = $userType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT余额成功,请耐心等候审核!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}USDT商户余额成功,请耐心等候审核!!!";
+        MessageService::make()->pushMessage($userId,    $title, $message);
+
+        // 提现自动审核,低于该金额自动审核
+        $autoCheckUsdt = ConfigService::make()->getConfigByCode('withdraw_auto_money', 300);
+        $autoCheckUsdt = $autoCheckUsdt > 0 ? $autoCheckUsdt : 0;
+        if ($money <= $autoCheckUsdt) {
+            // 打款处理
+            $result = WalletService::make()->usdtTrcTransfer($trcUrl, $money);
+            $txID = isset($result['txId']) ? $result['txId'] : '';
+            $payAddress = isset($result['address']) ? $result['address'] : '';
+            if ($txID && $payAddress) {
+                $updateData = ['hash'=> $txID,'wallet_url'=> $payAddress,'audit_remark'=>'自动审核打款','status'=>2,'update_time'=>time()];
+                if($this->model->where(['order_no'=> $orderNo,'user_type'=> $userType])->update($updateData)){
+                    $title = $userType == 1 ? 'USDT余额提现审核成功' : '商户余额提现审核成功';
+                    $message = $userType == 1 ? "您在{$dateTime}(UTC+8)申请提现{$money}USDT余额审核成功,请耐心等候打款到账!!!" : "您在{$dateTime}(UTC+8)申请提现{$money}USDT商户余额审核成功,请耐心等候打款到账!!!";
+                    MessageService::make()->pushMessage($userId, $title, $message);
+                }
+            }
         }
 
-        DB::commit();
-        $this->error = 2424;
+        $this->error = $title;
         return [
             'id'=> $id,
             'money'=> $money,
-            'pay_type'=> $payType,
+            'user_type'=> $userType,
         ];
     }
 

+ 10 - 0
resources/lang/zh-cn/api.php

@@ -79,6 +79,7 @@ return [
     '2036'=> 'USDT余额扣除失败,请刷新重试~',
     '2037'=> '充值成功',
     '2038'=> '交易密码错误',
+    '2039'=> '账户未入驻或非法,请联系客服',
 
     '2040'=> '抱歉,您还未获得开播权限,请先升级',
     '2041'=> '开播成功',
@@ -104,6 +105,15 @@ return [
     '2305'=> '打赏支付失败',
     '2306'=> '打赏成功',
 
+    '2401'=>'请填写提现金额',
+    '2402'=>'提现金额不能超过账户USDT余额',
+    '2403'=>'提现账户地址未绑定,请先到用户中心绑定地址',
+    '2404'=>'提现账户类型错误',
+    '2405'=>'创建提现订单失败',
+    '2406'=>'提现账户扣款失败',
+    '2407'=>'提现账户处理失败',
+    '2408'=> '',
+
     
     '我正在直播,快来看看吧'=>'我正在直播,快来看看吧',
     '打赏消费通知'=>'打赏消费通知',