作者 潘浩文
1 个管道 的构建 通过 耗费 0 秒

XIAOPAN

... ... @@ -463,26 +463,12 @@ class UsersController extends HomeBaseController{
$fee=$this->request->param('fee');
$user=Db::name('users')->where('id',$user_id)->find();
if ($user['fee']>=$fee) {
//生成订单号
$order_sn=cmf_get_order_sn();
Db::startTrans();
try{
Db::name('users')->where('id',$user_id)->setDec('fee', $fee);
Db::name('withdraw')->insert([
'user_id'=>$user_id,
'money'=>$fee,
'create_time'=>time(),
'order_sn'=>$order_sn
]);
Db::commit();
}catch (\Exception $e) {
// 回滚事务
Db::rollback();
$this->apiResponse(301,'提现失败');
}
$app = new Application($this->options);
$merchantPay = $app->merchant_pay;
$merchantPayData = [
//进行提现
$app = new Application($this->options);
$merchantPay = $app->merchant_pay;
$merchantPayData = [
'partner_trade_no' => $order_sn, //随机字符串作为订单号,跟红包和支付一个概念。
'openid' => $user['open_id'], //收款人的openid
'check_name' => 'NO_CHECK', //文档中有三种校验实名的方法 NO_CHECK OPTION_CHECK FORCE_CHECK
... ... @@ -493,8 +479,22 @@ class UsersController extends HomeBaseController{
'spbill_create_ip' => get_client_ip(0, true), //发起交易的IP地址
];
$re = $merchantPay->send($merchantPayData);
// var_dump($re);
if ($re['return_code']=='SUCCESS' && $re['result_code']=='SUCCESS'){
Db::startTrans();
try{
Db::name('users')->where('id',$user_id)->setDec('fee', $fee);
Db::name('withdraw')->insert([
'user_id'=>$user_id,
'money'=>$fee,
'create_time'=>time(),
'order_sn'=>$order_sn
]);
Db::commit();
}catch (\Exception $e) {
// 回滚事务
Db::rollback();
$this->apiResponse(301,'提现失败');
}
$this->apiResponse(200,'success',$re);
}
}else{
... ...