瀏覽代碼

Merge branch 'master' into custom_manager
合并代码

yb 7 月之前
父節點
當前提交
b2c3fbf476

+ 21 - 4
app/admin/controller/coupon/CouponController.php

@@ -126,6 +126,11 @@ class CouponController extends Curd
                     $item['premises_range'] = 'all';
                 }
             }
+            if (!empty($item['coupon_validdate_begin']) && !empty($item['coupon_validdate_end'])){
+                $item['coupon_use_time'] = 'date';
+            }elseif ($item['coupon_validdate_day']){
+                $item['coupon_use_time'] = 'day';
+            }
         }
 
         return $items;
@@ -223,8 +228,14 @@ class CouponController extends Curd
         $params = $request->post();
         $data = $this->inputFilter($params);
         $data['coupon_id'] = "CU" . str_pad(SysSerial::getSerial(), 6, '0') . random_string(6, 'up');
-        $data['coupon_validdate_begin'] = date("Y-m-d H:i:s", strtotime($data['coupon_validdate_begin']));
-        $data['coupon_validdate_end'] = date("Y-m-d H:i:s", strtotime($data['coupon_validdate_end']));
+        if (!empty($params['coupon_use_time']) && $params['coupon_use_time'] == 'date'){
+            $data['coupon_validdate_day'] = null;
+            $data['coupon_validdate_begin'] = date("Y-m-d H:i:s", strtotime($data['coupon_validdate_begin']));
+            $data['coupon_validdate_end'] = date("Y-m-d H:i:s", strtotime($data['coupon_validdate_end']));
+        }elseif (!empty($params['coupon_use_time']) && $params['coupon_use_time'] == 'day'){
+            $data['coupon_validdate_begin'] = null;
+            $data['coupon_validdate_end'] = null;
+        }
         $couponJson = [];
         if ($params['coupon_use_member'] == 'member' && isset($params['member_list'])) {
             $couponJson['member']['list'] = $params['member_list'];
@@ -329,8 +340,14 @@ class CouponController extends Curd
         $primary_key = $this->model->getKeyName();
         $id = $request->post($primary_key);
         $data = $this->inputFilter($params);
-        $data['coupon_validdate_begin'] = date("Y-m-d H:i:s", strtotime($data['coupon_validdate_begin']));
-        $data['coupon_validdate_end'] = date("Y-m-d H:i:s", strtotime($data['coupon_validdate_end']));
+        if (!empty($params['coupon_use_time']) && $params['coupon_use_time'] == 'date'){
+            $data['coupon_validdate_day'] = null;
+            $data['coupon_validdate_begin'] = date("Y-m-d H:i:s", strtotime($data['coupon_validdate_begin']));
+            $data['coupon_validdate_end'] = date("Y-m-d H:i:s", strtotime($data['coupon_validdate_end']));
+        }elseif (!empty($params['coupon_use_time']) && $params['coupon_use_time'] == 'day'){
+            $data['coupon_validdate_begin'] = null;
+            $data['coupon_validdate_end'] = null;
+        }
         $model = $this->model->find($id);
         if (!$model) {
             throw new BusinessException('记录不存在', 2);

+ 8 - 8
app/admin/controller/notify/OrderPayController.php

@@ -12,11 +12,11 @@ class OrderPayController
     {
         Log::channel('pay')->info("WXPAY_NOTIFY_REPLY", $request->all());
         try {
-            $config = config('payment.wxpay');
-            $config['notify_url'] = getenv('NOTIFY_DOMAIN_ADMIN').'/notify/orderPay/wxpay';
-            Pay::wechat($config)->success()->send();
+//            $config = config('payment.wxpay');
+//            $config['notify_url'] = getenv('NOTIFY_DOMAIN_ADMIN').'/notify/orderPay/wxpay';
+//            Pay::wechat($config)->success()->send();
 
-            exit('<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>');
+            echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
         }catch (\Exception $e){
             Log::channel('pay')->info("WXPAY_NOTIFY_REPLY_FAIL", ['msg'=>"回复失败"]);
         }
@@ -27,11 +27,11 @@ class OrderPayController
     {
         Log::channel('pay')->info("ALIPAY_NOTIFY_REPLY", $request->all());
         try {
-            $config = config('payment.alipay');
-            $config['notify_url'] = getenv('NOTIFY_DOMAIN_ADMIN').'/notify/orderPay/alipay';
-            Pay::alipay($config)->success()->send();
+//            $config = config('payment.alipay');
+//            $config['notify_url'] = getenv('NOTIFY_DOMAIN_ADMIN').'/notify/orderPay/alipay';
+//            Pay::alipay($config)->success()->send();
             header('Content-type: application/json');
-            exit(json_encode(['code' => '200', 'msg' => 'success']));
+            echo json_encode(['code' => '200', 'msg' => 'success']);
         }catch (\Exception $e){
             Log::channel('pay')->info("ALIPAY_NOTIFY_REPLY_FAIL", ['msg'=>"回复失败"]);
         }

+ 14 - 4
app/admin/controller/notify/RechargeController.php

@@ -41,6 +41,14 @@ class RechargeController
 //    }
 
 
+    /**
+     * @Desc
+     * @Author Gorden
+     * @Date 2024/8/19 13:33
+     *
+     * @param Request $request
+     * @return \support\Response
+     */
     public function paySuccess(Request $request)
     {
         $data = $request->post();
@@ -52,8 +60,10 @@ class RechargeController
             return json_fail('参数异常');
         }
         try {
-            _syslog("APP充值","APP充值成功",$data,$data,1001);
-            return $this->disposePaySuccess($data['pay_id']);
+            $result = $this->disposePaySuccess($data['pay_id']);
+            _syslog("APP充值","APP处理完成",$data,$data,1001);
+
+            return $result;
         }catch(BusinessException $e){
             _syslog("APP充值","APP充值失败",$data,$data,1001);
             return json_fail("处理失败");
@@ -82,8 +92,8 @@ class RechargeController
     public function disposePaySuccess($payId){
         $payDetail = PayDetail::find($payId);
         if (!$payDetail || $payDetail->pay_status != 'SUCCESS') {
-            // throw new BusinessException("支付状态异常");
-           return json_fail("支付状态异常");
+             throw new BusinessException("支付状态异常");
+//           return json_fail("支付状态异常");
         }
         $extendJson = [];
         if (!empty($payDetail->pay_extend_json)) {

+ 40 - 22
app/admin/controller/order/RefundController.php

@@ -19,20 +19,20 @@ class RefundController extends Curd
     {
         $this->model = new OrderReturn();
         $this->validate = true;
-        $this->validateClass=new ReturnValidate();
+        $this->validateClass = new ReturnValidate();
     }
 
     public function select(Request $request): Response
     {
         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
         $order = $request->get('order', 'desc');
-        $type = $request->get('type','');
+        $type = $request->get('type', '');
         $field = $field ?? 'order_return_addtimes';
         $where['order_return_category'] = '退款';
-        if ($type == 'today'){
+        if ($type == 'today') {
             $where['order_return_addtimes'] = [
-                strtotime(date('Y-m-d').' 00:00:00'),
-                strtotime(date('Y-m-d').' 23:59:59')
+                strtotime(date('Y-m-d') . ' 00:00:00'),
+                strtotime(date('Y-m-d') . ' 23:59:59')
             ];
         }
         $query = $this->doSelect($where, $field, $order);
@@ -45,8 +45,8 @@ class RefundController extends Curd
             'member' => function ($query) {
                 $query->select('member_id', 'member_mobile');
             },
-            'cert'=>function($query){
-                $query->select('join_cert_member_id','member_cert_name');
+            'cert' => function ($query) {
+                $query->select('join_cert_member_id', 'member_cert_name');
             },
             'order' => function ($query) {
                 $query->select('order_id', 'order_name');
@@ -89,13 +89,13 @@ class RefundController extends Curd
 
     public function afterQuery($items)
     {
-        foreach ($items as &$item){
-            if (!empty($item['order_return_apply_json']) && is_json($item['order_return_apply_json'])){
-                $json = json_decode($item['order_return_apply_json'],true);
+        foreach ($items as &$item) {
+            if (!empty($item['order_return_apply_json']) && is_json($item['order_return_apply_json'])) {
+                $json = json_decode($item['order_return_apply_json'], true);
                 $item['order_return_apply_json'] = $json['apply'] ?? '';
             }
-            if (!empty($item['order_return_recharge_json']) && is_json($item['order_return_recharge_json'])){
-                $json = json_decode($item['order_return_recharge_json'],true);
+            if (!empty($item['order_return_recharge_json']) && is_json($item['order_return_recharge_json'])) {
+                $json = json_decode($item['order_return_recharge_json'], true);
                 $item['order_return_recharge_json'] = $json['change'] ?? '';
             }
 
@@ -113,14 +113,14 @@ class RefundController extends Curd
         if (!$model) {
             throw new BusinessException('记录不存在', 2);
         }
-        if (empty($model->order_return_accept_datetimes) && $model->order_return_status == 'PENDING' && $data['order_return_status'] == 'DOING'){
+        if (empty($model->order_return_accept_datetimes) && $model->order_return_status == 'PENDING' && $data['order_return_status'] == 'DOING') {
             $data['order_return_accept_datetimes'] = date('Y-m-d H:i:s');
         }
-        if (!empty($data['order_return_apply_json'])){
-            $data['order_return_apply_json'] = json_encode(['apply'=>$data['order_return_apply_json']]);
+        if (!empty($data['order_return_apply_json'])) {
+            $data['order_return_apply_json'] = json_encode(['apply' => $data['order_return_apply_json']]);
         }
-        if (!empty($data['order_return_recharge_json'])){
-            $data['order_return_recharge_json'] = json_encode(['change'=>$data['order_return_recharge_json']]);
+        if (!empty($data['order_return_recharge_json'])) {
+            $data['order_return_recharge_json'] = json_encode(['change' => $data['order_return_recharge_json']]);
         }
 
         unset($data[$primary_key]);
@@ -175,13 +175,13 @@ class RefundController extends Curd
                 $item['goods']['components'] = $goodsArr;
             }
 
-            if (!empty($item['refund'])){
-                if (!empty($item['refund']['order_return_apply_json'])  && is_json($item['refund']['order_return_apply_json'])){
-                    $json = json_decode($item['refund']['order_return_apply_json'],true);
+            if (!empty($item['refund'])) {
+                if (!empty($item['refund']['order_return_apply_json']) && is_json($item['refund']['order_return_apply_json'])) {
+                    $json = json_decode($item['refund']['order_return_apply_json'], true);
                     $item['refund']['order_return_apply_json'] = $json['reason'] ?? '';
                 }
-                if (!empty($item['refund']['order_return_recharge_json'])  && is_json($item['refund']['order_return_recharge_json'])){
-                    $json = json_decode($item['refund']['order_return_recharge_json'],true);
+                if (!empty($item['refund']['order_return_recharge_json']) && is_json($item['refund']['order_return_recharge_json'])) {
+                    $json = json_decode($item['refund']['order_return_recharge_json'], true);
                     $item['refund']['order_return_recharge_json'] = $json['change'] ?? '';
                 }
             }
@@ -197,4 +197,22 @@ class RefundController extends Curd
 
         return json_success('', $data);
     }
+
+    public function customRefund(Request $request)
+    {
+        $orderId = $request->post('order_id','');
+        $orderId = $request->post('order_id', '');
+        $amount = $request->post('refund_amount', 0);
+        $password = $request->post('refund_password', '');
+        if (!$orderId || !$amount || !$password) {
+            return json_fail('参数异常');
+        }
+        if ($password != '123456') {
+            return json_fail('支付密码错误');
+        }
+        $order = Order::where('order_id',$orderId)->where('order_status_payment','SUCCESS')->first();
+        if (!$order){
+            return json_fail("订单异常");
+        }
+    }
 }

+ 188 - 53
app/admin/controller/order/WholeController.php

@@ -246,7 +246,7 @@ class WholeController extends Curd
                 } else if (!empty($payWay[0]) && $payWay[0] == 'ALIPAY') {
                     $item['payWay'] = '支付宝';
                 }
-            }else{
+            } else {
                 $item['payWay'] = null;
             }
         }
@@ -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) {
@@ -957,10 +959,6 @@ class WholeController extends Curd
                 }
                 // 去支付
                 $result = OrderService::qrcodePay($params);
-                // $result = [
-                //     'return_code'=>'SUCCESS',
-                //     'result_code' => 'SUCCESS'
-                // ];
                 $result = json_encode($result);
                 $params['pay_json_response'] = $result;
                 $result = json_decode($result, true);
@@ -968,19 +966,31 @@ 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')) {
+                        $order->order_status_system = 'PAYING';
+                        $order->order_status_payment = 'PENDING';
+                        $order->order_is_complete = 'N';
+//                        Db::rollBack();
+//                        return json_fail('支付失败');
+                    } else {
+                        $order->order_status_system = $systemStatus;
+                        $order->order_status_payment = 'SUCCESS';
                     }
                 } 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')) {
+                        $order->order_status_system = 'PAYING';
+                        $order->order_status_payment = 'PENDING';
+                        $order->order_is_complete = 'N';
+//                        Db::rollBack();
+//                        return json_fail('支付失败');
+                    } else {
+                        $order->order_status_system = $systemStatus;
+                        $order->order_status_payment = 'SUCCESS';
                     }
                 } else {
                     Db::rollBack();
-                    return json_fail('二维码错误');
+                    return json_fail('付款码无效');
                 }
 
                 // 组合支付,追加加一条支付记录 pay_detail
@@ -1004,8 +1014,6 @@ class WholeController extends Curd
                     $params['pay_category'] = $submitPayCategory;
                 }
 
-                $order->order_status_system = $systemStatus;
-                $order->order_status_payment = 'SUCCESS';
                 // 账户支付的金额
                 $params['order_amount_pay'] = $accountAmount;
             }
@@ -1165,6 +1173,10 @@ class WholeController extends Curd
                 }
             }
 
+            if ($order->order_status_payment != 'SUCCESS') {
+                _syslog("订单", "支付异常,检查是否有轮询");
+                return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
+            }
             _syslog("订单", "订单支付成功");
             return json_success('支付成功');
         } catch (\Exception $e) {
@@ -1354,19 +1366,31 @@ 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')) {
+                            $order->order_status_system = 'PAYING';
+                            $order->order_status_payment = 'PENDING';
+                            $order->order_is_complete = 'N';
+//                        Db::rollBack();
+//                        return json_fail('支付失败');
+                        } else {
+                            $order->order_status_system = $systemStatus;
+                            $order->order_status_payment = 'SUCCESS';
                         }
                     } 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')) {
+                            $order->order_status_system = 'PAYING';
+                            $order->order_status_payment = 'PENDING';
+                            $order->order_is_complete = 'N';
+//                        Db::rollBack();
+//                        return json_fail('支付失败');
+                        } else {
+                            $order->order_status_system = $systemStatus;
+                            $order->order_status_payment = 'SUCCESS';
                         }
                     } else {
                         Db::rollBack();
-                        return json_fail('二维码错误');
+                        return json_fail('付款码无效');
                     }
                 }
 
@@ -1374,8 +1398,6 @@ class WholeController extends Curd
                 OrderService::createPayConstituteDetail($params, $payDetail);
                 // 账户支付的金额
                 $params['order_amount_pay'] = $orderAmountPay;
-                $order->order_status_system = $systemStatus;
-                $order->order_status_payment = 'SUCCESS';
             }
             $orderConfigJson = [];
             if (!empty($order->order_config_json)) {
@@ -1453,7 +1475,10 @@ class WholeController extends Curd
                     }
                 }
             }
