where($where); $totalCount = $query->count(); $list = $query ->order('id', 'desc') ->page($page, $pageSize) ->select() ->toArray(); // 关联订单商品信息 if (!empty($list)) { foreach ($list as &$order) { $cartInfo = Db::name('store_order_cart_info') ->where('oid', $order['id']) ->select() ->toArray(); foreach ($cartInfo as &$item) { if (!empty($item['cart_info'])) { $innerCartInfo = json_decode($item['cart_info'], true); unset($item['cart_info']); $item = array_merge($item, $innerCartInfo); } } $order['cart_info'] = $cartInfo; } } return [ 'list' => $list, 'totalCount' => $totalCount, 'pageSize' => $pageSize, 'page' => $page ]; } /** * 获取订单详情 * @param int $id * @return array|null */ public function getOrderDetail($id) { $order = $this->where('id', $id)->find(); if (!$order) { return null; } $data = $order->toArray(); // 获取订单商品 $cartInfo = (new StoreOrderCartInfo())->where('oid', $id)->select()->toArray(); $data['cart_info'] = $cartInfo; return $data; } }