chengkun
2025-08-29 73cdff843994b42beef7a22844326f83fee104de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
 
namespace app\admin\controller;
 
use think\facade\Db;
use think\facade\Request;
use think\facade\View;
use think\Exception;
 
class WithdrawalRecord extends Common {
    /*
     * 品牌管理
     */
    public function index(): string {
        $other['title'] = '提现审核';
        $guide['one']['text'] = '数据审核';
        $guide['two']['text'] = '提现审核';
        View::assign('guide', $guide);
        View::assign('other', $other);
        return View::fetch('index');
    }
    
    /*
     */
    public function getWithdrawalRecordList() {
        try {
            if (!Request::isPost()) {
                throw new Exception(lang('request_method_incorrect'));
            }
            $kw = input('kw');
//            $condition[] = ['SRR.status', '=', 0];
            $condition[] = ['SWR.payment_account', 'like', '%' . $kw . '%'];
            $p = input('p', 1);
            $other['page_size'] = input('page_size', 20);
            $order = 'SWR.id desc';
            $count = Db::name('supplier_withdrawal_record')
                ->alias('SWR')
                ->join('payment_tool PT', 'PT.payment_tool_id=SWR.payment_tool_id')
                ->join('supplier_asset SA', 'SA.id=SWR.asset_id')
                ->join('currency C', 'C.id=SA.currency_id')
                ->where($condition)->count();
            $list = Db::name('supplier_withdrawal_record')
                ->alias('SWR')
                ->field("SWR.*,PT.payment_tool_name,C.currency_name")
                ->join('payment_tool PT', 'PT.payment_tool_id=SWR.payment_tool_id')
                ->join('supplier_asset SA', 'SA.id=SWR.asset_id')
                ->join('currency C', 'C.id=SA.currency_id')
                ->where($condition)->order($order)->page($p, $other['page_size'])->withAttr('add_time', function ($value) {
                    return date('Y-m-d H:i', $value);
                })
                ->select()->toArray();
            $other['count'] = $count;
            $result['other'] = $other;
            if (!$list) {
                throw new Exception(lang('no_data_found'));
            } else {
                $result['list'] = $list;
                return $this->successResponse($result);
            }
        } catch (\Exception $exc) {
            return $this->errorResponse($exc->getMessage());
        }
    }
    
    
    /**
     * 汇款审核
     */
    public function reviewWithdrawalRecord() {
        // 开始数据库事务
        Db::startTrans();
        try {
            if (!Request::isPost()) {
                throw new Exception(lang('request_method_incorrect'));
            }
            $record_id = input('post.record_id');
            if (!is_numeric($record_id)) {
                throw new Exception(lang('parameter_error'));
            }
            $status = input('post.status');
            //更新数据
            $info = Db::name('supplier_withdrawal_record')->field('id,status,asset_id,payment_amount,supplier_id')->where('id', $record_id)->find();
            if (!$info) {
                throw new Exception(lang('no_data_found'));
            }
            if ($info['status'] == 1) {
                throw new Exception('该申请已审核通过,请勿重复审核');
            }
            $payment_amount = $info['payment_amount'];
            if ($status == 1) {
                $service_charge = input('post.service_charge');
                if (!is_numeric($service_charge)) {
                    throw new Exception('请输入手续费');
                }
                $add_fee = $payment_amount - $service_charge;//实际收款金额:充值金额-手续费
                $asset_update['mnyusd'] = Db::raw("mnyusd+$payment_amount");//提现总额
                $asset_update['mnylck'] = Db::raw("mnylck-$payment_amount");//冻结金额
                Db::name('supplier_asset')->where('id', $info['asset_id'])->update($asset_update);
                $record_update = [
                    'status'         => 1,
                    'service_charge' => $service_charge,
                    'review_time'    => time()//审核时间
                ];
                Db::name('supplier_withdrawal_record')->where('id', $record_id)->update($record_update);//更新状态
                $LogData = [
                    'amount'      => $add_fee,
                    'type'        => 2,//1增加,2减少
                    'remark'      => '提现确认',
                    'user_id'     => $this->admin_id,
                    'supplier_id' => $info['supplier_id'],
                    'target_type' => 2,//提现
                    'target_id'   => $info['asset_id'],
                ];
                event('SupplierBillLog', $LogData);//提现确认日志
                $message = '操作成功,审核通过';
            } else {
                $review_comments = input('post.review_comments');
                //审核不通过处理
                $asset_update['mnyavl'] = Db::raw("mnyavl+$payment_amount");//可用余额恢复
                $asset_update['mnylck'] = Db::raw("mnylck-$payment_amount");//冻结金额恢复
                Db::name('supplier_asset')->where('id', $info['asset_id'])->update($asset_update);
                
                $no_record_update = [
                    'status'         => 2,
                    'review_comments' => $review_comments,
                    'review_time'    => time()//审核时间
                ];
                Db::name('supplier_withdrawal_record')->where('id', $record_id)->update($no_record_update);
                $message = '操作成功,审核不通过';
            }
            // 提交事务
            Db::commit();
            return $this->successResponse($message);
            
        } catch (Exception $exc) {
            // 回滚事务
            Db::rollback();
            return $this->errorResponse($exc->getMessage());
        }
    }
    
}