Browse Source

订单自动完成

gorden 7 months ago
parent
commit
3b9b60dfc2

+ 15 - 6
app/admin/controller/order/WholeController.php

@@ -858,6 +858,14 @@ class WholeController extends Curd
         }
     }
 
+    /**
+     * @Desc 发货
+     * @Author Gorden
+     * @Date 2024/7/16 8:43
+     *
+     * @param Request $request
+     * @return Response
+     */
     public function delivery(Request $request)
     {
         if (!Order::where('order_id', $request->post('order_id'))->where('order_status_system', 'SENDING')->exists()) {
@@ -886,14 +894,15 @@ class WholeController extends Curd
                 $params['order_express_addtimes'] = strtotime($params['order_express_addtimes']);
 
                 $orderData = [
+                    'order_is_complete' => 'Y',
                     'order_status_system' => 'CONFIRM',
-                    'order_status_storage' => 'EXPRESSING'
+                    'order_status_storage' => 'DONE'
                 ];
 
                 // 7天后自动完成
-                $redis = Redis::connection();
-                $key = Order::AUTOMATIC_COMPLETE_PREFIX . date('Ymd', strtotime("+7 days"));
-                $redis->sadd($key, $params['order_id']);
+//                $redis = Redis::connection();
+//                $key = Order::AUTOMATIC_COMPLETE_PREFIX . date('Ymd', strtotime("+7 days"));
+//                $redis->sadd($key, $params['order_id']);
 
 //                $model = new OrderExpress();
                 $model = OrderExpress::where('join_express_order_id', $params['order_id'])->first();
@@ -906,9 +915,9 @@ class WholeController extends Curd
                     'order_status_storage' => 'EXPRESSING'
                 ];
 
-                // 15天后自动确认收货
+                // 15天后自动完成订单
                 $redis = Redis::connection();
-                $key = Order::AUTOMATIC_RECEIPT_PREFIX . date('Ymd', strtotime("+15 days"));
+                $key = Order::AUTOMATIC_COMPLETE_PREFIX . date('Ymd', strtotime("+15 days"));
                 $redis->sadd($key, $params['order_id']);
 
                 $model = OrderExpress::where('join_express_order_id', $params['order_id'])->first();

+ 43 - 5
app/admin/service/order/OrderService.php

@@ -30,15 +30,16 @@ class OrderService
                 // 订单主表
                 Order::where('order_id', $order->order_id)->update([
                     'order_is_complete' => 'Y',
-                    'order_status_system' => 'CONFIRM'
+                    'order_status_system' => 'CONFIRM',
+                    'order_status_storage'=> 'DONE'
                 ]);
                 // 订单详情表
-                OrderSheet::where('join_sheet_order_id', $order->order_id)->update(['order_sheet_status' => 'CONFIRM']);
+                OrderSheet::where('join_sheet_order_id', $order->order_id)->update(['order_sheet_status' => 'DONE']);
 
                 // 7天后自动完成 order_is_complete=Y
-                $redis = Redis::connection();
-                $key = Order::AUTOMATIC_COMPLETE_PREFIX . date('Ymd', strtotime("+7 days"));
-                $redis->sadd($key, $order->order_id);
+//                $redis = Redis::connection();
+//                $key = Order::AUTOMATIC_COMPLETE_PREFIX . date('Ymd', strtotime("+7 days"));
+//                $redis->sadd($key, $order->order_id);
             }
             Db::commit();
         } catch (\Exception $e) {
@@ -46,6 +47,43 @@ class OrderService
         }
     }
 
+    /**
+     * @Desc 自动完成订单
+     * @Author Gorden
+     * @Date 2024/7/16 9:37
+     *
+     * @return void
+     */
+    public static function AutomaticComplete()
+    {
+        Db::beginTransaction();
+        try {
+
+            $redis = Redis::connection();
+            $key = Order::AUTOMATIC_COMPLETE_PREFIX . date('Ymd');
+            $orderIds = $redis->smembers($key);
+
+            foreach ($orderIds as $orderId){
+                $order = Order::where('order_id',$orderId)
+                    ->select('order_is_complete','order_category','order_status_system')
+                    ->first();
+                if ($order && $order->order_is_complete != 'Y' && $order->order_category != 'RETURN' && in_array($order->order_status_system,['RECVING','SIGNED','CONFIRM'])){
+                    // 更新主表
+                    Order::where('order_id',$orderId)->update(['order_is_complete'=>'Y','order_status_system'=>'CONFIRM','order_status_storage'=>'DONE']);
+                    // sheet表
+                    OrderSheet::where('join_sheet_order_id',$orderId)->update(['order_sheet_status'=>'DONE']);
+                }
+            }
+
+            $redis->del($key);
+
+            Db::commit();
+        } catch (\Exception $e) {
+            dump($e->getMessage());
+            Db::rollBack();
+        }
+    }
+
     public static function checkPayingOrder()
     {
         try {

+ 10 - 0
app/event/ClientMessageEvent.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace app\event;
+
+class ClientMessageEvent
+{
+    public function delevery(){
+
+    }
+}

+ 2 - 1
composer.json

@@ -43,7 +43,8 @@
     "ldy/payment": "^3.6",
     "intervention/image": "^2.7",
     "webman/console": "^1.3",
-    "yansongda/pay": "v2.10"
+    "yansongda/pay": "v2.10",
+    "webman/event": "^1.0"
   },
   "suggest": {
     "ext-event": "For better performance. "

+ 5 - 0
config/event.php

@@ -0,0 +1,5 @@
+<?php
+
+return [
+    
+];

+ 4 - 0
config/plugin/webman/event/app.php

@@ -0,0 +1,4 @@
+<?php
+return [
+    'enable' => true,
+];

+ 17 - 0
config/plugin/webman/event/bootstrap.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * This file is part of webman.
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the MIT-LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @author    walkor<walkor@workerman.net>
+ * @copyright walkor<walkor@workerman.net>
+ * @link      http://www.workerman.net/
+ * @license   http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+
+return [
+    Webman\Event\BootStrap::class,
+];

+ 7 - 0
config/plugin/webman/event/command.php

@@ -0,0 +1,7 @@
+<?php
+
+use Webman\Event\EventListCommand;
+
+return [
+    EventListCommand::class
+];

+ 3 - 1
process/Task.php

@@ -27,10 +27,12 @@ class Task
             MessageService::unreadChatMessage();
         });
 
-        // 每天的8点执行,注意这里省略了秒位
+        // 每天的2点执行,注意这里省略了秒位
         new Crontab('0 2 * * *', function () {
             // 签收后7天自动确认收货(已完成)
             OrderService::AutomaticReceipt();
+            // 发货后15天自动完成
+            OrderService::AutomaticComplete();
         });
     }
 }