-
+            if ($order->order_status_payment != 'SUCCESS') {
+                _syslog("订单", "支付异常,检查是否有轮询");
+                return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
+            }
             _syslog("订单", "订单支付成功");
             return json_success('支付成功');
         } catch (\Exception $e) {
@@ -1861,20 +1886,35 @@ 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';
                         }
                     } 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';
+                            $params['order_is_complete'] = 'N';
+//                            Db::rollBack();
+//                            return json_fail('支付失败');
+                        } else {
+                            $params['order_status_system'] = $systemStatus;
+                            $params['order_status_payment'] = 'SUCCESS';
                         }
+                    }else{
+                        Db::rollBack();
+                        return json_fail('付款码无效');
                     }
 
                     // 组合支付,追加加一条支付记录 pay_detail
-                    if ($params['pay_constitute'] == 'Y' && $qrcodePayAmount > 0) {
+                    if ($params['pay_constitute'] == 'Y' && $qrcodePayAmount > 0 && $params['order_status_payment'] == 'SUCCESS') {
                         $insertPayDetailData = [
                             'join_pay_member_id' => $params['join_order_member_id'],
                             'join_pay_order_id' => $params['orderGroupId'],
@@ -1894,8 +1934,6 @@ class WholeController extends Curd
                         $params['pay_category'] = $submitPayCategory;
                     }
 
-                    $params['order_status_system'] = $systemStatus;
-                    $params['order_status_payment'] = 'SUCCESS';
                     // 账户支付的金额
                     $params['order_amount_pay'] = $accountAmount;
                 }
@@ -1926,10 +1964,13 @@ class WholeController extends Curd
                 }
                 $params['submit_premises_id'] = $premises->dept_id;
             }
