queryOrder( )订单状态查询 * * * * * ~~~ /** * @param string $order_number 订单号 * @return array errCode ok: 成功 -1:失败 */ function queryOrder($order_number = '') { $paymentModel = new \app\common\model\Payment(); if (!$payment = $paymentModel->getPaymentByFind(['order_number' => $order_number])) { return ['errCode' => -1, 'errMsg' => '订单不存在']; } if (setWxpayConfig($payment['mpid'])) { $input = new \WxPayOrderQuery(); $input->SetOut_trade_no($order_number); $orderRes = \WxPayApi::orderQuery($input); if (!empty($orderRes)) { if (isset($orderRes['trade_state']) && $orderRes['trade_state'] == 'SUCCESS') {//已经支付 if ($payment['status'] == '0') {//订单状态未处理为成功 $model = new \app\common\model\MemberWealthRecord(); if ($model->addMoney($payment['member_id'], $payment['mpid'], $payment['money'], $payment['title'])) { if (!$paymentModel->save(['status' => 1], ['order_number' => $order_number])) { return ['errCode' => -1, 'errMsg' => '改变订单状态失败']; } return ['errCode' => 'ok', 'errMsg' => '交易完成']; } else { return ['errCode' => -1, 'errMsg' => '改变账户金额失败']; } } else { return ['errCode' => 'ok', 'errMsg' => '交易完成']; } } else { return ['errCode' => -1, 'errMsg' => '未完成交易']; } } else { return ['errCode' => -1, 'errMsg' => '订单不存在']; } } return ['errCode' => -1, 'errMsg' => '没有公众号配置信息']; } ~~~