feat: 修改库存计算逻辑并添加总采购价字段
This commit is contained in:
parent
694c83379a
commit
12b4544233
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
@ -33,83 +33,94 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
* @author admin
|
* @author admin
|
||||||
* @date 2024/07/31 16:55
|
* @date 2024/07/31 16:55
|
||||||
*/
|
*/
|
||||||
public static function add(array $params,$type=1)
|
public static function add(array $params, $type = 1)
|
||||||
{
|
{
|
||||||
// Db::startTrans();
|
// Db::startTrans();
|
||||||
try {
|
try {
|
||||||
$before_nums = 0;
|
$before_nums = 0;
|
||||||
$after_nums = 0;
|
$after_nums = 0;
|
||||||
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||||
if ($storege) {
|
if ($storege) {
|
||||||
if ($params['financial_pm'] == 0) {
|
if ($params['financial_pm'] == 0) {
|
||||||
$after_nums = $storege['nums'] - $params['nums'];
|
$after_nums = $storege['nums'] - $params['nums'];
|
||||||
// if ($after_nums < 0) {
|
// if ($after_nums < 0) {
|
||||||
// throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
|
// throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
|
||||||
// }
|
// }
|
||||||
WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update();
|
WarehouseProductStorege::where('id', $storege['id'])->dec('nums', $params['nums'])->update();
|
||||||
//门店加库存
|
//门店加库存
|
||||||
$storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id',$params['store_id'])->find();
|
$storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find();
|
||||||
if(!$storeBranchProduct){
|
if (!$storeBranchProduct) {
|
||||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
|
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
|
||||||
if (!$storeProduct) {
|
if (!$storeProduct) {
|
||||||
throw new BusinessException('商品不存在');
|
throw new BusinessException('商品不存在');
|
||||||
|
}
|
||||||
|
$storeBranchProduct = StoreProductLogic::ordinary(['id' => $params['product_id']], $params['store_id'], $params['admin_id'], $storeProduct);
|
||||||
|
}
|
||||||
|
if ($params['nums'] > 0 && $type == 1) {
|
||||||
|
StoreBranchProductLogic::stock(['id' => $storeBranchProduct['id'], 'product_id' => $params['product_id'], 'nums' => $params['nums']]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$after_nums = $storege['nums'] + $params['nums'];
|
||||||
|
if ($type == 1) {
|
||||||
|
$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]);
|
||||||
}
|
}
|
||||||
$storeBranchProduct=StoreProductLogic::ordinary(['id'=>$params['product_id']],$params['store_id'], $params['admin_id'], $storeProduct);
|
|
||||||
}
|
|
||||||
if ($params['nums'] > 0&&$type==1) {
|
|
||||||
StoreBranchProductLogic::stock(['id'=>$storeBranchProduct['id'],'product_id'=>$params['product_id'],'nums'=>$params['nums']]);
|
|
||||||
}
|
}
|
||||||
|
$before_nums = $storege['nums'];
|
||||||
} else {
|
} else {
|
||||||
$after_nums = $storege['nums'] + $params['nums'];
|
$after_nums = $params['nums'];
|
||||||
if($type==1){
|
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
|
||||||
WarehouseProductStorege::where('id', $storege['id'])->inc('nums', $params['nums'])->update();
|
if (!$storeProduct) {
|
||||||
|
throw new BusinessException('商品不存在');
|
||||||
}
|
}
|
||||||
|
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
|
||||||
|
WarehouseProductStorege::create([
|
||||||
|
'warehouse_id' => $params['warehouse_id'],
|
||||||
|
'product_id' => $params['product_id'],
|
||||||
|
'nums' => $params['nums'],
|
||||||
|
'total_price'=>$total_price
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
$before_nums = $storege['nums'];
|
$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();
|
||||||
} else {
|
$data = [
|
||||||
$after_nums=$params['nums'];
|
|
||||||
WarehouseProductStorege::create([
|
|
||||||
'warehouse_id' => $params['warehouse_id'],
|
'warehouse_id' => $params['warehouse_id'],
|
||||||
|
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||||
|
'oid' => $params['oid'] ?? 0,
|
||||||
|
'store_id' => $params['store_id'] ?? 0,
|
||||||
'product_id' => $params['product_id'],
|
'product_id' => $params['product_id'],
|
||||||
|
'financial_pm' => $params['financial_pm'],
|
||||||
|
'batch' => $batch_count + 1,
|
||||||
'nums' => $params['nums'],
|
'nums' => $params['nums'],
|
||||||
]);
|
'before_nums' => $before_nums,
|
||||||
}
|
'after_nums' => $after_nums,
|
||||||
$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();
|
// 'price' => $params['price'] ?? '',
|
||||||
$data = [
|
'purchase' => $params['purchase'] ?? '',
|
||||||
'warehouse_id' => $params['warehouse_id'],
|
// 'cost' => $params['cost'] ?? '',
|
||||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
'total_price' => $params['total_price'] ?? '',
|
||||||
'oid' => $params['oid'] ?? 0,
|
'admin_id' => $params['admin_id'],
|
||||||
'store_id' => $params['store_id'] ?? 0,
|
'code' => $params['code'] ?? '',
|
||||||
'product_id' => $params['product_id'],
|
'status' => 1,
|
||||||
'financial_pm' => $params['financial_pm'],
|
'mark' => $params['mark'] ?? '',
|
||||||
'batch' => $batch_count + 1,
|
];
|
||||||
'nums' => $params['nums'],
|
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||||
'before_nums' => $before_nums,
|
$data['manufacture'] = strtotime($params['manufacture']);
|
||||||
'after_nums' => $after_nums,
|
}
|
||||||
// 'price' => $params['price'] ?? '',
|
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
||||||
'purchase' => $params['purchase'] ?? '',
|
$data['expiration_date'] = strtotime($params['expiration_date']);
|
||||||
// 'cost' => $params['cost'] ?? '',
|
}
|
||||||
'total_price' => $params['total_price'] ?? '',
|
$res = WarehouseProduct::create($data);
|
||||||
'admin_id' => $params['admin_id'],
|
|
||||||
'code' => $params['code'] ?? '',
|
|
||||||
'status' => 1,
|
|
||||||
'mark' => $params['mark'] ?? '',
|
|
||||||
];
|
|
||||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
|
||||||
$data['manufacture'] = strtotime($params['manufacture']);
|
|
||||||
}
|
|
||||||
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
|
||||||
$data['expiration_date'] = strtotime($params['expiration_date']);
|
|
||||||
}
|
|
||||||
$res = WarehouseProduct::create($data);
|
|
||||||
|
|
||||||
//更改采购订单状态
|
//更改采购订单状态
|
||||||
if(isset($params['purchase_product_offer_id']) &&$params['purchase_product_offer_id']!=''){
|
if (isset($params['purchase_product_offer_id']) && $params['purchase_product_offer_id'] != '') {
|
||||||
PurchaseProductOffer::where('id',$params['purchase_product_offer_id'])->update(['is_storage'=>1,'supplier_id'=>$params['supplier_id']??0]);
|
PurchaseProductOffer::where('id', $params['purchase_product_offer_id'])->update(['is_storage' => 1, 'supplier_id' => $params['supplier_id'] ?? 0]);
|
||||||
}
|
}
|
||||||
// self::enter($res['id'], $params['financial_pm']);
|
// self::enter($res['id'], $params['financial_pm']);
|
||||||
// Db::commit();
|
// Db::commit();
|
||||||
return $res;
|
return $res;
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
throw new BusinessException($e->getMessage());
|
throw new BusinessException($e->getMessage());
|
||||||
// Db::rollback();
|
// Db::rollback();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user