-            if (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS' && !empty($params['dept_table_id'])) {
-                $table = SysDept::where('dept_id', $params['dept_table_id'])->where('dept_category', '桌台')->first();
+            if (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS' && !empty($params['dept_premises_id'])) {
+                $table = '';
+                if (!empty($params['dept_table_id'])){
+                    $table = SysDept::where('dept_id', $params['dept_table_id'])->where('dept_category', '桌台')->first();
+                }
                 $orderConfigJson['premises'] = $params['dept_premises_id'];
-                $orderConfigJson['dept'] = $premises->dept_id;
+                $orderConfigJson['dept'] = $premises->dept_id ?? 0;
                 $orderConfigJson['reach'] = "00:00";
                 $orderConfigJson['table'] = !empty($table) ? $table->dept_name : null;
                 $orderConfigJson['express'] = "到店吃";
@@ -2100,6 +2141,10 @@ class WholeController extends Curd
                 }
             }
 
+            if ($params['settlement_now'] == 'Y' && $params['order_status_payment'] != 'SUCCESS') {
+                _syslog("订单", "支付异常,检查是否有轮询");
+                return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
+            }
             _syslog("订单", "创建订单成功");
             return json_success('创建订单成功');
         } catch (BusinessException $e) {
@@ -2247,12 +2292,13 @@ class WholeController extends Curd
                 $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
                 $account->save();
 
+                $params['order_status_system'] = $systemStatus;
+                $params['order_status_payment'] = 'SUCCESS';
+
                 // 生成支付记录
                 OrderService::createPayDetail($params);
-
                 $params['order_amount_pay'] = $orderAmountPay;
-                $params['order_status_system'] = $systemStatus;
-                $params['order_status_payment'] = 'SUCCESS';
+
             }
             // if ($params['settlement_now'] == 'Y' && $params['pay_category'] == 'WELFARE') {  // 福利账户
             //     $account = MemberAccount::where('join_account_member_id', $params['join_order_member_id'])
