6
0
Fork 0
base
panliang 2023-08-14 15:38:39 +08:00
parent 191770ebf1
commit 0f45a07105
1 changed files with 6 additions and 5 deletions

View File

@ -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;
}