public function getOrderItemStatus($magentoorderitemid) {
$query = (new \yii\db\Query())
->select(["COALESCE(ShipTracking.ShipCarrier, '') AS ShipCarrier", "COALESCE(ShipTracking.ShipVendor, '') AS ShipMethod", "COALESCE(ShipTracking.ShipCarrier, '') AS ShipCarrier","COALESCE(ShipTracking.TrackingNumber, '') AS TrackingNumber"])
->from('OrderDetails')
->leftJoin('PickTicketOrders','PickTicketOrders.OrderId = OrderDetails.OrderId')
->leftJoin('ShipTracking', 'ShipTracking.PickTicketId = PickTicketOrders.Id')
->leftJoin('Products', 'Products.ISBN = OrderDetails.ISBN')
->where('OrderDetails.MagentoOrderItemId=:magentoorderitemid', [':magentoorderitemid' => $magentoorderitemid]);
$result = Yii::$app->db->createCommand($query)->execute();
return $result;
}
即使我删除joins
和where
,我也会将选择更改为*
。它不起作用
答案 0 :(得分:1)
$query = (new \yii\db\Query())
->select(["COALESCE(ShipTracking.ShipCarrier, '') AS ShipCarrier", "COALESCE(ShipTracking.ShipVendor, '') AS ShipMethod", "COALESCE(ShipTracking.ShipCarrier, '') AS ShipCarrier","COALESCE(ShipTracking.TrackingNumber, '') AS TrackingNumber"])
->from('OrderDetails')
->leftJoin('PickTicketOrders','PickTicketOrders.OrderId = OrderDetails.OrderId')
->leftJoin('ShipTracking', 'ShipTracking.PickTicketId = PickTicketOrders.Id')
->leftJoin('Products', 'Products.ISBN = OrderDetails.ISBN')
->where('OrderDetails.MagentoOrderItemId=:magentoorderitemid', [':magentoorderitemid' => $magentoorderitemid]);
$command = $query->createCommand();
$result = $command->queryAll();
以这种方式使用此查询
答案 1 :(得分:0)
我最终使用以下内容并且有效
$query = (new \yii\db\Query())
->select(["COALESCE(ShipTracking.ShipCarrier, '') AS ShipCarrier", "COALESCE(ShipTracking.ShipVendor, '') AS ShipMethod", "COALESCE(ShipTracking.ShipCarrier, '') AS ShipCarrier","COALESCE(ShipTracking.TrackingNumber, '') AS TrackingNumber"])
->from('OrderDetails')
->leftJoin('PickTicketOrders','PickTicketOrders.OrderId = OrderDetails.OrderId')
->leftJoin('ShipTracking', 'ShipTracking.PickTicketId = PickTicketOrders.Id')
->leftJoin('Products', 'Products.ISBN = OrderDetails.ISBN')
->where('OrderDetails.MagentoOrderItemId=:magentoorderitemid', [':magentoorderitemid' => $magentoorderitemid]);
$result = $query->all();