@@ -2322,12 +2368,13 @@ class WholeController extends Curd
                 $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
                 $account->save();
 
+
+                $params['order_status_system'] = $systemStatus;
+                $params['order_status_payment'] = 'SUCCESS';
                 // 生成支付记录
                 OrderService::createPayDetail($params);
 
                 $params['order_amount_pay'] = $orderAmountPay;
-                $params['order_status_system'] = $systemStatus;
-                $params['order_status_payment'] = 'SUCCESS';
             }
             //!empty($params['pay_category_constitute']) && in_array('CARD',$params['pay_category_constitute'])
             // if(($params['pay_constitute'] == 'Y' || $params['pay_category'] == 'QRCODE') && $params['settlement_now'] == 'Y' && !empty($params['qrcode_nbr'])){     // 付款码
@@ -2345,15 +2392,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';
                         }
                     } 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';
+                            $params['order_is_complete'] = 'N';
+//                            Db::rollBack();
+//                            return json_fail('支付失败');
+                        } else {
+                            $params['order_status_system'] = $systemStatus;
+                            $params['order_status_payment'] = 'SUCCESS';
                         }
                     } else {
                         Db::rollBack();
@@ -2365,8 +2424,6 @@ class WholeController extends Curd
                     // 账户支付的金额
                     $params['order_amount_pay'] = $orderAmountPay;
                 }
