db->beginTransaction(); try { if (empty($trade_info)) throw new \Exception('传递进来的流水数据为空'); $agent_order = CloudStockAgentOrder::find() ->where(['trade_id' => $trade_info['trade_id'], 'order_no' => $trade_info['order_no']]) ->andWhere(['=','send_status',CloudStockEnum::PICK_ORDER_STATUS3]) ->one(); if (empty($agent_order)) throw new \Exception('云库存自提订单不存在或者已经支付。trade_info => ' . json_encode(ArrayHelper::toArray($trade_info), JSON_UNESCAPED_UNICODE)); $agent_order->send_status = CloudStockEnum::PICK_ORDER_STATUS0; $res = $agent_order->save(); if (false === $res) throw new \Exception($agent_order->getErrorMessage()); $t->commit(); // 发起自提事件 $event = new FillOrderPickEvent($agent_order->mall_id); $data = ['id' => $agent_order->id]; \Yii::$app->services->events->dispatch($event, $data, $event->listeners); $goodsIds = CloudStockAgentOrderDetails::find() ->where(['mall_id' => $agent_order->mall_id, 'status' => StatusEnum::ENABLED, 'order_id' => $agent_order->id]) ->select('goods_id') ->column(); $sync_params = [ 'mall_id' => $agent_order->mall_id, 'user_id' => $agent_order['user_id'], 'goods_id' => $goodsIds ]; \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, $sync_params, CloudStockAgentOrder::class, 'handleSync'); return true; } catch (\Exception $e) { $t->rollBack(); $msg = '云库存自提订单支付回调处理失败:' . $e->getMessage() . ', file: ' . $e->getFile() . ', line: ' . $e->getLine(); \Yii::error($msg);\Yii::getLogger()->flush(true); return false; } } }