where('pay_code', $notifyInfo['out_trade_no']) ->findOrEmpty(); //要加lock吗? if ($pay_info->isEmpty()) throw new Exception('该支付信息不存在'); //待处理 if ($pay_info->status == MasterOrderModel::$order_status_wait_pay) { $updatetime = date('Y-m-d H:i:s'); PayInfoModel::where(['pay_code' => $notifyInfo['out_trade_no'], 'status' => MasterOrderModel::$order_status_wait_pay, 'id' => $pay_info->id]) ->save([ 'status' => MasterOrderModel::$order_status_not_deliver, 'updaterid' => '0', 'updater' => '微信支付', 'updatetime' => $updatetime, 'transaction_id' => $notifyInfo['transaction_id'], 'trade_type' => $notifyInfo['trade_type'], 'notify_result' => json_encode($notifyInfo, JSON_UNESCAPED_UNICODE), ]); if ($pay_info->type == GoodModel::$type_exchange) { //兑换商品订单 Db::name('order') ->where(['is_del' => CommonModel::$del_normal, 'pay_info_id' => $pay_info->id, 'status' => MasterOrderModel::$order_status_wait_pay]) ->update([ 'updaterid' => '0', 'updater' => '微信支付', 'updatetime' => $updatetime, 'status' => MasterOrderModel::$order_status_not_deliver ]); } else { //服务订单 Db::name('order_service') ->where(['is_del' => CommonModel::$del_normal, 'pay_info_id' => $pay_info->id, 'status' => MasterOrderModel::$order_status_wait_pay]) ->update([ 'updaterid' => '0', 'updater' => '微信支付', 'updatetime' => $updatetime, 'status' => MasterOrderModel::$order_status_not_deliver ]); } } Db::commit(); return xml(['return_code' => 'SUCCESS', 'return_msg' => 'DEAL WITH SUCCESS']); } catch (Exception $exception) { Db::rollback(); return xml(['return_code' => 'FAIL', 'return_msg' => $exception->getMessage()]); } // 返回XML状态,至于XML数据可以自己生成,成功状态是必须要返回的。 // // return_code> // return_msg> // } //查询支付结果 public static function checkPayResult(string $pay_code = ''): Json { $rs = PayInfoModel::field('id,status') ->where(['pay_code' => $pay_code, 'uid' => self::$aid]) ->findOrEmpty() ->toArray(); if (empty($rs)) return json_show(CommonModel::$error_param, '该支付信息不存在'); if ($rs['status'] == MasterOrderModel::$order_status_wait_pay) { //待支付时,手动去微信端查验是否支付完成(有可能异步通知到的晚,尚未更新状态) $temp = WechatLogic::checkPayResult($pay_code); $rs['status'] = $temp['RESULT_CODE'];//????@todo } return json_show(CommonModel::$success, '请求成功', ['result' => $rs['status']]); } }