CoponController.php 767 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Coupon;
  6. class CouponController extends Controller
  7. {
  8. public function check (Request $request) {
  9. if (empty($request->input('code'))) {
  10. abort(500, '优惠券码不能为空');
  11. }
  12. $coupon = Coupon::where('code', $request->input('code'))->first();
  13. if (!$coupon) {
  14. abort(500, '优惠券无效');
  15. }
  16. if (time() < $coupon->started_at) {
  17. abort(500, '优惠券还未到可用时间');
  18. }
  19. if (time() > $coupon->ended_at) {
  20. abort(500, '优惠券已过期');
  21. }
  22. return response([
  23. 'data' => $coupon
  24. ]);
  25. }
  26. }