Browse Source

周期券发过去的券

gorden 5 months ago
parent
commit
57c34bdb11
1 changed files with 7 additions and 1 deletions
  1. 7 1
      app/admin/service/coupon/CouponDetailService.php

+ 7 - 1
app/admin/service/coupon/CouponDetailService.php

@@ -233,6 +233,9 @@ class CouponDetailService
 
             $interval = (new \DateTime(date($gainMonday)))->diff(new \DateTime($nowMonday));
             $weekCut = $interval->days / 7;
+            if (strtotime($periodJson['gain_datetime']) < time() && $weekCut > 0) {
+                $weekCut = -$weekCut;
+            }
             if ($val < 1) {
                 if ($now_nbr == 1) {
                     $params['coupon_detail_gain_datetime'] = $gainMonday;
@@ -255,8 +258,11 @@ class CouponDetailService
         } elseif ($periodJson['unit'] == 'month') {
             $val = $periodJson['val'] - 1;
             // 选的日期的1号距离今月1号是几个月
-            $interval = (new \DateTime(date('Y-m-01 00:00:00', strtotime($periodJson['gain_datetime']))))->diff(new \DateTime(date('Y-m-01 00:00:00')));
+            $interval = (new \DateTime(date('Y-m-02 00:00:00', strtotime($periodJson['gain_datetime']))))->diff(new \DateTime(date('Y-m-02 00:00:00')));
             $monthCut = $interval->m + ($interval->y * 12);
+            if (strtotime($periodJson['gain_datetime']) < time() && $monthCut > 0) {
+                $monthCut = -$monthCut;
+            }
             if ($val < 1) {
                 if ($now_nbr == 1) {
                     $params['coupon_detail_gain_datetime'] = date('Y-m-01 00:00:00', strtotime($periodJson['gain_datetime']));