From 0f45a07105d3fd31975c671619e62f72f8716e3e Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Mon, 14 Aug 2023 15:38:39 +0800 Subject: [PATCH] stock --- app/Admin/Repositories/StoreTockRepository.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Admin/Repositories/StoreTockRepository.php b/app/Admin/Repositories/StoreTockRepository.php index 6b014d68..aedeceaf 100644 --- a/app/Admin/Repositories/StoreTockRepository.php +++ b/app/Admin/Repositories/StoreTockRepository.php @@ -30,6 +30,7 @@ class StoreTockRepository extends Repository $self = $stock->where('product_sku_id', $item->product_sku_id)->where('tag_id', StockLog::TAG_SELF)->sum('amount'); $sell_price = data_get($item->productSku, 'sell_price') / 100; $cost_price = data_get($item->productSku, 'cost_price') / 100; + $current_stock = data_get($item, 'amount'); $subData = [ 'id' => $item->product_sku_id, 'store_name' => data_get($item->store, 'title'), @@ -38,7 +39,7 @@ class StoreTockRepository extends Repository 'category_name' => data_get($item->productSku, 'category.name'), 'cost_price' => $cost_price, 'sell_price' => $sell_price, - 'stock' => data_get($item, 'amount'), + 'stock' => $current_stock, // 入库数 'tag_in' => $in, // 销售数 = 提货数 + 发货数 @@ -53,8 +54,8 @@ class StoreTockRepository extends Repository 'init_stock' => data_get($item->stockLog, 'balance', 0), // 调货数 = 出库数 'tag_out' => $stock->where('product_sku_id', $item->product_sku_id)->where('tag_id', StockLog::TAG_OUT)->sum('amount'), - // 毛利 = (入库数-报损数-自用数) x (售价-成本) - 'total_profit' => floor(($in - $loss - $self) * ($sell_price - $cost_price)), + // 毛利 = 现有库存 x (售价-成本) + 'total_profit' => round($current_stock * ($sell_price - $cost_price), PHP_ROUND_HALF_DOWN), ]; array_push($data, $subData); } @@ -134,7 +135,7 @@ class StoreTockRepository extends Repository 'total_cost_price' => 0, // 现有总价值 = 库存 * 售价 'total_sell_price' => 0, - // 毛利 = (入库数-报损数-自用数) x (售价-成本) + // 毛利 = 库存 x (售价-成本) 'total_profit' => 0, ]; foreach ($list as $item) { @@ -154,7 +155,7 @@ class StoreTockRepository extends Repository $data['total_out'] += $stock->where('product_sku_id', $item->product_sku_id)->where('tag_id', StockLog::TAG_OUT)->sum('amount') * $cost_price; $data['total_cost_price'] += $current_stock * $cost_price; $data['total_sell_price'] += $current_stock * $sell_price; - $data['total_profit'] += ($in_amount - $loss_amount - $self_amount) * ($sell_price - $cost_price); + $data['total_profit'] += $current_stock * ($sell_price - $cost_price); } return $data; }