CouponService.php 2.5 KB

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