chengkun
2025-09-04 2e12809f4d16aa00239b5e2c6a13a9a51842d134
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
<?php
 
namespace app\admin\controller;
 
use think\facade\Db;
use think\facade\Request;
use think\facade\View;
use think\Exception;
 
class RemitRecord extends Common {
    /*
     * 品牌管理
     */
    public function index(): string {
        View::assign('menuitem', strtolower('remitRecord-index'));
        $other['title'] = '汇款审核';
        $guide['one']['text'] = '数据审核';
        $guide['two']['text'] = '汇款审核';
        View::assign('guide', $guide);
        View::assign('other', $other);
        return View::fetch('index');
    }
    
    /*
     */
    public function getRemitRecordList() {
        try {
            if (!Request::isPost()) {
                throw new Exception(lang('request_method_incorrect'));
            }
            $kw = input('kw');
//            $condition[] = ['SRR.status', '=', 0];
            $condition[]= ['SRR.remittor_name|SRR.remittor_account|SRR.remit_transaction_number', 'like', '%' . $kw . '%'];
            $p = input('p', 1);
            $other['page_size'] = input('page_size', 20);
            $order = 'SRR.id desc';
            $count = Db::name('seller_remit_record')
                ->alias('SRR')
                ->join('pay_bank PA', 'PA.id=SRR.pay_bank_id')
                ->where($condition)->count();
            $list = Db::name('seller_remit_record')
                ->alias('SRR')
                ->field("SRR.*,PA.payee_name")
                ->join('pay_bank PA', 'PA.id=SRR.pay_bank_id')
                ->where($condition)->order($order)->page($p, $other['page_size'])->withAttr('add_time', function ($value) {
                    return date('Y-m-d H:i', $value);
                })
                ->withAttr('remit_date_time', function ($value) {
                    return $value ? date('Y-m-d', $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 reviewRemitRecord() {
        // 开始数据库事务
        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('seller_remit_record')->field('id,status,asset_id,remit_amount,seller_id')->where('id', $record_id)->find();
            if (!$info) {
                throw new Exception(lang('no_data_found'));
            }
            if ($info['status'] == 1) {
                throw new Exception('该申请已审核通过,不能重复审核');
            }
            if ($status == 1) {
                $service_charge = input('post.service_charge');
                $remit_amount = $info['remit_amount'];
                if (!$service_charge || !is_numeric($service_charge)) {
                    throw new Exception('请输入手续费');
                }
                $add_fee = $remit_amount - $service_charge;//实际收款金额:充值金额-手续费
                $asset_update['mnyall'] = Db::raw("mnyall+$add_fee");//入库总额
                $asset_update['mnyavl'] = Db::raw("mnyavl+$add_fee");//可用余额
                Db::name('seller_asset')->where('id', $info['asset_id'])->update($asset_update);
                $record_update = [
                    'status'      => 1,
                    'service_charge'=> $service_charge,
                    'review_time' => time()//审核时间
                ];
                Db::name('seller_remit_record')->where('id', $record_id)->update($record_update);//更新状态
                $LogData = [
                    'amount'      => $add_fee,
                    'type'           => 1,//1增加,2减少
                    'remark'         => '汇款确认',
                    'user_id'        => $this->admin_id,
                    'seller_id'        => $info['seller_id'],
                    'target_type' => 1,
                    'target_id' => $info['asset_id'],
 
                ];
                event('SellerBillLog', $LogData);//汇款确认入账日志
                $message = '操作成功,审核通过';
            } else {
                Db::name('seller_remit_record')->where('id', $record_id)->update(['status' => 2]);
                $message = '操作成功,审核不通过';
            }
            // 提交事务
            Db::commit();
            return $this->successResponse($message);
            
        } catch (Exception $exc) {
            // 回滚事务
            Db::rollback();
            return $this->errorResponse($exc->getMessage());
        }
    }
    
}