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

XIAOPAN

@@ -463,26 +463,12 @@ class UsersController extends HomeBaseController{ @@ -463,26 +463,12 @@ class UsersController extends HomeBaseController{
463 $fee=$this->request->param('fee'); 463 $fee=$this->request->param('fee');
464 $user=Db::name('users')->where('id',$user_id)->find(); 464 $user=Db::name('users')->where('id',$user_id)->find();
465 if ($user['fee']>=$fee) { 465 if ($user['fee']>=$fee) {
  466 + //生成订单号
466 $order_sn=cmf_get_order_sn(); 467 $order_sn=cmf_get_order_sn();
467 - Db::startTrans();  
468 - try{  
469 - Db::name('users')->where('id',$user_id)->setDec('fee', $fee);  
470 - Db::name('withdraw')->insert([  
471 - 'user_id'=>$user_id,  
472 - 'money'=>$fee,  
473 - 'create_time'=>time(),  
474 - 'order_sn'=>$order_sn  
475 - ]);  
476 - Db::commit();  
477 - }catch (\Exception $e) {  
478 - // 回滚事务  
479 - Db::rollback();  
480 - $this->apiResponse(301,'提现失败');  
481 - }  
482 - $app = new Application($this->options);  
483 - $merchantPay = $app->merchant_pay;  
484 -  
485 - $merchantPayData = [ 468 + //进行提现
  469 + $app = new Application($this->options);
  470 + $merchantPay = $app->merchant_pay;
  471 + $merchantPayData = [
486 'partner_trade_no' => $order_sn, //随机字符串作为订单号,跟红包和支付一个概念。 472 'partner_trade_no' => $order_sn, //随机字符串作为订单号,跟红包和支付一个概念。
487 'openid' => $user['open_id'], //收款人的openid 473 'openid' => $user['open_id'], //收款人的openid
488 'check_name' => 'NO_CHECK', //文档中有三种校验实名的方法 NO_CHECK OPTION_CHECK FORCE_CHECK 474 'check_name' => 'NO_CHECK', //文档中有三种校验实名的方法 NO_CHECK OPTION_CHECK FORCE_CHECK
@@ -493,8 +479,22 @@ class UsersController extends HomeBaseController{ @@ -493,8 +479,22 @@ class UsersController extends HomeBaseController{
493 'spbill_create_ip' => get_client_ip(0, true), //发起交易的IP地址 479 'spbill_create_ip' => get_client_ip(0, true), //发起交易的IP地址
494 ]; 480 ];
495 $re = $merchantPay->send($merchantPayData); 481 $re = $merchantPay->send($merchantPayData);
496 -// var_dump($re);  
497 if ($re['return_code']=='SUCCESS' && $re['result_code']=='SUCCESS'){ 482 if ($re['return_code']=='SUCCESS' && $re['result_code']=='SUCCESS'){
  483 + Db::startTrans();
  484 + try{
  485 + Db::name('users')->where('id',$user_id)->setDec('fee', $fee);
  486 + Db::name('withdraw')->insert([
  487 + 'user_id'=>$user_id,
  488 + 'money'=>$fee,
  489 + 'create_time'=>time(),
  490 + 'order_sn'=>$order_sn
  491 + ]);
  492 + Db::commit();
  493 + }catch (\Exception $e) {
  494 + // 回滚事务
  495 + Db::rollback();
  496 + $this->apiResponse(301,'提现失败');
  497 + }
498 $this->apiResponse(200,'success',$re); 498 $this->apiResponse(200,'success',$re);
499 } 499 }
500 }else{ 500 }else{