gorden 7 月之前
父節點
當前提交
5442da34e7
共有 1 個文件被更改,包括 77 次插入60 次删除
  1. 77 60
      app/admin/controller/order/WholeController.php

+ 77 - 60
app/admin/controller/order/WholeController.php

@@ -460,6 +460,8 @@ class WholeController extends Curd
         $order->sheet_amount = number_format($sheetAmount, 2);
 
         $payDetails = PayDetail::where('join_pay_order_id', $order->order_groupby)
+            ->where('pay_category', '<>', 'REFUND')
+            ->where('pay_status', 'SUCCESS')
             ->select('pay_id', 'pay_category', 'pay_prepayid', 'pay_paytimes', 'pay_status', 'pay_amount', 'pay_extend_json')
             ->get();
         if (count($payDetails) > 1) {
@@ -2359,15 +2361,27 @@ class WholeController extends Curd
                     $prefix = substr($params['qrcode_nbr'], 0, 2);
                     if (in_array($prefix, [10, 11, 12, 13, 14, 15])) {
                         $params['pay_category'] = 'WXPAY';
-                        if ($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS') {
-                            Db::rollBack();
-                            return json_fail('支付失败');
+                        if ((!isset($result['return_code']) || $result['return_code'] != 'SUCCESS') || (!isset($result['result_code']) || $result['result_code'] != 'SUCCESS') || (empty($result['trade_state']) || $result['trade_state'] != 'SUCCESS')) {
+                            $params['order_status_system'] = 'PAYING';
+                            $params['order_status_payment'] = 'PENDING';
+                            $params['order_is_complete'] = 'N';
+//                            Db::rollBack();
+//                            return json_fail('支付失败');
+                        } else {
+                            $params['order_status_system'] = $systemStatus;
+                            $params['order_status_payment'] = 'SUCCESS';
+                            $params['order_is_complete'] = 'N';
                         }
                     } else if (in_array($prefix, [25, 26, 27, 28, 29, 30])) {
                         $params['pay_category'] = 'ALIPAY';
-                        if ($result['code'] != '10000' || $result['msg'] != 'Success') {
-                            Db::rollBack();
-                            return json_fail('支付失败');
+                        if ((!isset($result['code']) || $result['code'] != '10000') || (empty($result['trade_status']) || $result['trade_status'] != 'TRADE_SUCCESS')) {
+                            $params['order_status_system'] = 'PAYING';
+                            $params['order_status_payment'] = 'PENDING';
+//                            Db::rollBack();
+//                            return json_fail('支付失败');
+                        } else {
+                            $params['order_status_system'] = $systemStatus;
+                            $params['order_status_payment'] = 'SUCCESS';
                         }
                     } else {
                         Db::rollBack();
@@ -2379,8 +2393,8 @@ class WholeController extends Curd
                     // 账户支付的金额
                     $params['order_amount_pay'] = $orderAmountPay;
                 }
-                $params['order_status_system'] = $systemStatus;
-                $params['order_status_payment'] = 'SUCCESS';
+//                $params['order_status_system'] = $systemStatus;
+//                $params['order_status_payment'] = 'SUCCESS';
             }
 
             $orderConfigJson = [];
@@ -2521,60 +2535,63 @@ class WholeController extends Curd
             Db::commit();
 
             // 打小票
-            if (!empty($premises) && isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS') {
-                dump("insertCons 打小票");
-//            if (!empty($premises)){
-                if ($premises->dept_category != '餐厅') {
-                    $restaurant = SysDept::where('dept_super_id', $premises->dept_id)->where('dept_category', '餐厅')->first();
-                } else {
-                    $restaurant = $premises;
-                }
-                if (!empty($restaurant->dept_extend_json)) {
-                    $deptExtendJson = json_decode($restaurant->dept_extend_json, true);
-                    if (isset($deptExtendJson['printer'])) {
-                        foreach ($deptExtendJson['printer'] as $key => $item) {
-                            if (strpos($key, '结算') !== false && $params['order_status_payment'] == 'SUCCESS') {
-                                $voteData = [
-                                    'func' => 'procActionToPrinter',
-                                    'sign' => '',
-                                    'data' => [
-                                        'printer_premises' => $restaurant->dept_id,
-                                        'printer_device' => [
-                                            $key
-                                        ],
-                                        'printer_action' => 'ExecPrintOrder',
-                                        'printer_data' => [
-                                            'order_id' => $params['orderId'],
-                                            'order_batch' => ''
-                                        ]
-                                    ]
-                                ];
-                                http_post_json(getenv('VOTE_MENU_URL'), $voteData);
-                            }
-                            if ((strpos($key, '前台') !== false || strpos($key, '后厨') !== false)) {
-                                $voteData = [
-                                    'func' => 'procActionToPrinter',
-                                    'sign' => '',
-                                    'data' => [
-                                        'printer_premises' => $restaurant->dept_id,
-                                        'printer_device' => [
-                                            $key
-                                        ],
-                                        'printer_action' => 'ExecPrintOrder',
-                                        'printer_data' => [
-                                            'order_id' => $params['orderId'],
-                                            'order_batch' => ''
-                                        ]
-                                    ]
-                                ];
-                                http_post_json(getenv('VOTE_MENU_URL'), $voteData);
-                            }
-                        }
-                    }
-                }
-            }
+//            if (!empty($premises) && isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS') {
+//                dump("insertCons 打小票");
+////            if (!empty($premises)){
+//                if ($premises->dept_category != '餐厅') {
+//                    $restaurant = SysDept::where('dept_super_id', $premises->dept_id)->where('dept_category', '餐厅')->first();
+//                } else {
+//                    $restaurant = $premises;
+//                }
+//                if (!empty($restaurant->dept_extend_json)) {
+//                    $deptExtendJson = json_decode($restaurant->dept_extend_json, true);
+//                    if (isset($deptExtendJson['printer'])) {
+//                        foreach ($deptExtendJson['printer'] as $key => $item) {
+//                            if (strpos($key, '结算') !== false && $params['order_status_payment'] == 'SUCCESS') {
+//                                $voteData = [
+//                                    'func' => 'procActionToPrinter',
+//                                    'sign' => '',
+//                                    'data' => [
+//                                        'printer_premises' => $restaurant->dept_id,
+//                                        'printer_device' => [
+//                                            $key
+//                                        ],
+//                                        'printer_action' => 'ExecPrintOrder',
+//                                        'printer_data' => [
+//                                            'order_id' => $params['orderId'],
+//                                            'order_batch' => ''
+//                                        ]
+//                                    ]
+//                                ];
+//                                http_post_json(getenv('VOTE_MENU_URL'), $voteData);
+//                            }
+//                            if ((strpos($key, '前台') !== false || strpos($key, '后厨') !== false)) {
+//                                $voteData = [
+//                                    'func' => 'procActionToPrinter',
+//                                    'sign' => '',
+//                                    'data' => [
+//                                        'printer_premises' => $restaurant->dept_id,
+//                                        'printer_device' => [
+//                                            $key
+//                                        ],
+//                                        'printer_action' => 'ExecPrintOrder',
+//                                        'printer_data' => [
+//                                            'order_id' => $params['orderId'],
+//                                            'order_batch' => ''
+//                                        ]
+//                                    ]
+//                                ];
+//                                http_post_json(getenv('VOTE_MENU_URL'), $voteData);
+//                            }
+//                        }
+//                    }
+//                }
+//            }
 
             _syslog("订单", "创建订单成功");
+            if ($params['settlement_now'] == 'Y' && $params['order_status_payment'] != 'SUCCESS') {
+                return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
+            }
             return json_success('创建订单成功');
         } catch (BusinessException $e) {
             Db::rollBack();