Jelajahi Sumber

order across day

zz 5 tahun lalu
induk
melakukan
d2aa371cd4
1 mengubah file dengan 50 tambahan dan 1 penghapusan
  1. 50 1
      app/Modules/Trade/Pay/OrderPaySuccess.php

+ 50 - 1
app/Modules/Trade/Pay/OrderPaySuccess.php

@@ -3,6 +3,7 @@
 namespace App\Modules\Trade\Pay;
 
 use App\Modules\Subscribe\Models\Order;
+use DB;
 
 /**
  * 
@@ -18,6 +19,8 @@ class OrderPaySuccess
     public static function handle(string $trade_no, string $transaction_id)
     {
         $order = Order::where('trade_no', $trade_no)->first();
+        //订单跨天
+        $is_change = self::orderAcrossDay($order);
         $order->transaction_id = $transaction_id;
         if ($order) {
             if ($order->status == 'PAID') {
@@ -31,9 +34,55 @@ class OrderPaySuccess
             } elseif ($order->order_type == 'RECHARGE') {
                 $app = new RechargeOrderPaySuccess($order);
             }
-            return $app->success();
+            $status =  $app->success();
+            if ($is_change) {
+                DB::table('orders')->where('id', $order->id)->update([
+                    'pay_end_at' => date('Y-m-d H:i:s', time() + 5),
+                    'updated_at' => date('Y-m-d H:i:s', time() + 5),
+                    'created_at' => date('Y-m-d H:i:s')
+                ]);
+            }
+            return $status;
         } else {
             return false;
         }
     }
+
+
+    private static function orderAcrossDay($order_info)
+    {
+        if (date('Y-m-d', strtotime($order_info->created_at)) == date('Y-m-d')) return false;
+        $created_at = date('Y-m-d H:i:s', strtotime($order_info->created_at));
+        $trade_no = $order_info->trade_no;
+        $init_order = [
+            'distribution_channel_id' => $order_info->distribution_channel_id,
+            'uid' => $order_info->uid,
+            'product_id' => $order_info->product_id,
+            'price' => $order_info->price,
+            'pay_type' => $order_info->pay_type,
+            'trade_no' => 'cd-' . $trade_no,
+            'pay_merchant_source' => $order_info->pay_merchant_source,
+            'pay_merchant_id' => $order_info->pay_merchant_id,
+            'create_ip' => $order_info->create_ip,
+            'send_order_id' => $order_info->send_order_id,
+            'send_order_name' => $order_info->send_order_name,
+            'order_type' => $order_info->order_type,
+            'from_bid' => $order_info->from_bid,
+            'from_type' => $order_info->from_type,
+            'activity_id' => $order_info->activity_id,
+            'inner_send_order_id' => $order_info->inner_send_order_id,
+            'status' => 'UNPAID',
+            'transaction_id' => '',
+            'pay_end_at' => '0000-00-00 00:00:00',
+            'created_at' => $created_at,
+            'updated_at' => $created_at
+        ];
+        try {
+            DB::table('orders')->insert($init_order);
+        } catch (\Exception $e) {
+            return false;
+        }
+        return true;
+    }
+
 }