refundInfo = $this->refundOrderModel->getInfoByOrderSnoAndType($this->orderNo,self::PayType); $this->orderInfo = $this->orderModel->getInfoById($this->refundInfo->order_id); $this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType); if (empty($this->orderInfo) || empty($this->payInfo) || empty($this->refundInfo)) { $this->log->debug(__CLASS__.':订单不存在,订单号:'.$this->orderNo); throw new ErrException('订单不存在'); } if ($this->refundInfo->refund_status != RefundCode::WAIT_BY_PAY_TOOL) { $this->log->debug(__CLASS__.':订单已退款成功,订单信息:'.json_encode($this->refundInfo->toArray())); throw new ErrException('订单已退款成功'); } if ($this->refundInfo->refund_type != PayCode::WECHAT_PAY) { $this->log->debug(__CLASS__.':订单退款渠道错误,订单信息:'.json_encode($this->refundInfo->toArray())); throw new ErrException('订单退款渠道错误'); } } /** * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ protected function manageRefundOrder(): void { try { $this->refundInfo->refund_status = RefundCode::REFUND_SUCCESS; $this->refundInfo->refund_time = date('Y-m-d H:i:s'); $this->refundInfo->wx_transaction_id = $this->callbackData['transaction_id']; $this->refundInfo->notify_json = json_encode($this->callbackData); $this->refundInfo->remark = '退款成功'; if (!$this->refundInfo->save()) throw new Exception('更新退款订单失败'); }catch (Exception $e) { $this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id); throw new ErrException($e->getMessage()); } } /** * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ protected function manageOrderByRefund(): void { try { $isRefundMoney = $this->refundOrderModel->getSuccessMoneyByOrderId($this->refundInfo->order_id,$this->refundInfo->order_type); if ($isRefundMoney <= 0) throw new Exception('订单退款金额错误'); if ($isRefundMoney == $this->payInfo->pay_money) { $this->orderInfo->status = OrderCode::FINISH_REFUND; $this->orderInfo->is_refund_all = 1;//todo 感觉可以删除这个值 } else { $this->orderInfo->status = OrderCode::UNCOMPLETED_REFUND; } if (!$this->orderInfo->save()) throw new Exception('更新退款订单失败'); }catch (Exception $e) { $this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id); throw new ErrException($e->getMessage()); } } }