Browse Source

增加提现相关接口

Jason 1 năm trước cách đây
mục cha
commit
b166e3485d

+ 126 - 0
application/api/controller/Money.php

@@ -71,6 +71,7 @@ class Money extends Api
             'user_id'   => $user['id'],
             'amount'    => $amount,
             'status'    => MoneyIn::Default,
+            'user_type' => $user['user_type'],
             'agent_id'  => $recharge_info['agent_id']
         ];
 
@@ -200,4 +201,129 @@ class Money extends Api
 
         $this->success('', $data);
     }
+
+    /**
+     * 提交提现信息
+     * @return void
+     * @throws \think\exception\DbException
+     */
+    public function withdraw_submit()
+    {
+        $type          = $this->request->post('type');
+        $amount        = $this->request->post('amount');
+        if(!in_array($type, [1,2])){
+            $this->error(__('参数有误'));
+        }
+        if(!($amount > 0)){
+            $this->error(__('参数有误'));
+        }
+
+        $user = $this->auth->getUser();
+        if($amount > $user['balance']){
+            $this->error(__('余额不足'));
+        }
+
+        $withdraw_info = UserModel::getAgentWithdrawInfoByAgentId($user['agent_id']);
+        if(empty($withdraw_info)){
+            $this->error(__('无提现信息'));
+        }
+
+        $insert_data = [
+            'order_type' => $type,
+            'user_id'   => $user['id'],
+            'amount'    => $amount,
+            'status'    => MoneyOut::Default,
+            'agent_id'  => $withdraw_info['agent_id'],
+            'user_type' => $user['user_type'],
+        ];
+
+        //USDT充值
+        if($type == 1){
+            if(empty($withdraw_info['usdt'])){
+                $this->error(__('参数有误'));
+            }
+            $usdt_address = $this->request->post('usdt');
+            if(empty($usdt_address)){
+                $this->error(__('参数有误'));
+            }
+
+            $insert_data['order_no']      = 'U' . time() . $user['id'];
+            $insert_data['usdt_address']  = $usdt_address;
+        }else{
+            if(empty($withdraw_info['bank'])){
+                $this->error(__('参数有误'));
+            }
+            $insert_data['bank_name']   = $this->request->post('bank_name');
+            $insert_data['bank_card']   = $this->request->post('bank_card');
+            $insert_data['account_name']= $this->request->post('account_name');
+            if(empty($insert_data['bank_name']) || empty($insert_data['bank_card']) || empty($insert_data['account_name'])){
+                $this->error(__('参数有误'));
+            }
+            $insert_data['order_no']    = 'B' . time() . $user['id'];
+        }
+
+        $fund_pwd = $this->request->post('fund_pwd');
+        if(empty($fund_pwd)){
+            $this->error(__('参数有误'));
+        }
+        if($user['fund_pwd'] != md5($fund_pwd)){
+            $this->error(__('资金密码有误'));
+        }
+
+        //写入
+        Db::startTrans();
+        try {
+            (new MoneyOut())->save($insert_data);
+            Db::commit();
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+        $this->success('');
+    }
+
+    /**
+     * 充值提现列表
+     * @return void
+     * @throws \think\exception\DbException
+     */
+    public function money_list()
+    {
+        $type          = $this->request->post('type');
+        if(empty($type)){
+            $type = 1;
+        }
+        if(!in_array($type, [1,2])){
+            $this->error(__('参数有误'));
+        }
+
+        $user = $this->auth->getUser();
+        $res_data = [];
+
+        if($type == 1){
+            //充值列表
+            $info_list = MoneyIn::where('user_id', $user['id'])
+                ->field('order_no,order_type,amount,status,create_time')
+                ->order('id DESC')
+                ->paginate($this->pageSize);
+            foreach ($info_list as $k => $v) {
+                $info_list[$k]['status_name'] = (new MoneyIn())->getStatusNames($v['status']);
+            }
+            $res_data = $this->buildResp($info_list->total(), $info_list->currentPage(), $info_list->items());
+        }else{
+            //提现列表
+            $info_list = MoneyOut::where('user_id', $user['id'])
+                ->field('order_no,order_type,amount,status,create_time')
+                ->order('id DESC')
+                ->paginate($this->pageSize);
+            foreach ($info_list as $k => $v) {
+                $info_list[$k]['status_name'] = (new MoneyOut())->getStatusNames($v['status']);
+            }
+            $res_data = $this->buildResp($info_list->total(), $info_list->currentPage(), $info_list->items());
+        }
+
+
+        $res_data['money_in_sum']   = MoneyIn::where('user_id', $user['id'])->where('status', MoneyIn::Success)->sum('amount');
+        $res_data['money_out_sum']  = MoneyOut::where('user_id', $user['id'])->where('status', MoneyOut::Success)->sum('amount');
+        $this->success('', $res_data);
+    }
 }

+ 2 - 0
application/api/lang/zh-cn.php

@@ -6,4 +6,6 @@ return [
     '未定义'                                           => '未定义',
     '参数有误'                                         => '参数有误',
     '提交成功'                                         => '提交成功,请等待处理',
+    '余额不足'                                         => '您的可用余额不足',
+    '资金密码有误'                                      => '资金密码不正确',
 ];

+ 1 - 0
application/api/lang/zh-cn/money.php

@@ -2,6 +2,7 @@
 
 return [
     '无充值信息'               => '系统未配置充值信息,请联系客服',
+    '无提现信息'               => '系统未配置提现信息,请联系客服',
     '完成'                    => '完成',
     '冻结'                    => '冻结',
     '取消'                    => '取消',

+ 1 - 1
public/assets/js/backend/trade/money_out.js

@@ -28,7 +28,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                             formatter: Table.api.formatter.status
                         },
                         {field: 'users.mobile', title: __('User_id')},
-                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
+                        {field: 'usdt_address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                         {field: 'bank_name', title: __('Bank_name'), operate: 'LIKE'},
                         {field: 'bank_card', title: __('Bank_card'), operate: 'LIKE'},
                         {field: 'account_name', title: __('Account_name'), operate: 'LIKE'},