Przeglądaj źródła

修改提现、层级通道

lip 14 godzin temu
rodzic
commit
5494f5f05d

+ 14 - 2
app/Http/Controllers/admin/PaymentOrder.php

@@ -98,6 +98,7 @@ class PaymentOrder extends Controller
         return $this->success();
     }
 
+    //提现审核
     public function audit()
     {
         DB::beginTransaction();
@@ -106,6 +107,7 @@ class PaymentOrder extends Controller
                 'ids' => ['required', 'array', 'min:1', 'max:20'],
                 'ids.*' => ['required', 'integer', 'min:1'],
                 'status' => ['required', 'integer', 'in:1,3'],
+                'is_rgtx' => ['nullable', 'integer', 'in:0,1'],
             ];
             $status = request()->input('status', null);
             if ($status != 1) {
@@ -117,8 +119,18 @@ class PaymentOrder extends Controller
             $count = 0;
             foreach ($params['ids'] as $id) {
                 if ($params['status'] == 1) {
-                    $ret = PaymentOrderService::createPayout($id);
-                    if ($ret['code'] !== 0) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
+                    if (!empty($params['is_rgtx'])) {
+                        $order = PaymentOrderModel::where('id', $id)
+                            ->where('type', 4)
+                            ->where('status', PaymentOrderService::STATUS_STAY)
+                            ->first();
+                        if (!$order) throw new Exception("订单不存在_{$id}", HttpStatus::CUSTOM_ERROR);
+                        $order->status = PaymentOrderService::STATUS_SUCCESS;
+                        $order->save();
+                    } else {
+                        $ret = PaymentOrderService::createPayout($id);
+                        if ($ret['code'] !== 0) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
+                    }
                 } else {
                     $ret = PaymentOrderService::withdrawalFailed($id, $remark);
                     if ($ret['code'] !== 0) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);

+ 12 - 3
app/Http/Controllers/admin/RechargeChannel.php

@@ -14,7 +14,7 @@ class RechargeChannel extends Controller
     //获取充值方式
     public function getChannel()
     {
-        $channel = RechargeChannelModel::getChannel();
+        $channel = RechargeChannelModel::getChannel(1);
         return $this->success(['total' => count($channel), 'data' => $channel]);
     }
 
@@ -33,7 +33,9 @@ class RechargeChannel extends Controller
                 ->forPage($page, $limit)
                 ->get();
             foreach($list as &$item) {
-                $item->rechargeChannel = RechargeChannelModel::getChannel($item['type']);
+                $item->rechargeType = RechargeChannelModel::getChannel(1, $item['recharge_type']);
+                $item->withdrawType = RechargeChannelModel::getChannel(2, $item['withdraw_type']);
+                $item->activityType = RechargeChannelModel::getChannel(3, $item['activity_type']);
             }
         } catch (Exception $e) {
             return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
@@ -50,7 +52,9 @@ class RechargeChannel extends Controller
             $params = request()->validate([
                 'id' => ['nullable','integer'],
                 'name' => ['required','string'],
-                'type' => ['required','array'],
+                'recharge_type' => ['required','array'],
+                'withdraw_type' => ['required','array'],
+                'activity_type' => ['nullable','array'],
             ]);
             
             $params['type'] = implode(',', $params['type']);
@@ -78,6 +82,7 @@ class RechargeChannel extends Controller
             $params = request()->validate([
                 'page' => ['nullable', 'integer', 'min:1'],
                 'limit' => ['nullable', 'integer', 'min:1'],
+                'data_type' => ['nullable', 'string'],
                 'type' => ['nullable', 'string'],
                 'from' => ['nullable', 'integer'],
                 'key' => ['nullable', 'string'],
@@ -87,6 +92,9 @@ class RechargeChannel extends Controller
             $limit = request()->input('limit', 15);
 
             $query = new RechargeChannelModel();
+            if (!empty($params['data_type'])) {
+                $query = $query->where('data_type', $params['data_type']);
+            }
             if (!empty($params['type'])) {
                 $query = $query->where('type', $params['type']);
             }
@@ -121,6 +129,7 @@ class RechargeChannel extends Controller
                 'from' => ['nullable','integer'],
                 'key' => ['nullable','string'],
                 'name' => ['nullable','string'],
+                'data_type' => ['required','string'],
                 'type' => ['required','string'],
                 'rate' => ['required','numeric'],
                 'min' => ['nullable','integer'],

+ 62 - 14
app/Http/Controllers/api/Wallet.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\api;
 
 use App\Constants\Util;
+use App\Constants\HttpStatus;
 use App\Services\WalletService;
 use App\Services\ConfigService;
 use App\Models\Config;
@@ -17,8 +18,8 @@ use App\Models\PaymentOrder;
 use App\Services\BalanceLogService;
 use App\Services\PaymentOrderService;
 use App\Services\QianBaoWithdrawService;
-use App\Services\Payment\QianBaoService;
 use App\Services\WithdrawService;
+use Illuminate\Support\Facades\DB;
 
 
 
@@ -41,7 +42,7 @@ class Wallet extends BaseController
         } else {
             $recharge_channel_group_id = request()->user->recharge_channel_group_id;
         }
-        $list = RechargeChannel::getFormatChannel($recharge_channel_group_id);
+        $list = RechargeChannel::getFormatChannel(1, $recharge_channel_group_id);
         return $this->success([
             'list' => $list,
         ]);
@@ -213,14 +214,17 @@ class Wallet extends BaseController
      */
     public function withdrawChannel()
     {
-        $list = QianBaoService::withdrawChannel();
-        $data[] = ['label' => 'USDT', 'value' => 'USDT'];
-        foreach ($list as $key => $item) {
-            $data[] = ['label' => $item, 'value' => $key];
+        $member_id = request()->user->member_id;
+        if (empty(request()->user->recharge_channel_group_id)) {
+            $recharge_channel_group_id = User::where('member_id', $member_id)->value('recharge_channel_group_id');
+        } else {
+            $recharge_channel_group_id = request()->user->recharge_channel_group_id;
         }
-        return $this->success($data);
+        $list = RechargeChannel::getFormatChannel(2, $recharge_channel_group_id);
+        return $this->success($list);
     }
 
+    //USDT提现
     public function withdraw()
     {   
         try {
@@ -289,13 +293,13 @@ class Wallet extends BaseController
     
 
     /**
-     * 提现(手动到账): DF001 支付宝转卡; DF002 支付宝转支付宝; DF005数字人民币
+     * 提现(手动到账): DF001 支付宝转卡; DF002 支付宝转支付宝; DF005数字人民币; rgtx(人工提现,手动打款)
      */
     public function payout() {
         try {
             $params = request()->validate([
                 'amount' => ['required', 'numeric', 'min:0.01'],
-                'channel' => ['required', 'string', 'in:DF001,DF002,DF005'],
+                'channel' => ['required', 'string', 'in:DF001,DF002,DF005,rgtx'],
                 'bank_name' => ['required', 'string'],
                 'account' => ['required', 'string'],
                 'card_no' => ['required', 'string'],
@@ -308,12 +312,56 @@ class Wallet extends BaseController
             if (!password_verify($params['safe_word'], $user->payment_password)) {
                 throw new Exception(lang('资金密码错误'));
             }
-
-            $res = QianBaoWithdrawService::createOrder($member_id, $params['amount'], $params['channel'], $params['bank_name'], $params['account'], $params['card_no']);
-            if ($res['code'] == 0) { 
-                return $this->success($res,'提交成功');
+            if ($params['channel'] == 'rgtx') {
+                DB::beginTransaction();
+                $amount = $params['amount'];
+                try {
+                    $wallet = WalletService::findOne(['member_id' => $member_id]);
+                    if (!$wallet) throw new Exception('钱包不存在', HttpStatus::CUSTOM_ERROR);
+                    $balance = $wallet->available_balance;
+                    if (bccomp($balance, $amount, 2) < 0) {
+                        throw new Exception("您的钱包余额不足!", HttpStatus::CUSTOM_ERROR);
+                    }
+                    $available_balance = bcsub($balance, $amount, 10);
+
+                    // 先预扣款(锁定资金)
+                    $wallet->available_balance = $available_balance;
+                    if (!$wallet->save()) throw new Exception('钱包更新失败!', HttpStatus::CUSTOM_ERROR);
+
+                    $rate = RechargeChannel::where('type', 'rgtx')->value('rate');
+                    $rate = $rate ?? 1;
+                    $data = [];
+                    $data['type'] = PaymentOrderService::TYPE_SELF_PAYOUT;
+                    $data['order_no'] = PaymentOrderService::createOrderNo('rgtx' . $data['type'] . '_', $member_id);
+                    $data['member_id'] = $member_id;
+                    $data['fee'] = $amount * $rate;
+                    $data['amount'] = number_format($amount, 2, '.', '');
+                    $data['channel'] = $params['channel'];
+                    $data['bank_name'] = $params['bank_name'];
+                    $data['account'] = $params['account'];
+                    $data['card_no'] = $params['card_no'];
+                    $data['status'] = PaymentOrderService::STATUS_STAY;
+                    // 创建待处理状态的提现记录
+                    $info = PaymentOrder::create($data);
+                    // 记录余额变动日志
+                    BalanceLogService::addLog($member_id, $amount * -1, $balance, $available_balance, '人工提现', $info->id, '钱宝提现费率:'.($rate  * 100) . '%');
+
+                    $balance = bcadd($available_balance, 0, 2);
+                    DB::commit();
+                } catch (Exception $e) {
+                    DB::rollBack();
+                    if ($e->getCode() === HttpStatus::CUSTOM_ERROR) {
+                        return $this->error($e->getMessage());
+                    }
+                }
+                return $this->success($info,'提交成功');
+            } else {
+                $res = QianBaoWithdrawService::createOrder($member_id, $params['amount'], $params['channel'], $params['bank_name'], $params['account'], $params['card_no']);
+                if ($res['code'] == 0) { 
+                    return $this->success($res,'提交成功');
+                }
+                return $this->error($res['text']);
             }
-            return $this->error($res['text']);
         } catch (ValidationException $e) {
             return $this->error($e->validator->errors()->first());
         } catch (\Exception $e) {

+ 23 - 15
app/Models/RechargeChannel.php

@@ -6,7 +6,7 @@ class RechargeChannel extends BaseModel
 {
 
     protected $table = 'recharge_channel';
-    protected $fillable = ['id','key', 'name', 'type', 'rate','min','max' ,'fixed' ,'sort'];
+    protected $fillable = ['id','data_type','key', 'name', 'type', 'rate','min','max' ,'fixed' ,'sort'];
     protected $hidden = [];
 
     public function getFixedAttribute($value)
@@ -14,9 +14,9 @@ class RechargeChannel extends BaseModel
         return $value ? explode(',', $value) : null; 
     }
 
-    public static function getChannel($type = [])
+    public static function getChannel($data_type, $type = [])
     {
-        $query = self::where('status', 1);
+        $query = self::where('status', 1)->where('data_type', $data_type);
         if ($type) {
             $query = $query->whereIn('type', $type);
         }
@@ -29,6 +29,7 @@ class RechargeChannel extends BaseModel
     public static function product($from = '')
     {
         $where['status'] = 1;
+        $where['data_type'] = 1;
         if($from){
             $where['from'] = $from;
         }
@@ -36,22 +37,29 @@ class RechargeChannel extends BaseModel
         return array_column($list, null, 'key');
     }
 
-    public static function getFormatChannel($recharge_channel_group_id = '')
+    public static function getFormatChannel($data_type, $recharge_channel_group_id = 1)
     {
-        $query = self::where(['status' => 1]);
+        $query = self::where(['status' => 1, 'data_type' => $data_type]);
         
-        if ($recharge_channel_group_id) {
-            $type = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value('type');
-            if ($type) {
-                $query = $query->whereIn('type', $type);
-            }
+        $field = 'recharge_type'; //充值类型
+        if ($data_type == 2) {
+            //提现类型
+            $field = 'withdraw_type';
+        } elseif ($data_type == 3) {
+            //提现类型
+            $field = 'activity_type';
+        } 
+        $type = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value($field);
+        if ($type) {
+            $query = $query->whereIn($field, $type);
         }
-        $product = $query->orderBy('sort', 'asc')->select(['id','name','type','min','max','fixed','rate'])->get()->toArray();
+        
+        $product = $query->orderBy('sort', 'asc')->select(['id', 'data_type','name','recharge_type', 'withdraw_type', 'activity_type','min','max','fixed','rate'])->get()->toArray();
         
         $list = [];
         foreach($product as $key => $pv) {
-            if (isset($list[$pv['type']]['config'])) {
-                $config = $list[$pv['type']]['config'];
+            if (isset($list[$pv[$field]]['config'])) {
+                $config = $list[$pv[$field]]['config'];
                 if (empty($config['range'])) {
                     $config['range'][] = $config;
                 }
@@ -73,10 +81,10 @@ class RechargeChannel extends BaseModel
                 $config = $pv;
             }
             
-            $list[$pv['type']] = [
+            $list[$pv[$field]] = [
                 'key' => $key,
                 'label' => lang($pv['name']),
-                'value' => $pv['type'],
+                'value' => $pv[$field],
                 'config' => $config ?? [],
             ];
         }

+ 25 - 4
app/Models/RechargeChannelGroup.php

@@ -5,19 +5,40 @@ namespace App\Models;
 class RechargeChannelGroup extends BaseModel
 {
     protected $table = 'recharge_channel_group';
-    protected $fillable = ['name', 'type'];
+    protected $fillable = ['name', 'recharge_type', 'withdraw_type', 'activity_type'];
     protected $hidden = [];
 
     // 修改器:将逗号分隔字符串转为数组
-    public function getTypeAttribute($value)
+    public function getRechargeTypeAttribute($value)
     {
         return $value ? explode(',', $value) : []; 
     }
 
     // 设置器:将数组转为逗号分隔字符串
-    public function setTypeAttribute($value)
+    public function setRechargeAttribute($value)
     {
-        $this->attributes['type'] = is_array($value) ? implode(',', $value) : $value;
+        $this->attributes['recharge_type'] = is_array($value) ? implode(',', $value) : $value;
+    }
+
+    public function getWithdrawTypeAttribute($value)
+    {
+        return $value ? explode(',', $value) : []; 
+    }
+
+    public function setWithdrawAttribute($value)
+    {
+        $this->attributes['withdraw_type'] = is_array($value) ? implode(',', $value) : $value;
+    }
+    public function getActivityTypeAttribute($value)
+    {
+        return $value ? explode(',', $value) : []; 
+    }
+
+    public function setActivityAttribute($value)
+    {
+        if (!$value)
+            return '';
+        $this->attributes['activity_type'] = is_array($value) ? implode(',', $value) : $value;
     }
 
 }

+ 1 - 0
app/Services/PaymentOrderService.php

@@ -19,6 +19,7 @@ class PaymentOrderService extends BaseService
     const TYPE_PAY = 1; // 代收
     const TYPE_PAYOUT = 2; // 代付
     const TYPE_SELF_PAY = 3; // 手动充值
+    const TYPE_SELF_PAYOUT = 4; // 手动提现打款
 
     const STATUS_STAY = 0;  // 待处理
     const STATUS_PROCESS = 1; // 处理中