wesmiler 1 år sedan
förälder
incheckning
70c77fb2d5

+ 6 - 1
app/Http/Controllers/Admin/RechargeController.php

@@ -72,6 +72,11 @@ class RechargeController extends Backend
      * @return mixed
      */
     public function auth(){
-        return $this->service->rechargeAuth();
+        $params = request()->post();
+        if(!$result = BalanceLogService::make()->rechargeAuth($params)){
+            return showJson(BalanceLogService::make()->getError(), false);
+        }else{
+            return showJson(BalanceLogService::make()->getError(), true);
+        }
     }
 }

+ 6 - 1
app/Http/Controllers/Admin/WithdrawController.php

@@ -71,6 +71,11 @@ class WithdrawController extends Backend
      * @return mixed
      */
     public function auth(){
-        return $this->service->auth();
+        $params = request()->post();
+        if(!$result = BalanceLogService::make()->withdrawAuth($params)){
+            return showJson(BalanceLogService::make()->getError(), false);
+        }else{
+            return showJson(BalanceLogService::make()->getError(), true);
+        }
     }
 }

+ 426 - 0
app/Services/Common/BalanceLogService.php

@@ -19,6 +19,7 @@ use App\Models\MerchantModel;
 use App\Services\Api\FinanceService;
 use App\Services\Api\MessageService;
 use App\Services\BaseService;
+use App\Services\RedisService;
 use App\Services\WalletService;
 use Illuminate\Support\Facades\DB;
 
