diff --git a/app/controller/api/Coupon.php b/app/controller/api/Coupon.php index f527f6b..d2fdffd 100644 --- a/app/controller/api/Coupon.php +++ b/app/controller/api/Coupon.php @@ -392,7 +392,7 @@ class Coupon extends Base } $coupon = CouponRepository::getInstance()->findById($couponId,[],function ($q){ - return $q->with(["couponMain","redpack"]); + return $q->with(["couponMain","redpack"])->lock(true); }); if(empty($coupon)){ @@ -597,7 +597,7 @@ class Coupon extends Base "create_time" => date("Y-m-d H:i:s",$time), "pay_time" => '0000-00-00 00:00:00', ]; - $redpack = Redpack::create($redpackData); + //发起支付 //$result = $payment->transfer->toBalance($toBalanceData); @@ -606,8 +606,7 @@ class Coupon extends Base //付款成功才提交!!!!!伪装成功 if( true || isset($result['payment_no']) ){ - $redpack->pay_time = date("Y-m-d H:i:s",$time); - $redpack->save(); + $redpackData['pay_time'] = date("Y-m-d H:i:s",$time); Db::commit(); return $this->json( @@ -622,6 +621,9 @@ class Coupon extends Base //默认回滚 Db::rollback(); + + Redpack::create($redpackData); + return $this->json(5003, "验证失败,发放红包失败"); } Db::commit();