tp5事务代码

Ezra
2022-04-12 / 0 评论 / 155 阅读 / 正在检测是否收录...
if ($message['result_code'] === 'SUCCESS') {
                        $orderNO = $message['out_trade_no'];
                        Db::startTrans();
                        try {
                            $order = OrderModel::where('order_no' , '=' , $orderNO)->find();
                            //订单状态是未支付的才处理
                            if ($order['status'] == 1) {
                                $stockStatus = ( new OrderService() )->chenkOrderStock($order->id);
                                if ($stockStatus['pass']) {
                                    $this->updateOrderStatus($order->id , true);
                                    $this->reduceStock($stockStatus);
                                } else {
                                    $this->updateOrderStatus($order->id , false);
                                }
                            }
                            Db::commit();
                            return true;
                        } catch ( Exception $e ) {
                            Db::rollback();
                            Log::write($e);
                            return $fail('服务器处理失败,请稍后再通知我');//服务器处理出现异常需要返回给微信false,让他再次发起通知
                        }
                    //支付失败
                    } else if ($result['result_code'] === 'FAIL') {
                        //支付失败也需要返回true,表示服务器已处理,不然微信会反复通知,没有意义
                        return true;
                    }
0

评论 (0)

取消