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

XIAOPAN

@@ -456,13 +456,21 @@ class UsersController extends HomeBaseController{ @@ -456,13 +456,21 @@ class UsersController extends HomeBaseController{
456 $user=Db::name('users')->where('id',$user_id)->find(); 456 $user=Db::name('users')->where('id',$user_id)->find();
457 if ($user['fee']>=$fee) { 457 if ($user['fee']>=$fee) {
458 $order_sn=cmf_get_order_sn(); 458 $order_sn=cmf_get_order_sn();
459 - Db::name('users')->setDec('fee', $fee); 459 + Db::startTrans();
  460 + try{
  461 + Db::name('users')->where('id',$user_id)->setDec('fee', $fee);
460 Db::name('withdraw')->insert([ 462 Db::name('withdraw')->insert([
461 'user_id'=>$user_id, 463 'user_id'=>$user_id,
462 'money'=>$fee, 464 'money'=>$fee,
463 'create_time'=>time(), 465 'create_time'=>time(),
464 'order_sn'=>$order_sn 466 'order_sn'=>$order_sn
465 ]); 467 ]);
  468 + Db::commit();
  469 + }catch (\Exception $e) {
  470 + // 回滚事务
  471 + Db::rollback();
  472 + $this->apiResponse(301,'提现失败');
  473 + }
466 $app = new Application($this->options); 474 $app = new Application($this->options);
467 $merchantPay = $app->merchant_pay; 475 $merchantPay = $app->merchant_pay;
468 $merchantPayData = [ 476 $merchantPayData = [