...
|
...
|
@@ -2,6 +2,8 @@ |
|
|
|
|
|
namespace app\admin\controller\user;
|
|
|
|
|
|
use addons\third\library\Service;
|
|
|
use addons\wechat\library\Config as ConfigService;
|
|
|
use app\common\controller\Backend;
|
|
|
use EasyWeChat\Foundation\Application;
|
|
|
use think\Db;
|
...
|
...
|
@@ -107,27 +109,17 @@ class UserWithdraw extends Backend |
|
|
}
|
|
|
}
|
|
|
$row->status = $params['status'];
|
|
|
$withdraw_percent = config('site.withdraw_percent');
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
$user_model = new \app\admin\model\User();
|
|
|
$user = $user_model->where('id', $row->user_id)->find();
|
|
|
if ($params['status'] == 2) {
|
|
|
// 微信提现
|
|
|
$options = get_addon_config('epay');
|
|
|
$wechat_option = [
|
|
|
'app_id' => $options['wechat']['appid'],
|
|
|
'app_secret' => $options['wechat']['app_secret'],
|
|
|
'payment' => [
|
|
|
'merchant_id' => $options['wechat']['mch_id'],
|
|
|
'key' => $options['wechat']['key'],
|
|
|
'cert_path' => ROOT_PATH . 'addons' . $options['wechat']['cert_client'],
|
|
|
'key_path' => ROOT_PATH . 'addons' . $options['wechat']['cert_key'],
|
|
|
]
|
|
|
];
|
|
|
$app = new Application($wechat_option);
|
|
|
$app = new Application(ConfigService::load());
|
|
|
$merchantPay = $app->merchant_pay;
|
|
|
$order_sn = $row->order_sn;
|
|
|
$user_openid = Db::name('third')->where('user_id', $row->user_id)->where('third_party', 'wechat')->value('openid');
|
|
|
$user_openid = Db::name('third')->where('user_id', $row->user_id)->where('platform', 'wechat')->value('openid');
|
|
|
$merchantPayData = [
|
|
|
'partner_trade_no' => $order_sn, //随机字符串作为订单号,跟红包和支付一个概念。
|
|
|
'openid' => $user_openid, //收款人的openid
|
...
|
...
|
@@ -138,37 +130,67 @@ class UserWithdraw extends Backend |
|
|
];
|
|
|
$result_pay = $merchantPay->send($merchantPayData);
|
|
|
if ($result_pay['return_code'] == 'SUCCESS' && $result_pay['result_code'] == 'SUCCESS') {
|
|
|
if($row->type == 1) {
|
|
|
// 余额变动记录
|
|
|
$log = [
|
|
|
'user_id' => $row->user_id,
|
|
|
'score' => $row->money * $withdraw_percent,
|
|
|
'before' => $user['score'],
|
|
|
'after' => $user['score'] - $row->money * $withdraw_percent,
|
|
|
'createtime' => time(),
|
|
|
'status' => 2,
|
|
|
'memo' => '提现'
|
|
|
];
|
|
|
$result_log = Db::name('user_score_log')->insertGetId($log);
|
|
|
} else{
|
|
|
// 余额变动记录
|
|
|
$log = [
|
|
|
'user_id' => $row->user_id,
|
|
|
'money' => $row->money,
|
|
|
'before' => $user['money'],
|
|
|
'after' => $user['money'] - $row->money,
|
|
|
'createtime' => time(),
|
|
|
'status' => 2,
|
|
|
'memo' => '提现'
|
|
|
];
|
|
|
$result_log = Db::name('user_money_log')->insertGetId($log);
|
|
|
}
|
|
|
$row->success_time = time();
|
|
|
$row->more = json_encode($result_pay, JSON_UNESCAPED_UNICODE);
|
|
|
} else {
|
|
|
Db::rollback();
|
|
|
$this->error($result_pay['err_code_des']);
|
|
|
}
|
|
|
} else {
|
|
|
if($row->type == 1) {
|
|
|
// 余额变动记录
|
|
|
$log = [
|
|
|
'user_id' => $row->user_id,
|
|
|
'score' => $row->money,
|
|
|
'before' => $user['money'],
|
|
|
'after' => $user['money'] - $row->money,
|
|
|
'score' => $row->money * $withdraw_percent,
|
|
|
'before' => $user['score'],
|
|
|
'after' => $user['score'] + $row->money * $withdraw_percent,
|
|
|
'createtime' => time(),
|
|
|
'status' => 2,
|
|
|
'memo' => '提现'
|
|
|
'status' => 3,
|
|
|
'memo' => '提现审核失败'
|
|
|
];
|
|
|
$result_log = Db::name('user_score_log')->insertGetId($log);
|
|
|
$row->success_time = time();
|
|
|
$row->more = json_encode($result_pay, JSON_UNESCAPED_UNICODE);
|
|
|
// 返还用户余额
|
|
|
$result_user = $user_model->where('id', $user['id'])->setInc('score', $row->money * $withdraw_percent);
|
|
|
} else {
|
|
|
Db::rollback();
|
|
|
$this->error($result_pay['err_code_des']);
|
|
|
// 余额变动记录
|
|
|
$log = [
|
|
|
'user_id' => $row->user_id,
|
|
|
'money' => $row->money,
|
|
|
'before' => $user['money'],
|
|
|
'after' => $user['money'] + $row->money,
|
|
|
'createtime' => time(),
|
|
|
'status' => 3,
|
|
|
'memo' => '提现审核失败'
|
|
|
];
|
|
|
$result_log = Db::name('user_money_log')->insertGetId($log);
|
|
|
// 返还用户余额
|
|
|
$result_user = $user_model->where('id', $user['id'])->setInc('money', $row->money);
|
|
|
}
|
|
|
} else {
|
|
|
// 余额变动记录
|
|
|
$log = [
|
|
|
'user_id' => $row->user_id,
|
|
|
'score' => $row->money,
|
|
|
'before' => $user['score'],
|
|
|
'after' => $user['score'] + $row->money,
|
|
|
'createtime' => time(),
|
|
|
'status' => 3,
|
|
|
'memo' => '提现审核失败'
|
|
|
];
|
|
|
$result_log = Db::name('user_score_log')->insertGetId($log);
|
|
|
// 返还用户余额
|
|
|
$result_user = $user_model->where('id', $user['id'])->setInc('score', $row->money);
|
|
|
if (!$result_log || !$result_user) {
|
|
|
Db::rollback();
|
|
|
$this->error('提现审核失败');
|
...
|
...
|
|