Kirin пре 2 година
родитељ
комит
588839d2ca
2 измењених фајлова са 12 додато и 2 уклоњено
  1. 10 0
      app/admin/controller/store/StoreProduct.php
  2. 2 2
      app/models/store/StoreCart.php

+ 10 - 0
app/admin/controller/store/StoreProduct.php

@@ -317,6 +317,7 @@ class StoreProduct extends AuthController
             ['is_consumer', 0],
             ['bar_code', ''],
             ['store_bag', 0],
+            ['selectTime', []]
         ]);
         foreach ($data['activity'] as $k => $v) {
             if ($v == '秒杀') {
@@ -327,6 +328,15 @@ class StoreProduct extends AuthController
                 $data['activity'][$k] = 3;
             }
         }
+        $data['time_area_discount'] = [];
+        foreach ($data['selectTime'] as $v) {
+            if (strtotime(date('Y-m-d') . ' ' . ($v['start'] ?? '00:00')) >= strtotime(date('Y-m-d') . ' ' . ($v['end'] ?? '00:00'))) {
+                return Json::fail('区间折扣的开始时间需要小于结束时间');
+            }
+            $data['time_area_discount'][] = [$v['start'] . '-' . $v['end'] => $v['value']];
+        }
+        $data['time_area_discount'] = json_encode($data['time_area_discount']);
+        unset($data['selectTime']);
         $data['activity'] = implode(',', $data['activity']);
         $detail = $data['attrs'];
         $data['price'] = min(array_column($detail, 'price'));

+ 2 - 2
app/models/store/StoreCart.php

@@ -274,8 +274,8 @@ class StoreCart extends BaseModel
                                 if (!(count($times) == 2)) {
                                     break;
                                 }
-                                $start = strtotime(date('Y-m-d') . $times[0]);
-                                $end = strtotime(date('Y-m-d') . $times[1]);
+                                $start = strtotime(date('Y-m-d') . ' ' . $times[0]);
+                                $end = strtotime(date('Y-m-d') . ' ' . $times[1]);
                                 if (time() > $start && time() <= $end) {
                                     $discount = $v;
                                 }