CouponService.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\admin\service\coupon;
  3. use app\model\CouponDetail;
  4. use support\Db;
  5. class CouponService
  6. {
  7. /**
  8. * @Desc 优惠券自动过期
  9. * @Author Gorden
  10. * @Date 2024/8/26 17:58
  11. *
  12. * @return void
  13. */
  14. public static function checkCouponExpired()
  15. {
  16. $couponDetails = Db::select("select * from app_coupon_detail where (coupon_detail_status = 'INIT' OR coupon_detail_status = 'PENDING' OR coupon_detail_status = 'ACTIVED' OR coupon_detail_status = 'WAITING') AND coupon_detail_deadline_datetime != '' AND CAST(UNIX_TIMESTAMP(coupon_detail_deadline_datetime) as SIGNED) < " . time());
  17. foreach ($couponDetails as $detail) {
  18. $endTimeUnix = strtotime($detail->coupon_detail_deadline_datetime);
  19. if ($endTimeUnix < time()) {
  20. CouponDetail::where('coupon_detail_id', $detail->coupon_detail_id)->update(['coupon_detail_status' => 'EXPIRED']);
  21. echo $detail->coupon_detail_id . "已过期\n";
  22. }
  23. }
  24. }
  25. public static function couponClassifyInfo($classify, $category, $value, $limit)
  26. {
  27. try {
  28. switch ($classify) {
  29. case "满减券":
  30. if (!empty($limit) && $category == 'NORMAL') {
  31. return "满" . $limit . '减' . $value;
  32. }elseif (!empty($limit) && !empty($value) && $category == 'PIECE'){
  33. return "满" . intval($limit) . '件减' . $value;
  34. }
  35. break;
  36. case "立减券":
  37. return "立减" . $value;
  38. break;
  39. case "抵用券":
  40. return "抵用券";
  41. break;
  42. case "折扣券":
  43. if (!empty($limit) && $category == 'NORMAL') {
  44. return "满" . $limit . '打' . ($value / 10) . '折';
  45. }else if (!empty($limit) && !empty($value) && $category == 'PIECE') {
  46. return "满" . intval($limit) . '件打' . ($value / 10) . '折';
  47. } else {
  48. return $value/10 . '折';
  49. }
  50. break;
  51. case "赠品券":
  52. return "赠品券";
  53. break;
  54. case "福利券":
  55. return '抵扣' . $value;
  56. break;
  57. case "年卡":
  58. return "年卡";
  59. break;
  60. case "季卡":
  61. return "季卡";
  62. break;
  63. case "月卡":
  64. return "月卡";
  65. break;
  66. }
  67. } catch (\Exception $e) {
  68. }
  69. }
  70. }