diff --git a/app/controller/api/Coupon.php b/app/controller/api/Coupon.php index 356be28..cf8550a 100644 --- a/app/controller/api/Coupon.php +++ b/app/controller/api/Coupon.php @@ -493,6 +493,7 @@ class Coupon extends Base return $this->json(4001, "商家已禁用"); } + $businessModel = $business["model"]; // 指定时间段内发布的优惠券个数 $TimeListModeReleaseCount = BusinessRepository::getInstance() ->getTimeListModeReleaseCount($business["code"],$business["time_limit_start"],$business["time_limit_end"]); @@ -510,11 +511,12 @@ class Coupon extends Base ) ) ) { - if ($business['balance'] < $coupon->couponMain->deduction_money) { - return $this->json(4001, "商家余额不足"); - } + $businessModel = BusinessModel::model_ordinary; + } + + if ($business['balance'] < $coupon->couponMain->deduction_money) { + return $this->json(4001, "商家余额不足"); } - $deductionMoney = $coupon->couponMain->deduction_money; @@ -646,26 +648,16 @@ class Coupon extends Base Deduction::create($deductionData); - //4. 商家扣钱 普通商家才扣钱 否则不扣钱 - if( - $business["model"] == BusinessModel::model_ordinary - || - ( - $business["model"] == BusinessModel::model_time_limit - && - ( - strtotime($business["time_limit_end"]) < $time - || - $TimeListModeReleaseCount >= $business["time_limit_release_count"] - ) - ) - ){ - - $business->save([ - "balance" => Db::raw("balance - " . $deductionMoney,), - "model" => BusinessModel::model_ordinary - ]); + //4. 商家扣钱 所有模式商家都要扣钱 + $businessSaveData = [ + "balance" => Db::raw("balance - " . $deductionMoney,), + ]; + //是否要变更模式 + if ($businessModel == BusinessModel::model_ordinary) { + $businessSaveData["model"] = BusinessModel::model_ordinary; } + $business->save($businessSaveData); + $payment = WechatPay::getInstance();