diff --git a/app/api/logic/LogisticsLogic.php b/app/api/logic/LogisticsLogic.php index 75355e2b..89807b5e 100644 --- a/app/api/logic/LogisticsLogic.php +++ b/app/api/logic/LogisticsLogic.php @@ -50,15 +50,17 @@ class LogisticsLogic extends BaseLogic 'page' => !empty($params['page_num'])? $params['page_num'] : 1, ])->each(function($lst_item){ $lst_item['status_name'] = $lst_item->status_name; + $product_count = 0; //获取产品信息 - $lst_item['products'] = Product::field('product_num,cart_info')->where('order_id', $lst_item['order_id'])->select()->each(function($pro_item){ + $lst_item['products'] = Product::field('product_num,cart_info')->where('order_id', $lst_item['order_id'])->select()->each(function($pro_item) use(&$product_count){ $pro_item['cart_info'] = json_decode($pro_item['cart_info'], true); $pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name']; $pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name']; + $product_count += $pro_item['product_num']; unset($pro_item['cart_info']); return $pro_item; }); - $lst_item['product_count'] = count($lst_item['products']); + $lst_item['product_count'] = $product_count; return $lst_item; })->toArray(); //返回数据 @@ -75,10 +77,12 @@ class LogisticsLogic extends BaseLogic $logistics = Logistics::field('id,order_id,order_sn,shop_name,shop_phone,shop_address,user_name,user_address,status,create_time') ->where('id', $id)->find(); //获取商品信息 - $product = Product::field('product_num,cart_info')->where('order_id', $logistics['order_id'])->select()->each(function($pro_item){ + $product_count = 0; + $product = Product::field('product_num,cart_info')->where('order_id', $logistics['order_id'])->select()->each(function($pro_item) use(&$product_count){ $pro_item['cart_info'] = json_decode($pro_item['cart_info'], true); $pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name']; $pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name']; + $product_count += $pro_item['product_num']; unset($pro_item['cart_info']); return $pro_item; })->toArray(); @@ -104,7 +108,7 @@ class LogisticsLogic extends BaseLogic return[ 'logistics' => $logistics, 'product' => $product, - 'product_count' => count($product), + 'product_count' => $product_count, 'record' => $records, ]; }