gorden hai 9 meses
pai
achega
c082af2c0d
Modificáronse 2 ficheiros con 42 adicións e 12 borrados
  1. 37 9
      app/admin/service/order/OrderService.php
  2. 5 3
      process/Task.php

+ 37 - 9
app/admin/service/order/OrderService.php

@@ -19,17 +19,45 @@ class OrderService
      */
     public static function AutomaticReceipt()
     {
-        $redis = Redis::connection();
-        $key = Order::AUTOMATIC_RECEIPT_PREFIX . date('Ymd');
-        if (!$redis->exists($key)) {
-            return;
+        try {
+            Db::beginTransaction();
+            $timeUnix = strtotime("-7 days");
+            $orders = Order::where('order_status_system', 'SIGNED')
+                ->where('order_addtimes', '<', $timeUnix)
+                ->get();
+            foreach ($orders as $order) {
+                // 订单主表
+                Order::where('order_id', $order->order_id)->update([
+                    'order_is_complete' => 'Y',
+                    'order_status_system' => 'CONFIRM'
+                ]);
+                // 订单详情表
+                OrderSheet::where('join_sheet_order_id', $order->order_id)->update(['order_sheet_status' => 'CONFIRM']);
+            }
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollBack();
         }
-        Db::beginTransaction();
+    }
+
+    public static function checkPayingOrder()
+    {
         try {
-            $orderIds = $redis->smembers($key);
-            Order::whereIn('order_id', $orderIds)->update(['order_is_complete' => 'Y', 'order_status_system' => 'CONFIRM']);
-            OrderSheet::whereIn('join_sheet_order_id', $orderIds)->update(['order_sheet_status' => 'CONFIRM']);
-            $redis->del($key);
+            Db::beginTransaction();
+            $timeUnix = strtotime("-15 minutes");
+            $orders = Order::where('order_status_system', 'PAYING')
+                ->where('order_addtimes', '<', $timeUnix)
+                ->get();
+            foreach ($orders as $order) {
+                // 订单主表
+                Order::where('order_id', $order->order_id)->update([
+                    'order_category' => 'CANCEL',
+                    'order_status_system' => 'CANCEL',
+                    'order_status_payment' => 'CANCEL'
+                ]);
+                // 订单详情表
+                OrderSheet::where('join_sheet_order_id', $order->order_id)->update(['order_sheet_status' => 'CANCEL']);
+            }
 
             Db::commit();
         } catch (\Exception $e) {

+ 5 - 3
process/Task.php

@@ -14,13 +14,15 @@ class Task
         new Crontab('0 */1 * * * *', function () {
             // 商品自动上架
             GoodsService::checkListing();
-            // 商品自动
+            // 商品自动
             GoodsService::checkOffListing();
+            // 未支付30分钟取消
+            OrderService::checkPayingOrder();
         });
 
         // 每天的8点执行,注意这里省略了秒位
-        new Crontab('0 8 * * *', function () {
-            // 自动确认收货
+        new Crontab('0 2 * * *', function () {
+            // 签收后7天自动确认收货
             OrderService::AutomaticReceipt();
         });
     }