WithdrawalController.php
5.7 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
namespace app\admin\controller;
use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use EasyWeChat\Foundation\Application;
use function GuzzleHttp\Psr7\str;
use think\Db;
class WithdrawalController extends AdminBaseController{
/**
* 提现审核
*/
public function withd_audit(){
$param = $this->request->param();
$where['state'] = 0;
if(!empty($param['start_time']) && !empty($param['end_time'])){
$start_time = strtotime($param['start_time']);
$end_time = strtotime($param['end_time']);
$where['a.create_time'] = [['>=',$start_time],['<=',$end_time]];
}
if(!empty($param['keyword'])){
$where['b.phone'] = ['like','%'.trim($param['keyword']).'%'];
}
$data = Db::name('money_expend') -> alias('a') -> field('a.*,b.phone') -> join('my_user b','a.uid=b.uid','LEFT') -> where($where) -> paginate(12);
$data->appends($param);
$data_arr = $data -> toArray();
if(!empty($data_arr)){
foreach($data_arr['data'] as $key => $val){
$name = Db::name('user') -> where('id',$val['uid']) -> find();
$data_arr['data'][$key]['name'] = $name['user_nickname'];
}
}
$this->assign('start_time',!empty($param['start_time']) ? $param['start_time'] : '');
$this->assign('end_time',!empty($param['end_time']) ? $param['end_time'] : '');
$this->assign('keyword',!empty($param['keyword']) ? trim($param['keyword']) : '');
$this -> assign('data_arr',$data_arr['data']);
$this -> assign('data',$data);
return $this -> fetch();
}
/**
* 提现列表
*/
public function withd_list(){
$param = $this->request->param();
$where['state'] = [['=',1],['=',2],'or'];
if(!empty($param['start_time']) && !empty($param['end_time'])){
$start_time = strtotime($param['start_time']);
$end_time = strtotime($param['end_time']);
$where['a.create_time'] = [['>=',$start_time],['<=',$end_time]];
}
if(!empty($param['keyword'])){
$where['b.phone|u.user_nickname'] = ['like','%'.trim($param['keyword']).'%'];
}
$data = Db::name('money_expend')
->alias('a')
->field('a.*,b.phone,u.user_nickname as name')
->join('my_user b','a.uid=b.uid','LEFT')
->join('user u','a.uid=u.id','LEFT')
->where($where)
->order("a.create_time desc")
->paginate(12);
$data->appends($param);
$data_arr = $data -> toArray();
$this->assign('start_time',!empty($param['start_time']) ? $param['start_time'] : '');
$this->assign('end_time',!empty($param['end_time']) ? $param['end_time'] : '');
$this->assign('keyword',!empty($param['keyword']) ? trim($param['keyword']) : '');
$this -> assign('data_arr',$data_arr['data']);
$this -> assign('data',$data);
return $this -> fetch();
}
/**
* 提现列表删除
*/
public function withd_del(){
$id = $_POST['id'];
$data = Db::name('money_expend') -> delete($id);
if($data){
return true;
}else{
return false;
}
}
/**
* 提现审核拒绝
*/
public function withd_refuse(){
$id = $_POST['id'];
$create_time = time();
$data = Db::name('money_expend') -> where("id",$id) -> update(['state'=>2,'create_time'=>$create_time]);
if($data){
return true;
}else{
return false;
}
}
/**
* 提现审核通过
*/
public function withd_through(){
$money_expend = Db::name('money_expend') -> where('id',$_POST['id']) -> find();
if($money_expend['state'] == 0) {
$third_party = Db::name('third_party_user') -> where('user_id',$money_expend['uid']) -> find();
$result = $this -> merchantPay($third_party['openid'],'',$money_expend['money'],'企业付款');
if($result['result_code'] == 'SUCCESS'){
$create_time = time();
Db::name('money_expend') -> where('id',$_POST['id']) -> update(['state'=>1,'create_time'=>$create_time]);
$money_expend['money'] = $money_expend['money']/(1-0.006);
Db::name('my_user') -> where('uid',$money_expend['uid']) -> setDec('balance',$money_expend['money']);
return true;
}else{
Db::name('error')->insertGetId(['error'=>json_encode($result)]);
return false;
}
}
}
/**
* 提现
*/
public function merchantPay($openid,$user_name,$price,$desc){
$options = [
'app_id' => config('wechat_config.app_id'),
'secret' => config('wechat_config.secret'),
'payment' => config('wechat_config.payment'),
];
$app = new Application($options);
$merchantPay = $app->merchant_pay;
$merchantPayData = [
'partner_trade_no' => cmf_get_order_sn(), //随机字符串作为订单号,跟红包和支付一个概念。
'openid' => $openid, //收款人的openid
'check_name' => 'NO_CHECK', //文档中有三种校验实名的方法 NO_CHECK OPTION_CHECK FORCE_CHECK
're_user_name'=>$user_name, //OPTION_CHECK FORCE_CHECK 校验实名的时候必须提交
'amount' => $price*100, //单位为分
'desc' => $desc,
'spbill_create_ip' => $this->request->ip(0,true), //发起交易的IP地址
];
$result = $merchantPay->send($merchantPayData);
return $result;
}
}