feat: 修改库存计算逻辑并添加总采购价字段

This commit is contained in:
mkm 2024-08-24 11:30:25 +08:00
parent 694c83379a
commit 12b4544233
3 changed files with 93 additions and 84 deletions

View File

@ -64,8 +64,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
$list = StoreProduct::where($this->searchWhere) $list = StoreProduct::where($this->searchWhere)
->alias('p') // 为 StoreProduct 表设置别名 ->alias('p') // 为 StoreProduct 表设置别名
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->field('p.id, p.store_name, p.image,p.stock as total_stock,
->field('p.id, p.store_name, p.image,
(SELECT SUM(c.cart_num) FROM `la_store_order_cart_info` c WHERE c.product_id=p.id AND c.is_pay=1 AND c.delete_time IS NULL) AS sales, (SELECT SUM(c.cart_num) FROM `la_store_order_cart_info` c WHERE c.product_id=p.id AND c.is_pay=1 AND c.delete_time IS NULL) AS sales,
(SELECT SUM(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id AND b.delete_time IS NULL) AS store_stock, (SELECT SUM(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id AND b.delete_time IS NULL) AS store_stock,
(SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id AND w.delete_time IS NULL) AS warehouse_stock, (SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id AND w.delete_time IS NULL) AS warehouse_stock,
@ -75,7 +74,6 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
->select() ->select()
->each(function ($item) { ->each(function ($item) {
// 计算总库存 // 计算总库存
$item->total_stock = $item->store_stock + $item->warehouse_stock;
$item->total_completed_amount=$item->total_completed_amount??0; $item->total_completed_amount=$item->total_completed_amount??0;
$item->warehouse_stock=$item->warehouse_stock??0; $item->warehouse_stock=$item->warehouse_stock??0;
$item->total_outstanding_amount=$item->total_outstanding_amount??0; $item->total_outstanding_amount=$item->total_outstanding_amount??0;
@ -139,6 +137,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
'purchase' => '采购价', 'purchase' => '采购价',
'cost' => '商户', 'cost' => '商户',
'price' => '零售', 'price' => '零售',
'total_price' => '总采购价',
]; ];
return $data; return $data;
} }

View File

@ -34,8 +34,6 @@ class WarehouseLogic extends BaseLogic
'value' => [], 'value' => [],
'type' => 1, 'type' => 1,
]; ];
$topData[] = [ $topData[] = [
'title' => '已结算金额', 'title' => '已结算金额',
'desc' => '平台支付给供应商的金额', 'desc' => '平台支付给供应商的金额',
@ -50,46 +48,48 @@ class WarehouseLogic extends BaseLogic
'value' => [], 'value' => [],
'type' => 1, 'type' => 1,
]; ];
$store_stock_1 = StoreBranchProduct::where('stock', '>', 0)->sum('stock'); $toreProduct = StoreProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find();
$store_stock_2 = WarehouseProductStorege::where('nums', '>', 0)->sum('nums');
$topData[] = [ $topData[] = [
'title' => '总商品库存', 'title' => '总商品库存',
'desc' => '平台统计商品总库存、含门店仓库', 'desc' => '平台统计商品总库存、含门店仓库',
'total_money' => bcadd($store_stock_1, $store_stock_2, 2), 'total_money' =>$toreProduct['stock'],
'cash_title' => 1, 'cash_title' => $toreProduct['total_price'],
'value' => [], 'value' => [],
'type' => 1, 'type' => 1,
]; ];
$warehouseProductStorege = WarehouseProductStorege::where('stock', '>', 0)->field('sum(nums) as nums,sum(total_price) as total_price')->find();
$topData[] = [ $topData[] = [
'title' => '总仓库库存', 'title' => '总仓库库存',
'desc' => '平台统计仓库库存', 'desc' => '平台统计仓库库存',
'total_money' => WarehouseProductStorege::sum('nums'), 'total_money' => $warehouseProductStorege['nums'],
'cash_title' => 1, 'cash_title' => $warehouseProductStorege['total_price'],
'value' => [], 'value' => [],
'type' => 1, 'type' => 1,
]; ];
$warehouseProductStorege_1 = WarehouseProductStorege::where('stock', '>', 0)->where('warehouse_id',1)->field('sum(nums) as nums,sum(total_price) as total_price')->find();
$topData[] = [ $topData[] = [
'title' => '海吉星仓库库存', 'title' => '海吉星仓库库存',
'desc' => '平台统计海吉星仓库库存', 'desc' => '平台统计海吉星仓库库存',
'total_money' => WarehouseProductStorege::where('warehouse_id', 1)->sum('nums'), 'total_money' => $warehouseProductStorege_1['nums'],
'cash_title' => 1, 'cash_title' => $warehouseProductStorege_1['total_price'],
'value' => [], 'value' => [],
'type' => 1, 'type' => 1,
]; ];
$warehouseProductStorege_2 = WarehouseProductStorege::where('stock', '>', 0)->where('warehouse_id',2)->field('sum(nums) as nums,sum(total_price) as total_price')->find();
$topData[] = [ $topData[] = [
'title' => '泸县集采集配库存', 'title' => '泸县集采集配库存',
'desc' => '平台统计泸县集采集配库存', 'desc' => '平台统计泸县集采集配库存',
'total_money' => WarehouseProductStorege::where('warehouse_id', 2)->sum('nums'), 'total_money' => $warehouseProductStorege_2['nums'],
'cash_title' => 1, 'cash_title' => $warehouseProductStorege_2['total_price'],
'value' => [], 'value' => [],
'type' => 1, 'type' => 1,
]; ];
$storeBranchProduct = StoreBranchProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find();
$topData[] = [ $topData[] = [
'title' => '总门店库存', 'title' => '总门店库存',
'desc' => '平台统计门店库存', 'desc' => '平台统计门店库存',
'total_money' => StoreBranchProduct::sum('stock'), 'total_money' =>$storeBranchProduct['stock'],
'cash_title' => 1, 'cash_title' => $storeBranchProduct['total_price'],
'value' => [], 'value' => [],
'type' => 1, 'type' => 1,
]; ];
@ -100,7 +100,6 @@ class WarehouseLogic extends BaseLogic
$data['series'][$k]['desc'] = $v['desc']; $data['series'][$k]['desc'] = $v['desc'];
$data['series'][$k]['total_value'] = $v['total_money']; $data['series'][$k]['total_value'] = $v['total_money'];
$data['series'][$k]['total_money'] = $v['cash_title'] ?? ''; $data['series'][$k]['total_money'] = $v['cash_title'] ?? '';
$data['series'][$k]['type'] = $v['type']; $data['series'][$k]['type'] = $v['type'];
} }
return $data; return $data;

View File

@ -62,16 +62,27 @@ class WarehouseProductLogic extends BaseLogic
} else { } else {
$after_nums = $storege['nums'] + $params['nums']; $after_nums = $storege['nums'] + $params['nums'];
if ($type == 1) { if ($type == 1) {
WarehouseProductStorege::where('id', $storege['id'])->inc('nums', $params['nums'])->update(); $storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
if (!$storeProduct) {
throw new BusinessException('商品不存在');
}
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
WarehouseProductStorege::where('id', $storege['id'])->update(['nums' => $after_nums, 'total_price' => $total_price]);
} }
} }
$before_nums = $storege['nums']; $before_nums = $storege['nums'];
} else { } else {
$after_nums = $params['nums']; $after_nums = $params['nums'];
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
if (!$storeProduct) {
throw new BusinessException('商品不存在');
}
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
WarehouseProductStorege::create([ WarehouseProductStorege::create([
'warehouse_id' => $params['warehouse_id'], 'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'], 'product_id' => $params['product_id'],
'nums' => $params['nums'], 'nums' => $params['nums'],
'total_price'=>$total_price
]); ]);
} }
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count(); $batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();