@@ -30,6 +31,9 @@ use Illuminate\Support\Facades\DB;
  */
 class BalanceLogService extends BaseService
 {
+    // 静态对象
+    protected static $instance = null;
+
     /**
      * 构造函数
      * @author laravel开发员
@@ -41,6 +45,18 @@ class BalanceLogService extends BaseService
     }
 
     /**
+     * 静态入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = (new static());
+        }
+        return self::$instance;
+    }
+
+    /**
      * 获取列表
      * @param $params 参数
      * @param int $pageSize 分页大小:默认 15
@@ -212,6 +228,416 @@ class BalanceLogService extends BaseService
     }
 
     /**
+     * 充值审核
+     * @param $params
+     * @return bool
+     */
+    public function rechargeAuth($params)
+    {
+        $id = isset($params['id'])? $params['id'] : 0;
+        $checkStatus = isset($params['status'])? $params['status'] : 0;
+        $remark = isset($params['audit_remark'])? trim($params['audit_remark']) : '';
+        $payImg = isset($params['pay_img'])? trim($params['pay_img']) : '';
+
+        $info = $this->model->with(['member','merchant','acceptor'])->where(['id'=> $id,'mark'=>1])->first();
+        $type = isset($info['type'])? $info['type'] : 0;
+        $userType = isset($info['user_type'])? $info['user_type'] : 0;
+        $coinType = isset($info['coin_type'])? $info['coin_type'] : 0;
+        $payType = isset($info['pay_type'])? $info['pay_type'] : 0;
+        $accountId = isset($info['user_id'])? $info['user_id'] : 0;
+        $money = isset($info['money'])? $info['money'] : 0;
+        $actualMoney = isset($info['actual_money'])? $info['actual_money'] : 0;
+        $status = isset($info['status'])? $info['status'] : 0;
+        if(empty($info) || $accountId<=0){
+            $this->error = 4001;
+            return false;
+        }
+
+        if($status != 1){
+            $this->error = 4002;
+            return false;
+        }
+
+        if($type != 1){
+            $this->error = 1031;
+            return false;
+        }
+        $cacheKey ="caches:recharge:lock_{$id}";
+        if(RedisService::get($cacheKey)){
+            $this->error = 1034;
+            return false;
+        }
+
+        // 绑定的用户ID
+        $userId = $accountId;
+        $userInfo = isset($info['member'])? $info['member'] : [];
+        $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
+        if($userType == 2){
+            $userInfo = isset($info['merchant'])? $info['merchant'] : [];
+            $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
+            $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
+        }else if($userType == 3){
+            $userInfo = isset($info['acceptor'])? $info['acceptor'] : [];
+            $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
+            $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
+        }
+
+        if(empty($userInfo)){
+            $this->error = 4004;
+            return false;
+        }
+
+        // 审核处理
+        RedisService::set($cacheKey, true);
+        $updateData = ['status'=> $checkStatus,'audit_remark'=> $remark,'update_time'=> time()];
+        DB::beginTransaction();
+        if(!$this->model->where(['id'=> $id])->update($updateData)){
+            DB::rollBack();
+            $this->error = 1072;
+            RedisService::clear($cacheKey);
+            return false;
+        }
+
+        // 审核通过到账处理
+        $title = '';
+        $message = '';
+        $dateTime = date('Y-m-d H:i:s');
+        $coinTypes = [1=>'USDT余额',2=>'星豆余额',3=>'交易额度'];
+        $accountTypes = [1=>'会员账户',2=>'商家账户',3=>'承兑商账户'];
+        $coinName = isset($coinTypes[$coinType])? $coinTypes[$coinType] : '账户';
+        $accountName = isset($accountTypes[$userType])? $accountTypes[$userType] : '会员账户';
+        if($status == 2) {
+            // 线下交易
+            if($payType == 30){
+                if(!in_array($userType,[1,3]) && !in_array($coinType,[1,6])){
+                    DB::rollBack();
+                    $this->error = 1021;
+                    RedisService::clear($cacheKey);
+                    return false;
+                }
+
+                // USDT入账
+                if($userType == 1 && $coinType == 1){
+                    $updateData = ['usdt' => DB::raw("usdt + {$actualMoney}"),'update_time'=>time()];
+                    if (!MemberModel::where(['id' => $accountId])->update($updateData)){
+                        DB::rollBack();
+                        $this->error = 1072;
+                        RedisService::clear($cacheKey);
+                        return false;
+                    }
+                }
+                // 交易额度入账
+                else if($userType == 3 && $coinType == 6){
+                    $updateData = ['quota' => DB::raw("quota + {$actualMoney}"),'update_time'=>time()];
+                    if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
+                        DB::rollBack();
+                        $this->error = 1072;
+                        RedisService::clear($cacheKey);
+                        return false;
+                    }
+                }
+
+                // 账户明细
+                $log = [
+                    'user_id' => $accountId,
+                    'source_id' => 0,
+                    'source_order_no' => $info['order_no'],
+                    'type' => 5,
+                    'coin_type' => $coinType,
+                    'user_type'=> $userType,
+                    'money' => $money,
+                    'actual_money' => $actualMoney,
+                    'balance' => $balance,
+                    'create_time' => time(),
+                    'update_time' => time(),
+                    'remark' => "{$coinName}充值",
+                    'status' => 1,
+                    'mark' => 1,
+                ];
+                if(!AccountLogModel::insertGetId($log)){
+                    DB::rollBack();
+                    $this->error = 2029;
+                    RedisService::clear($cacheKey);
+                    return false;
+                }
+
+            }else{
+                DB::rollBack();
+                $this->error = 1021;
+                RedisService::clear($cacheKey);
+                return false;
+            }
+
+            $title = "{$coinName}充值审核成功通知";
+            $message = "您的充值申请在{$dateTime}UTC+8审核成功,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n金额:{$money}\n到账:{$actualMoney}\n审核状态:成功\n审核说明:{$remark}";
+
+        }else{
+            $title = "{$coinName}充值审核失败通知";
+            $message = "您的充值申请在{$dateTime}UTC+8审核失败,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n金额:{$money}\n到账:{$actualMoney}\n审核状态:未通过\n审核说明:{$remark}";
+        }
+
+        // 消息通知
+        MessageService::make()->pushMessage($userId, $title, $message, 3);
+
+        DB::commit();
+        $this->error = 1071;
+        return true;
+    }
+
+    /**
+     * 提现审核
+     * @param $params
+     * @return bool
+     */
+    public function withdrawAuth($params)
+    {
+        $id = isset($params['id'])? $params['id'] : 0;
+        $checkStatus = isset($params['status'])? $params['status'] : 0;
+        $remark = isset($params['audit_remark'])? trim($params['audit_remark']) : '';
+        $payImg = isset($params['pay_img'])? trim($params['pay_img']) : '';
+
+        $info = $this->model->with(['member','merchant','acceptor'])->where(['id'=> $id,'mark'=>1])->first();
+        $type = isset($info['type'])? $info['type'] : 0;
+        $userType = isset($info['user_type'])? $info['user_type'] : 0;
+        $coinType = isset($info['coin_type'])? $info['coin_type'] : 0;
+        $payType = isset($info['pay_type'])? $info['pay_type'] : 0;
+        $accountId = isset($info['user_id'])? $info['user_id'] : 0;
+        $money = isset($info['money'])? $info['money'] : 0;
+        $actualMoney = isset($info['actual_money'])? $info['actual_money'] : 0;
+        $fee = isset($info['fee'])? $info['fee'] : 0;
+        $status = isset($info['status'])? $info['status'] : 0;
+        if(empty($info) || $accountId<=0){
+            $this->error = 4001;
+            return false;
+        }
+
+        if($status != 1){
+            $this->error = 4002;
+            return false;
+        }
+
+        if($type != 2){
+            $this->error = 1031;
+            return false;
+        }
+        $cacheKey ="caches:withdraw:lock_{$id}";
+        if(RedisService::get($cacheKey)){
+            $this->error = 1034;
+            return false;
+        }
+
+        // 绑定的用户ID
+        $userId = $accountId;
+        $userInfo = isset($info['member'])? $info['member'] : [];
+        $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
+        if($userType == 2){
+            $userInfo = isset($info['merchant'])? $info['merchant'] : [];
+            $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
+            $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
+        }else if($userType == 3){
+            $userInfo = isset($info['acceptor'])? $info['acceptor'] : [];
+            $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0;
+            $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
+        }
+
+        if(empty($userInfo)){
+            $this->error = 4004;
+            return false;
+        }
+
+        // 审核处理
+        RedisService::set($cacheKey, true);
+        DB::beginTransaction();
+
+        // 审核通过到账处理
+        $title = '';
+        $message = '';
+        $dateTime = date('Y-m-d H:i:s');
+        $accountTypes = [1=>'会员账户',2=>'商家账户',3=>'承兑商账户'];
+        $coinName = 'USDT余额';
+        if($userType == 2 && $coinType==1){
+            $coinName = 'USDT佣金';
+        }else if($userType == 3 && $coinType==1){
+            $coinName = 'USDT佣金';
+        }else if($userType == 3 && $coinType==6){
+            $coinName = '交易额度';
+        }
+        $accountName = isset($accountTypes[$userType])? $accountTypes[$userType] : '会员账户';
+        if($status == 2) {
+            // USDT链上打款
+            $hash = '';
+            if($payType == 20){
+                $trcUrl = isset($userInfo['trc_url'])? $userInfo['trc_url'] : '';
+                if(empty($trcUrl)){
+                    DB::rollBack();
+                    $this->error = 4005;
+                    RedisService::clear($cacheKey);
+                    return false;
+                }
+
+                $result     = WalletService::make()->usdtTrcTransfer($trcUrl, $actualMoney);
+                $hash       = isset($result['txId']) ? $result['txId'] : '';
+                if(empty($hash)){
+                    DB::rollBack();
+                    $this->error = 4005;
+                    RedisService::clear($cacheKey);
+                    return false;
+                }
+                $payAddress = isset($result['address']) ? $result['address'] : '';
+                $updateData = ['status'=>2,'audit_remark'=>$remark,'pay_img'=> get_image_path($payImg),'hash' => $hash, 'wallet_url' => $payAddress,'pay_status'=>20,'pay_at'=> $dateTime, 'update_time' => time()];
+                if(!$this->model->where(['id'=> $id])->update($updateData)){
+                    DB::rollBack();
+                    $this->error = 4006;
+                    RedisService::clear($cacheKey);
+                    return false;
+                }
+            }
+            // 线下打款
+            else if($payType == 30){
+                $updateData = ['status'=> 2,'pay_status'=>20,'pay_at'=>$dateTime,'pay_img'=> get_image_path($payImg),'audit_remark'=> $remark,'update_time'=> time()];
+                if(!$this->model->where(['id'=> $id])->update($updateData)){
+                    DB::rollBack();
+                    $this->error = 1072;
+                    RedisService::clear($cacheKey);
+                    return false;
+                }
+            }else{
+                DB::rollBack();
+                $this->error = 1021;
+                RedisService::clear($cacheKey);
+                return false;
+            }
+
+            // 平台手续费明细
+            if($fee>0){
+                $log = [
+                    'user_id'         => 0,
+                    'source_id'       => $accountId,
+                    'source_order_no' => $info['order_no'],
+                    'type'            => 5,
+                    'coin_type'       => $coinType,
+                    'user_type'       => 4,
+                    'money'           => $fee,
+                    'actual_money'    => $fee,
+                    'balance'         => 0,
+                    'create_time'     => time(),
+                    'update_time'     => time(),
+                    'hash'            => $hash,
+                    'remark'          => "{$coinName}提现",
+                    'status'          => 1,
+                    'mark'            => 1,
+                ];
+                if(!AccountLogModel::insertGetId($log)){
+                    DB::rollBack();
+                    $this->error = 2029;
+                    RedisService::clear($cacheKey);
+                    return false;
+                }
+                FinanceService::make()->saveLog(0, $fee, 1);
+            }
+
+            $title = "{$coinName}提现审核成功通知";
+            $message = "您的提现申请在{$dateTime}UTC+8审核成功,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n提现金额:{$money}\n到账:{$actualMoney}\n审核状态:审核成功\n审核说明:{$remark}";
+        }
+        // 审核失败驳回退款
+        else{
+            if(!in_array($userType,[1,2,3]) && !in_array($coinType,[1,6])){
+                DB::rollBack();
+                $this->error = 1021;
+                RedisService::clear($cacheKey);
+                return false;
+            }
+
+            $updateData = ['status'=> 3,'pay_img'=> get_image_path($payImg),'audit_remark'=> $remark,'update_time'=> time()];
+            if(!$this->model->where(['id'=> $id])->update($updateData)){
+                DB::rollBack();
+                $this->error = 1072;
+                RedisService::clear($cacheKey);
+                return false;
+            }
+
+            // 会员:USDT驳回入账
+            if($userType == 1 && $coinType == 1){
+                $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
+                $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
+                if (!MemberModel::where(['id' => $accountId])->update($updateData)){
+                    DB::rollBack();
+                    $this->error = 1072;
+                    RedisService::clear($cacheKey);
+                    return false;
+                }
+            }
+            // 商家:佣金入账
+            else if($userType == 2 && $coinType == 1){
+                $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
+                $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
+                if (!MerchantModel::where(['id' => $accountId])->update($updateData)){
+                    DB::rollBack();
+                    $this->error = 1072;
+                    RedisService::clear($cacheKey);
+                    return false;
+                }
+            }
+            // 承兑商:佣金入账
+            else if($userType == 3 && $coinType == 1){
+                $balance = isset($userInfo['usdt'])? $userInfo['usdt'] : 0;
+                $updateData = ['usdt' => DB::raw("usdt + {$money}"),'update_time'=>time()];
+                if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
+                    DB::rollBack();
+                    $this->error = 1072;
+                    RedisService::clear($cacheKey);
+                    return false;
+                }
+            }
+            // 承兑商:交易额度入账
+            else if($userType == 3 && $coinType == 6){
+                $balance = isset($userInfo['quota'])? $userInfo['quota'] : 0;
+                $updateData = ['quota' => DB::raw("quota + {$money}"),'update_time'=>time()];
+                if (!AcceptorModel::where(['id' => $accountId])->update($updateData)){
+                    DB::rollBack();
+                    $this->error = 1072;
+                    RedisService::clear($cacheKey);
+                    return false;
+                }
+            }
+
+            // 账户明细
+            $log = [
+                'user_id' => $accountId,
+                'source_id' => 0,
+                'source_order_no' => $info['order_no'],
+                'type' => 5,
+                'coin_type' => $coinType,
+                'user_type'=> $userType,
+                'money' => $money,
+                'actual_money' => $money,
+                'balance' => $balance,
+                'create_time' => time(),
+                'update_time' => time(),
+                'remark' => "{$coinName}提现驳回",
+                'status' => 1,
+                'mark' => 1,
+            ];
+            if(!AccountLogModel::insertGetId($log)){
+                DB::rollBack();
+                $this->error = 2029;
+                RedisService::clear($cacheKey);
+                return false;
+            }
+
+            $title = "{$coinName}提现审核失败通知";
+            $message = "您的提现申请在{$dateTime}UTC+8审核失败,提现金额已退回对应账户,明细如下:\n单号:{$info['order_no']}\n账户:{$accountName}\n提现金额:{$money}\n到账:{$actualMoney}\n审核状态:未通过\n审核说明:{$remark}";
+        }
+
+        // 消息通知
+        MessageService::make()->pushMessage($userId, $title, $message, 3);
+
+        DB::commit();
+        $this->error = 1071;
+        return true;
+    }
+
+    /**
      * 添加会编辑会员
      * @return array
      * @since 2020/11/11

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

@@ -70,6 +70,8 @@ return [
     '1068' => '获取授权信息失败,用户账号或已注销',
     '1069' => '分享成功',
     '1070' => '分享失败',
+    '1071' => '审核成功',
+    '1072' => '审核失败',
 
     // 登录注册
     '2001'=> '账号非法或未注册',
@@ -309,6 +311,13 @@ return [
     '3450'=> '请选择好友',
     '3451'=> '没有有效的好友',
 
+    '4001'=> '记录不存在',
+    '4002'=> '记录已审核处理',
+    '4003'=> '类型参数错误',
+    '4004'=> '账户信息不存在',
+    '4005'=> '用户未绑定钱包地址',
+    '4006'=> '审核打款处理失败',
+
     '112009'=> '供应商账户余额不足,请联系客服',
     '我正在直播,快来看看吧'=>'我正在直播,快来看看吧',
     '打赏消费通知'=>'打赏消费通知',