-                $params['order_status_system'] = $systemStatus;
-                $params['order_status_payment'] = 'SUCCESS';
             }
 
             $orderConfigJson = [];
@@ -2508,7 +2565,6 @@ class WholeController extends Curd
 
             // 打小票
             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();
@@ -2560,6 +2616,10 @@ class WholeController extends Curd
                 }
             }
 
+            if ($params['settlement_now'] == 'Y' && $params['order_status_payment'] != 'SUCCESS') {
+                _syslog("订单", "支付异常,检查是否有轮询");
+                return json_throw(2001, '支付异常', ['order_id' => $params['orderId']]);
+            }
             _syslog("订单", "创建订单成功");
             return json_success('创建订单成功');
         } catch (BusinessException $e) {
@@ -2662,7 +2722,7 @@ class WholeController extends Curd
                     'join_sheet_order_id' => $params['orderId'],
                     'join_sheet_goods_id' => $goods['goods_id'],
                     'join_sheet_goods_sku_id' => $goods['sku_id'],
-                    'order_sheet_status' => $params['settlement_now'] == 'Y' ? 'DONE' : 'PAYING',
+                    'order_sheet_status' => $params['settlement_now'] == 'Y' && $params['order_status_payment'] == 'SUCCESS' ? 'DONE' : 'PAYING',
                     'order_sheet_category' => (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS') ? 'DISHES' : 'NORMAL',
                     'order_sheet_num' => $goods['nbr'],
                     'order_sheet_price' => $goods['goods_sales_price'],
@@ -2733,7 +2793,7 @@ class WholeController extends Curd
             $data = [
                 'join_pay_member_id' => $params['join_order_member_id'],
                 'join_pay_order_id' => $params['orderGroupId'],
-                'pay_status' => $params['settlement_now'] == 'Y' ? 'SUCCESS' : 'WAITING',
+                'pay_status' => $params['settlement_now'] == 'Y' && $params['order_status_payment'] == 'SUCCESS' ? 'SUCCESS' : 'WAITING',
                 'pay_category' => $params['goods_classify'],
                 'pay_amount' => $params['order_amount_pay'],
                 'pay_prepayid' => $payPrepayid,
@@ -3488,7 +3548,6 @@ class WholeController extends Curd
     public function doRefund(Request $request)
     {
         $orderId = $request->post('order_id', '');
-        // $returnId = $request->post('return_id', '');
         $amount = $request->post('refund_amount', 0);
         $password = $request->post('refund_password', '');
         if (!$orderId || !$amount || !$password) {
@@ -3913,6 +3972,82 @@ class WholeController extends Curd
         return $data;
     }
 
+    /**
+     * @Desc 查询订单状态
+     * @Author Gorden
+     * @Date 2024/8/19 11:55
+     *
+     * @param Request $request
+     * @return Response|void
+     */
+    public function getOrderPayStatus(Request $request)
+    {
+        $orderId = $request->get('order_id', '');
+        if (!$orderId) {
+            return json_fail('订单不存在');
+        }
+
+        $order = Order::where('order_id', $orderId)->first();
+        if (!$order) {
+            return json_fail('订单不存在');
+        }
+
+        if ($order->order_status_payment == 'SUCCESS') {
+            return json_success('success');
+        }
+
+        $payDetailType = PayDetail::where('join_pay_order_id', $order->order_groupby)->pluck('pay_prepayid')->toArray();
+        try {
+            Db::beginTransaction();
+            if (in_array('WXPAY', $payDetailType)) {
+                $result = Pay::wechat(config('payment.wxpay'))->find($order->order_groupby, 'pos');
+                $result = json_decode(json_encode($result), true);
+                if (!empty($result['return_code']) && $result['return_code'] == 'SUCCESS' && !empty($result['result_code']) && $result['result_code'] == 'SUCCESS' && !empty($result['trade_state']) && $result['trade_state'] == 'SUCCESS') {
+                    if (in_array($order->order_category, ['SERVICE', 'CHNMED', 'CHNNCD', 'DISHES', 'MEALS', 'VIP'])) {
+                        $order->order_is_complete = 'Y';
+                        $order->order_status_system = 'DONE';
+                        $order->order_status_payment = 'SUCCESS';
+                    } else {
+                        $order->order_status_system = 'SENDING';
+                    }
+                    $order->save();
+                    // Sheet
+                    OrderSheet::where('join_sheet_order_id', $orderId)->where('order_sheet_status', 'PAYING')->update(['order_sheet_status' => 'DONE']);
+                    // 支付记录
+                    PayDetail::where('join_pay_order_id', $order->order_groupby)->where('pay_prepayid', 'WXPAY')->update(['pay_status' => 'SUCCESS']);
+
+                    Db::commit();
+                    return json_success('success');
+                }
+            } else if (in_array('ALIPAY', $payDetailType)) {
+                $result = Pay::alipay(config('payment.alipay'))->find($order->order_groupby);
+                $result = json_decode(json_encode($result), true);
+                if (!empty($result['code']) && $result['code'] == '10000' && !empty($result['trade_status']) && $result['trade_status'] == 'TRADE_SUCCESS') {
+                    if (in_array($order->order_category, ['SERVICE', 'CHNMED', 'CHNNCD', 'DISHES', 'MEALS', 'VIP'])) {
+                        $order->order_is_complete = 'Y';
+                        $order->order_status_system = 'DONE';
+                        $order->order_status_payment = 'SUCCESS';
+                    } else {
+                        $order->order_status_system = 'SENDING';
+                    }
+                    $order->save();
+                    // Sheet
+                    OrderSheet::where('join_sheet_order_id', $orderId)->where('order_sheet_status', 'PAYING')->update(['order_sheet_status' => 'DONE']);
+                    // 支付记录
+                    PayDetail::where('join_pay_order_id', $order->order_groupby)->where('pay_prepayid', 'ALIPAY')->update(['pay_status' => 'SUCCESS']);
+
+                    Db::commit();
+                    return json_success('success');
+                }
+            }
+            Db::rollBack();
+            return json_fail('没有查询到记录');
+        } catch (\Exception $e) {
+            Db::rollBack();
+            return json_fail('查询失败');
+        }
+    }
+
     public static $goodsClassify = [
         // goodsClassify: {GOODS:"健康产品订单",SERVICE:"服务订单",DEVICE:"设备订单",SPECIAL:"专题业务订单",PACKAGE:"套餐订单",RECHARGE:"充值订单",OTHER:"其他订单"},
 

+ 17 - 13
app/admin/service/order/OrderService.php

@@ -229,7 +229,8 @@ class OrderService
                 $result = self::findWxpay($params['orderGroupId'], 0);
             } catch (\Exception $e) {
                 $log->error("WXPAY", ['msg' => $e->getMessage()]);
-                throw new BusinessException("支付失败");
+                $result = self::findWxpay($params['orderGroupId'], 0);
+//                throw new BusinessException("支付失败");
             }
             try{
                 $log->info("WXPAY_RETURN", json_decode(json_encode($result), true));
@@ -259,7 +260,7 @@ class OrderService
                 $log->info("ALIPAY_RETURN", json_decode(json_encode($result), true));
             }catch (\Exception $e){}
         } else {
-            throw new BusinessException("二维码无效");
+            throw new BusinessException("付款码无效");
         }
 
         return $result;
@@ -277,10 +278,6 @@ class OrderService
      */
     public static function findWxpay($orderId, $nbr = 0)
     {
-        if ($nbr >= 6) {
-            SupportLog::channel('pay')->error("FIND_WXPAY", ['msg' => '订单查询失败','order_id'=>$orderId]);
-            throw new BusinessException("订单查询失败");
-        }
         try {
             $result = Pay::wechat(config('payment.wxpay'))->find($orderId, 'pos');
             $result = json_decode(json_encode($result), true);
@@ -289,11 +286,17 @@ class OrderService
         }
 
         if (!empty($result['return_code']) && $result['return_code'] == 'SUCCESS' && !empty($result['result_code']) && $result['result_code'] == 'SUCCESS' && !empty($result['trade_state']) && $result['trade_state'] == 'SUCCESS') {
+            SupportLog::channel('pay')->info("FIND_WXPAY_SUCCESS", ['nbr' => $nbr,'order_id'=>$orderId]);
             return $result;
         } else {
+            if ($nbr > 2) {
+                SupportLog::channel('pay')->error("FIND_WXPAY", ['msg' => '订单查询失败','order_id'=>$orderId]);
+                return ['msg'=>'订单查询失败'];
+            }
+            dump('nbr-'.$nbr);
             sleep(5);
             SupportLog::channel('pay')->error("FIND_WXPAY", ['nbr' => $nbr,'order_id'=>$orderId]);
-            self::findWxpay($orderId, $nbr + 1);
+            return self::findWxpay($orderId, $nbr + 1);
         }
     }
 
@@ -309,10 +312,6 @@ class OrderService
      */
     public static function findAlipay($orderId, $nbr = 0)
     {
-        if ($nbr >= 6) {
-            SupportLog::channel('pay')->error("FIND_ALIPAY", ['msg' => '订单查询失败','order_id'=>$orderId]);
-            throw new BusinessException("订单查询失败");
-        }
         try {
             $result = Pay::alipay(config('payment.alipay'))->find($orderId);
             $result = json_decode(json_encode($result), true);
@@ -321,11 +320,16 @@ class OrderService
         }
 
         if (!empty($result['code']) && $result['code'] == '10000' && !empty($result['trade_status']) && $result['trade_status'] == 'TRADE_SUCCESS') {
+            SupportLog::channel('pay')->info("FIND_ALIPAY_SUCCESS", ['nbr' => $nbr,'order_id'=>$orderId]);
             return $result;
         } else {
+            if ($nbr > 2) {
+                SupportLog::channel('pay')->error("FIND_ALIPAY", ['msg' => '订单查询失败','order_id'=>$orderId]);
+                return ['msg'=>'订单查询失败'];
+            }
             sleep(5);
             SupportLog::channel('pay')->error("FIND_ALIPAY", ['nbr' => $nbr,'order_id'=>$orderId]);
-            self::findAlipay($orderId, $nbr + 1);
+            return self::findAlipay($orderId, $nbr + 1);
         }
     }
 
@@ -362,7 +366,7 @@ class OrderService
         $insertPayDetailData = [
             'join_pay_member_id' => $params['join_order_member_id'],
             'join_pay_order_id' => $params['orderGroupId'],
-            'pay_status' => 'SUCCESS',
+            'pay_status' => $params['order_status_payment'] == 'SUCCESS' ? 'SUCCESS' : 'WAITING',
             'pay_category' => !empty($params['submit_goods_classify']) ? $params['submit_goods_classify'] : $params['goods_classify'],
             'pay_amount' => $params['order_amount_pay'],
             'pay_paytimes' => date('Y-m-d H:i:s'),

+ 4 - 4
app/admin/validate/coupon/CouponValidate.php

@@ -15,8 +15,8 @@ class CouponValidate extends Validate
 //        'coupon_status|优惠券状态' => 'require|in:ACTIVED,DISABLED',
         'coupon_category|分类' => 'max:32',
         'coupon_name|名称' => 'require|max:32',
-        'coupon_validdate_begin|启用日期' => 'require',
-        'coupon_validdate_end|过期时间' => 'require',
+//        'coupon_validdate_begin|启用日期' => 'require',
+//        'coupon_validdate_end|过期时间' => 'require',
     ];
 
     /**
@@ -24,7 +24,7 @@ class CouponValidate extends Validate
      * @var array[]
      */
     protected $scene = [
-        'add' => ['coupon_category', 'coupon_name', 'coupon_validdate_begin', 'coupon_validdate_end'],
-        'update' => ['coupon_id', 'coupon_category', 'coupon_name', 'coupon_validdate_begin', 'coupon_validdate_end'],
+        'add' => ['coupon_category', 'coupon_name'],
+        'update' => ['coupon_id', 'coupon_category', 'coupon_name'],
     ];
 }

+ 23 - 7
app/functions.php

@@ -3,8 +3,9 @@
  * Here is your custom functions.
  */
 
- if (!function_exists('http_post')) {
-    function http_post($url,$params){
+if (!function_exists('http_post')) {
+    function http_post($url, $params)
+    {
         $ch = curl_init();
         $this_header = array("content-type: application/x-www-form-urlencoded;charset=UTF-8");
         curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);
@@ -25,7 +26,8 @@
 }
 
 if (!function_exists('http_post_json')) {
-    function http_post_json($url,$params){
+    function http_post_json($url, $params)
+    {
         $ch = curl_init();
         $this_header = array('Content-Type: application/json;charset=UTF-8');
         curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);
@@ -45,11 +47,12 @@ if (!function_exists('http_post_json')) {
     }
 }
 
-if (!function_exists('month_12')){
-    function month_12(){
+if (!function_exists('month_12')) {
+    function month_12()
+    {
         $months = [];
-        for ($i=0;$i<12;$i++){
-            $months[$i] = date('Y/m',strtotime(date('Y-m-01')."-".$i."month"));
+        for ($i = 0; $i < 12; $i++) {
+            $months[$i] = date('Y/m', strtotime(date('Y-m-01') . "-" . $i . "month"));
         }
 
         return $months;
@@ -84,4 +87,17 @@ if (!function_exists('_syslog')) {
         $model->log_operation_data = $operationData ? json_encode($operationData) : null;
         $model->save();
     }
+}
+
+if (!function_exists('json_throw')) {
+    function json_throw($code, $message, $data = '', $options = JSON_UNESCAPED_UNICODE)
+    {
+        $return = [
+            'code' => $code,
+            'message' => $message,
+            'data' => $data,
+        ];
+
+        return new \support\Response(200, ['Content-Type' => 'application/json'], json_encode($return, $options));
+    }
 }

+ 1 - 0
route/admin.php

@@ -898,6 +898,7 @@ Route::group('/admin', function () {
             Route::post('/cutMeals', [\app\admin\controller\order\WholeController::class, 'cutMeals']);
             Route::post('/customPrinter', [\app\admin\controller\order\WholeController::class, 'customPrinter']);
             Route::post('/cancelOrder', [\app\admin\controller\order\WholeController::class, 'cancelOrder']);
+            Route::get('/getOrderPayStatus', [\app\admin\controller\order\WholeController::class, 'getOrderPayStatus']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);