refundInfo = $this->refundOrderModel->getInfoByOrderSnoAndType($this->orderSno,$this->payType); $this->orderInfo = $this->orderModel->getInfoById($this->refundInfo->order_id); $this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,$this->orderType,$this->payType); if (empty($this->orderInfo) || empty($this->payInfo) || empty($this->refundInfo)) throw new ErrException('订单不存在'); if ($this->refundInfo->refund_status != RefundCode::WAIT_BY_PAY_TOOL) throw new ErrException('订单已退款成功'); if ($this->refundInfo->refund_type != PayCode::WECHAT_PAY) throw new ErrException('订单退款渠道错误'); } /** * @return void */ 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('Function:RefundFinish:'.$e->getMessage().':orderId:'.$this->orderInfo->id); throw new ErrException('Function:RefundFinish:'.$e->getMessage().':orderId:'.$this->orderInfo->id); } } /** * @var OrderGood */ #[Inject] protected OrderGood $orderGoodModel; /** * @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; } else { $this->orderInfo->status = OrderCode::UNCOMPLETED_REFUND; } if (!$this->orderInfo->save()) throw new Exception('更新退款订单失败'); match ($this->refundInfo->type) { RefundCode::FULL_GOOD_REFUND => $this->orderGoodModel->where('order_id',$this->refundInfo->order_id)->update(['refund_status' => OrderCode::FINISH_REFUND]), RefundCode::PARTIAL_GOOD_REFUND => $this->orderGoodModel->whereIn('id',json_decode($this->refundInfo->good_ids,true))->update(['refund_status' => OrderCode::FINISH_REFUND]), }; }catch (Exception $e) { $this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id); throw new ErrException('Function:RefundFinish:'.$e->getMessage().':orderId:'.$this->orderInfo->id); } } }