2019-12-31 17:49:24 +08:00
|
|
|
<?php
|
|
|
|
|
2020-01-29 16:08:50 +08:00
|
|
|
namespace App\Http\Controllers\User;
|
2019-12-31 17:49:24 +08:00
|
|
|
|
2020-01-29 16:08:50 +08:00
|
|
|
use App\Http\Controllers\Controller;
|
2019-12-31 17:49:24 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Models\Coupon;
|
|
|
|
|
|
|
|
class CouponController extends Controller
|
|
|
|
{
|
2020-01-11 13:36:52 +08:00
|
|
|
public function check(Request $request)
|
|
|
|
{
|
2020-01-01 15:59:53 +08:00
|
|
|
if (empty($request->input('code'))) {
|
2020-01-01 16:20:44 +08:00
|
|
|
abort(500, '优惠券码不能为空');
|
2020-01-01 15:59:53 +08:00
|
|
|
}
|
|
|
|
$coupon = Coupon::where('code', $request->input('code'))->first();
|
|
|
|
if (!$coupon) {
|
|
|
|
abort(500, '优惠券无效');
|
|
|
|
}
|
2020-01-01 23:42:25 +08:00
|
|
|
if ($coupon->limit_use <= 0 && $coupon->limit_use !== NULL) {
|
2020-01-01 23:40:14 +08:00
|
|
|
abort(500, '优惠券已无可用次数');
|
|
|
|
}
|
2020-01-01 15:59:53 +08:00
|
|
|
if (time() < $coupon->started_at) {
|
|
|
|
abort(500, '优惠券还未到可用时间');
|
|
|
|
}
|
|
|
|
if (time() > $coupon->ended_at) {
|
|
|
|
abort(500, '优惠券已过期');
|
|
|
|
}
|
|
|
|
return response([
|
|
|
|
'data' => $coupon
|
|
|
|
]);
|
2019-12-31 17:49:24 +08:00
|
|
|
}
|
2020-01-11 13:36:52 +08:00
|
|
|
}
|