|
@@ -2,6 +2,8 @@ |
|
@@ -2,6 +2,8 @@ |
2
|
|
2
|
|
3
|
namespace app\admin\controller\user;
|
3
|
namespace app\admin\controller\user;
|
4
|
|
4
|
|
|
|
5
|
+use addons\third\library\Service;
|
|
|
6
|
+use addons\wechat\library\Config as ConfigService;
|
5
|
use app\common\controller\Backend;
|
7
|
use app\common\controller\Backend;
|
6
|
use EasyWeChat\Foundation\Application;
|
8
|
use EasyWeChat\Foundation\Application;
|
7
|
use think\Db;
|
9
|
use think\Db;
|
|
@@ -107,27 +109,17 @@ class UserWithdraw extends Backend |
|
@@ -107,27 +109,17 @@ class UserWithdraw extends Backend |
107
|
}
|
109
|
}
|
108
|
}
|
110
|
}
|
109
|
$row->status = $params['status'];
|
111
|
$row->status = $params['status'];
|
|
|
112
|
+ $withdraw_percent = config('site.withdraw_percent');
|
110
|
Db::startTrans();
|
113
|
Db::startTrans();
|
111
|
try {
|
114
|
try {
|
112
|
$user_model = new \app\admin\model\User();
|
115
|
$user_model = new \app\admin\model\User();
|
113
|
$user = $user_model->where('id', $row->user_id)->find();
|
116
|
$user = $user_model->where('id', $row->user_id)->find();
|
114
|
if ($params['status'] == 2) {
|
117
|
if ($params['status'] == 2) {
|
115
|
// 微信提现
|
118
|
// 微信提现
|
116
|
- $options = get_addon_config('epay');
|
|
|
117
|
- $wechat_option = [
|
|
|
118
|
- 'app_id' => $options['wechat']['appid'],
|
|
|
119
|
- 'app_secret' => $options['wechat']['app_secret'],
|
|
|
120
|
- 'payment' => [
|
|
|
121
|
- 'merchant_id' => $options['wechat']['mch_id'],
|
|
|
122
|
- 'key' => $options['wechat']['key'],
|
|
|
123
|
- 'cert_path' => ROOT_PATH . 'addons' . $options['wechat']['cert_client'],
|
|
|
124
|
- 'key_path' => ROOT_PATH . 'addons' . $options['wechat']['cert_key'],
|
|
|
125
|
- ]
|
|
|
126
|
- ];
|
|
|
127
|
- $app = new Application($wechat_option);
|
119
|
+ $app = new Application(ConfigService::load());
|
128
|
$merchantPay = $app->merchant_pay;
|
120
|
$merchantPay = $app->merchant_pay;
|
129
|
$order_sn = $row->order_sn;
|
121
|
$order_sn = $row->order_sn;
|
130
|
- $user_openid = Db::name('third')->where('user_id', $row->user_id)->where('third_party', 'wechat')->value('openid');
|
122
|
+ $user_openid = Db::name('third')->where('user_id', $row->user_id)->where('platform', 'wechat')->value('openid');
|
131
|
$merchantPayData = [
|
123
|
$merchantPayData = [
|
132
|
'partner_trade_no' => $order_sn, //随机字符串作为订单号,跟红包和支付一个概念。
|
124
|
'partner_trade_no' => $order_sn, //随机字符串作为订单号,跟红包和支付一个概念。
|
133
|
'openid' => $user_openid, //收款人的openid
|
125
|
'openid' => $user_openid, //收款人的openid
|
|
@@ -138,37 +130,67 @@ class UserWithdraw extends Backend |
|
@@ -138,37 +130,67 @@ class UserWithdraw extends Backend |
138
|
];
|
130
|
];
|
139
|
$result_pay = $merchantPay->send($merchantPayData);
|
131
|
$result_pay = $merchantPay->send($merchantPayData);
|
140
|
if ($result_pay['return_code'] == 'SUCCESS' && $result_pay['result_code'] == 'SUCCESS') {
|
132
|
if ($result_pay['return_code'] == 'SUCCESS' && $result_pay['result_code'] == 'SUCCESS') {
|
|
|
133
|
+ if($row->type == 1) {
|
|
|
134
|
+ // 余额变动记录
|
|
|
135
|
+ $log = [
|
|
|
136
|
+ 'user_id' => $row->user_id,
|
|
|
137
|
+ 'score' => $row->money * $withdraw_percent,
|
|
|
138
|
+ 'before' => $user['score'],
|
|
|
139
|
+ 'after' => $user['score'] - $row->money * $withdraw_percent,
|
|
|
140
|
+ 'createtime' => time(),
|
|
|
141
|
+ 'status' => 2,
|
|
|
142
|
+ 'memo' => '提现'
|
|
|
143
|
+ ];
|
|
|
144
|
+ $result_log = Db::name('user_score_log')->insertGetId($log);
|
|
|
145
|
+ } else{
|
|
|
146
|
+ // 余额变动记录
|
|
|
147
|
+ $log = [
|
|
|
148
|
+ 'user_id' => $row->user_id,
|
|
|
149
|
+ 'money' => $row->money,
|
|
|
150
|
+ 'before' => $user['money'],
|
|
|
151
|
+ 'after' => $user['money'] - $row->money,
|
|
|
152
|
+ 'createtime' => time(),
|
|
|
153
|
+ 'status' => 2,
|
|
|
154
|
+ 'memo' => '提现'
|
|
|
155
|
+ ];
|
|
|
156
|
+ $result_log = Db::name('user_money_log')->insertGetId($log);
|
|
|
157
|
+ }
|
|
|
158
|
+ $row->success_time = time();
|
|
|
159
|
+ $row->more = json_encode($result_pay, JSON_UNESCAPED_UNICODE);
|
|
|
160
|
+ } else {
|
|
|
161
|
+ Db::rollback();
|
|
|
162
|
+ $this->error($result_pay['err_code_des']);
|
|
|
163
|
+ }
|
|
|
164
|
+ } else {
|
|
|
165
|
+ if($row->type == 1) {
|
141
|
// 余额变动记录
|
166
|
// 余额变动记录
|
142
|
$log = [
|
167
|
$log = [
|
143
|
'user_id' => $row->user_id,
|
168
|
'user_id' => $row->user_id,
|
144
|
- 'score' => $row->money,
|
|
|
145
|
- 'before' => $user['money'],
|
|
|
146
|
- 'after' => $user['money'] - $row->money,
|
169
|
+ 'score' => $row->money * $withdraw_percent,
|
|
|
170
|
+ 'before' => $user['score'],
|
|
|
171
|
+ 'after' => $user['score'] + $row->money * $withdraw_percent,
|
147
|
'createtime' => time(),
|
172
|
'createtime' => time(),
|
148
|
- 'status' => 2,
|
|
|
149
|
- 'memo' => '提现'
|
173
|
+ 'status' => 3,
|
|
|
174
|
+ 'memo' => '提现审核失败'
|
150
|
];
|
175
|
];
|
151
|
$result_log = Db::name('user_score_log')->insertGetId($log);
|
176
|
$result_log = Db::name('user_score_log')->insertGetId($log);
|
152
|
- $row->success_time = time();
|
|
|
153
|
- $row->more = json_encode($result_pay, JSON_UNESCAPED_UNICODE);
|
177
|
+ // 返还用户余额
|
|
|
178
|
+ $result_user = $user_model->where('id', $user['id'])->setInc('score', $row->money * $withdraw_percent);
|
154
|
} else {
|
179
|
} else {
|
155
|
- Db::rollback();
|
|
|
156
|
- $this->error($result_pay['err_code_des']);
|
180
|
+ // 余额变动记录
|
|
|
181
|
+ $log = [
|
|
|
182
|
+ 'user_id' => $row->user_id,
|
|
|
183
|
+ 'money' => $row->money,
|
|
|
184
|
+ 'before' => $user['money'],
|
|
|
185
|
+ 'after' => $user['money'] + $row->money,
|
|
|
186
|
+ 'createtime' => time(),
|
|
|
187
|
+ 'status' => 3,
|
|
|
188
|
+ 'memo' => '提现审核失败'
|
|
|
189
|
+ ];
|
|
|
190
|
+ $result_log = Db::name('user_money_log')->insertGetId($log);
|
|
|
191
|
+ // 返还用户余额
|
|
|
192
|
+ $result_user = $user_model->where('id', $user['id'])->setInc('money', $row->money);
|
157
|
}
|
193
|
}
|
158
|
- } else {
|
|
|
159
|
- // 余额变动记录
|
|
|
160
|
- $log = [
|
|
|
161
|
- 'user_id' => $row->user_id,
|
|
|
162
|
- 'score' => $row->money,
|
|
|
163
|
- 'before' => $user['score'],
|
|
|
164
|
- 'after' => $user['score'] + $row->money,
|
|
|
165
|
- 'createtime' => time(),
|
|
|
166
|
- 'status' => 3,
|
|
|
167
|
- 'memo' => '提现审核失败'
|
|
|
168
|
- ];
|
|
|
169
|
- $result_log = Db::name('user_score_log')->insertGetId($log);
|
|
|
170
|
- // 返还用户余额
|
|
|
171
|
- $result_user = $user_model->where('id', $user['id'])->setInc('score', $row->money);
|
|
|
172
|
if (!$result_log || !$result_user) {
|
194
|
if (!$result_log || !$result_user) {
|
173
|
Db::rollback();
|
195
|
Db::rollback();
|
174
|
$this->error('提现审核失败');
|
196
|
$this->error('提现审核失败');
|