From 953246022b4b13123bdc5629cac7c05454ef87db Mon Sep 17 00:00:00 2001 From: hellcat <> Date: Mon, 13 Oct 2025 19:47:40 +0800 Subject: [PATCH] no message --- resources/views/tabler/user/product.tpl | 69 ++--------------------- src/Controllers/User/CouponController.php | 59 ++++--------------- src/Services/Payment.php | 7 ++- 3 files changed, 21 insertions(+), 114 deletions(-) diff --git a/resources/views/tabler/user/product.tpl b/resources/views/tabler/user/product.tpl index 920ac2ad4..5c025b32a 100755 --- a/resources/views/tabler/user/product.tpl +++ b/resources/views/tabler/user/product.tpl @@ -800,62 +800,6 @@ } }) - - function buyConfirm_福云(e) { - if ($("#autorenew").is(":checked")) - var t = 1; - else - t = 0; - $.ajax({ - type: "POST", - url: "buy", - dataType: "json", - data: { - coupon: $("#coupon").val(), - shop: e, - autorenew: t - }, - success: function (e) { - if (e.ret) { - var t = { - type: "success" - }; - t.title = e.msg, - Swal.fire(t), - window.setTimeout("location.href='/user'", 1500) - } else { - var o = { - type: "warning", - title: "购买失败" - }; - o.html = e.msg, - Swal.fire(o) - } - }, - error: function (e) { - var t = { - type: "error" - }; - t.title = data.msg, - Swal.fire(t) - } - }) - } - - /* - function _autorenewValue() - { - let autorenew = 0; - - if ($("#autorenew").is(":checked")) { - autorenew = 1; - } else { - autorenew = 0; - } - - return autorenew; - } - */ // 本地钱包购买按钮 function buyConfirm(e) { @@ -878,12 +822,7 @@ Swal.fire(t), window.setTimeout("location.href='/user'", 1500) } else { - var o = { - type: "warning", - title: "购买失败" - }; - o.html = e.msg, - Swal.fire(o) + showAlert("error", e.msg); } }, error: function (e) { @@ -922,8 +861,10 @@ "code" == r ? window.location.href = a : ($("#coolpay-modal").modal("show"), $("#to-coolpay").attr("href", a)) } - } else - Swal.fire("发生错误", o.msg, "error") + } else { + //Swal.fire("发生错误", o.msg, "error") + showAlert("error", o.msg); + } } }) } diff --git a/src/Controllers/User/CouponController.php b/src/Controllers/User/CouponController.php index 3c593fb19..9d4be134a 100755 --- a/src/Controllers/User/CouponController.php +++ b/src/Controllers/User/CouponController.php @@ -38,7 +38,7 @@ final class CouponController extends BaseController if ($coupon === null || ($coupon->expire_time !== 0 && $coupon->expire_time < time())) { return $response->withJson([ 'ret' => 0, - 'msg' => $invalid_coupon_msg, + 'msg' => '优惠码不存在或已过期', ]); } @@ -47,7 +47,7 @@ final class CouponController extends BaseController if ($product === null) { return $response->withJson([ 'ret' => 0, - 'msg' => $invalid_coupon_msg, + 'msg' => "该商品无效", ]); } @@ -56,14 +56,14 @@ final class CouponController extends BaseController if ($limit->disabled) { return $response->withJson([ 'ret' => 0, - 'msg' => $invalid_coupon_msg, + 'msg' => "优惠码已被禁用", ]); } if ($limit->product_id !== '' && ! in_array($product_id, explode(',', $limit->product_id))) { return $response->withJson([ 'ret' => 0, - 'msg' => $invalid_coupon_msg, + 'msg' => '优惠码不适用于此商品', ]); } @@ -71,12 +71,13 @@ final class CouponController extends BaseController $use_limit = $limit->use_time; if ($use_limit > 0) { - $user_use_count = (new Order())->where('user_id', $user->id)->where('user_coupon', $coupon->code)->count(); + $aPayOrderStatus = ["activated", "pending", "expired"]; + $user_use_count = (new Order())->where('user_id', $user->id)->where('user_coupon', $coupon->code)->whereIn("status", $aPayOrderStatus)->count(); if ($user_use_count >= $use_limit) { - return $response->withJson([ - 'ret' => 0, - 'msg' => $invalid_coupon_msg, - ]); +// return $response->withJson([ +// 'ret' => 0, +// 'msg' => '优惠码使用次数已达上限', +// ]); } } @@ -85,55 +86,17 @@ final class CouponController extends BaseController if ($total_use_limit > 0 && $coupon->use_count >= $total_use_limit) { return $response->withJson([ 'ret' => 0, - 'msg' => $invalid_coupon_msg, + 'msg' => '优惠码使用次数已达上限', ]); } $content = json_decode($coupon->content); $invalid_coupon_msg = "优惠码有效"; -// $iRet = 1; -// $sMsg = "优惠码可用"; -// -// $sDateNow = date("Y-m-d"); -//// $sDateNow = "2025-05-02"; -// $oHuodong = Huodong::where("start_date", "<=", $sDateNow)->where("end_date", ">=", $sDateNow)->first(); -// -// if ($oHuodong) { -// if ($oHuodong->class == "A") { -// if ($content->type === 'percentage') { -// -// $content->value = $oHuodong->coupon_global; -// $iRet = 2; -// $sMsg = '该优惠码可用,在【'.$oHuodong->title.'】期间视为-'.$oHuodong->coupon_global.'%优惠。'; -// -// } -// } -// } -// -// if ($content->type === 'percentage') { -// $discount = $product->price * $content->value / 100; -// } else { -// $discount = $content->value; -// } -// -// $buy_price = $product->price - $discount; - -// return $response->withJson([ -// 'ret' => $iRet, -// 'msg' => $sMsg, -// 'discount' => $discount, -// 'buy_price' => $buy_price, -// ]); return $response->withJson([ 'ret' => 1, 'msg' => $invalid_coupon_msg, 'coupon_value' => $content->value, -// 'name' => 8888, -// 'code' => 111, -// 'shop' => 222, -// 'credit' => $discount, -// 'total' => $buy_price, ]); } diff --git a/src/Services/Payment.php b/src/Services/Payment.php index c5e487838..195b4d7cc 100755 --- a/src/Services/Payment.php +++ b/src/Services/Payment.php @@ -265,6 +265,9 @@ final class Payment } if ($coupon_raw !== '') { + + $aPayOrderStatus = ["activated", "pending", "expired"]; + $coupon = (new UserCoupon())->where('code', $coupon_raw)->first(); if ($coupon === null || ($coupon->expire_time !== 0 && $coupon->expire_time < time())) { @@ -301,7 +304,7 @@ final class Payment $coupon_use_limit = $coupon_limit->use_time; if ($coupon_use_limit > 0) { - $user_use_count = (new Order())->where('user_id', $user->id)->where('user_coupon', $coupon->code)->count(); + $user_use_count = (new Order())->where('user_id', $user->id)->where('user_coupon', $coupon->code)->whereIn("status", $aPayOrderStatus)->count(); if ($user_use_count >= $coupon_use_limit) { return $response->withJson([ 'ret' => 0, @@ -352,7 +355,7 @@ final class Payment } if ($product_limit->new_user_required !== 0) { - $order_count = (new Order())->where('user_id', $user->id)->count(); + $order_count = (new Order())->where('user_id', $user->id)->whereIn("status", $aPayOrderStatus)->count(); if ($order_count > 0) { return $response->withJson([ 'ret' => 0,