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

XIAOPAN

@@ -542,6 +542,21 @@ class UsersController extends HomeBaseController{ @@ -542,6 +542,21 @@ class UsersController extends HomeBaseController{
542 if ($user['fee']>=$fee) { 542 if ($user['fee']>=$fee) {
543 //生成订单号 543 //生成订单号
544 $order_sn=cmf_get_order_sn(); 544 $order_sn=cmf_get_order_sn();
  545 + Db::startTrans();
  546 + try{
  547 + Db::name('users')->where('id',$user_id)->setDec('fee', $fee);
  548 + Db::name('withdraw')->insert([
  549 + 'user_id'=>$user_id,
  550 + 'money'=>$fee,
  551 + 'create_time'=>time(),
  552 + 'order_sn'=>$order_sn
  553 + ]);
  554 + Db::commit();
  555 + }catch (\Exception $e) {
  556 + // 回滚事务
  557 + Db::rollback();
  558 + $this->apiResponse(301,'提现失败');
  559 + }
545 //进行提现 560 //进行提现
546 $app = new Application($this->options); 561 $app = new Application($this->options);
547 $merchantPay = $app->merchant_pay; 562 $merchantPay = $app->merchant_pay;
@@ -557,23 +572,12 @@ class UsersController extends HomeBaseController{ @@ -557,23 +572,12 @@ class UsersController extends HomeBaseController{
557 ]; 572 ];
558 $re = $merchantPay->send($merchantPayData); 573 $re = $merchantPay->send($merchantPayData);
559 if ($re['return_code']=='SUCCESS' && $re['result_code']=='SUCCESS'){ 574 if ($re['return_code']=='SUCCESS' && $re['result_code']=='SUCCESS'){
560 - Db::startTrans();  
561 - try{  
562 - Db::name('users')->where('id',$user_id)->setDec('fee', $fee);  
563 - Db::name('withdraw')->insert([  
564 - 'user_id'=>$user_id,  
565 - 'money'=>$fee,  
566 - 'create_time'=>time(),  
567 - 'order_sn'=>$order_sn  
568 - ]);  
569 - Db::commit();  
570 - }catch (\Exception $e) {  
571 - // 回滚事务  
572 - Db::rollback();  
573 - $this->apiResponse(301,'提现失败');  
574 - }  
575 $this->apiResponse(200,'success'); 575 $this->apiResponse(200,'success');
576 }else{ 576 }else{
  577 + Db::name('users')->where('id',$user_id)->setInc('fee', $fee);
  578 + Db::name('withdraw')->where([
  579 + 'order_sn'=>$order_sn
  580 + ])->delete();
577 $this->apiResponse(301,'提现失败'); 581 $this->apiResponse(301,'提现失败');
578 } 582 }
579 }else{ 583 }else{