api_refund_list = Json::encode($trade_list); $resp = $req->send($refundCreate); if ($resp->getError()) return $resp->getError(); // 执行其他操作 try { $res = $resp->toArray(); if (!isset($res['code']) || $res['code'] != StatusEnum::DISABLED) return $res['message'] ?? var_export($res, true); } catch (\Exception $e) { return $e->getMessage(); } return true; } /** * @param array $config * @param array $refund * @param int $refund_status * @return void * @throws \Exception */ public function enterprise(array $config, array $refund, int $refund_status) { // 判断当前订单是否已经发货 if ($refund['orderDetail']['shipping_status'] == StatusEnum::ENABLED) { $trade_list[] = (new CreateRefundService())->assembleData($refund, $config); $flag = $this->retry(function () use ($config, $trade_list) { return $this->send($config, $trade_list); }); } else { // 未发货 $flag = true; (new RefundUpdateListener())->async_handle(['id' => $refund['order_id'], 'refund_status' => $refund_status]); } if (is_string($flag)) throw new \Exception($flag); return $flag; } /** * 未发货退款 * @param array $config * @param array $order * @param array $orderDetail * @return mixed|true|null */ protected function updateTradePush(array $config, array $order, array $orderDetail) { // 组装数据 $orderModel = new Order(); $orderModel->tid = $order['order_no']; $orderItemModel = new OrderItem(); $orderItemModel->refund_status = WangDianTongEnum::ORDER_REFUND_MAP[$orderDetail['is_feedback']] ?? 0;; $orderItemModel->oid = "{$order['order_no']}_{$orderDetail['id']}"; $orderModel->order_list = Json::encode([ $orderItemModel->toArray() ]); // 创建请求 $trade_list[] = $orderModel->toArray(); return $this->retry(function () use ($config, $trade_list) { // 这里执行 return $this->tradeSend($config, $trade_list); }); } /** * @param array $config * @param array $trade_list * @return mixed|string|true */ protected function tradeSend(array $config, array $trade_list) { $req = new CreateOrder($config); $orderCreate = new OrderCreate(); $orderCreate->switch = StatusEnum::DISABLED; $orderCreate->shop_no = $config['shop_no']; $orderCreate->trade_list = Json::encode($trade_list); $resp = $req->send($orderCreate); if ($resp->getError()) return $resp->getError(); // 执行其他操作 try { $res = $resp->toArray(); if (!isset($res['code']) || $res['code'] != StatusEnum::DISABLED) return $res['message'] ?? var_export($res, true); } catch (\Exception $e) { return $e->getMessage(); } return true; } }