CouponService.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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, $value, $limit)
  26. {
  27. try {
  28. switch ($classify){
  29. case "满减券":
  30. return "满".$limit.'减'.$value;
  31. break;
  32. case "立减券":
  33. return "立减".$value;
  34. break;
  35. case "抵用券":
  36. return "抵用券";
  37. break;
  38. case "折扣券":
  39. if (!empty($limit)){
  40. return "满".$limit.'打'.($value/10).'折';
  41. }else{
  42. return $value.'折';
  43. }
  44. break;
  45. case "赠品券":
  46. return "赠品券";
  47. break;
  48. case "福利券":
  49. if (!empty($limit)){
  50. return "满".$limit.'抵扣'.$value;
  51. }else{
  52. return '抵扣'.$value;
  53. }
  54. break;
  55. case "年卡":
  56. return "年卡";
  57. break;
  58. case "季卡":
  59. return "季卡";
  60. break;
  61. case "月卡":
  62. return "月卡";
  63. break;
  64. }
  65. }catch (\Exception $e){}
  66. }
  67. }