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)
|
||||
->alias('p') // 为 StoreProduct 表设置别名
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
|
||||
->field('p.id, p.store_name, p.image,
|
||||
->field('p.id, p.store_name, p.image,p.stock as total_stock,
|
||||
(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(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()
|
||||
->each(function ($item) {
|
||||
// 计算总库存
|
||||
$item->total_stock = $item->store_stock + $item->warehouse_stock;
|
||||
$item->total_completed_amount=$item->total_completed_amount??0;
|
||||
$item->warehouse_stock=$item->warehouse_stock??0;
|
||||
$item->total_outstanding_amount=$item->total_outstanding_amount??0;
|
||||
@ -139,6 +137,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
'purchase' => '采购价',
|
||||
'cost' => '商户',
|
||||
'price' => '零售',
|
||||
'total_price' => '总采购价',
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
@ -34,8 +34,6 @@ class WarehouseLogic extends BaseLogic
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
|
||||
|
||||
$topData[] = [
|
||||
'title' => '已结算金额',
|
||||
'desc' => '平台支付给供应商的金额',
|
||||
@ -50,46 +48,48 @@ class WarehouseLogic extends BaseLogic
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
$store_stock_1 = StoreBranchProduct::where('stock', '>', 0)->sum('stock');
|
||||
$store_stock_2 = WarehouseProductStorege::where('nums', '>', 0)->sum('nums');
|
||||
$toreProduct = StoreProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find();
|
||||
$topData[] = [
|
||||
'title' => '总商品库存',
|
||||
'desc' => '平台统计商品总库存、含门店仓库',
|
||||
'total_money' => bcadd($store_stock_1, $store_stock_2, 2),
|
||||
'cash_title' => 1,
|
||||
'total_money' =>$toreProduct['stock'],
|
||||
'cash_title' => $toreProduct['total_price'],
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
$warehouseProductStorege = WarehouseProductStorege::where('stock', '>', 0)->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
$topData[] = [
|
||||
'title' => '总仓库库存',
|
||||
'desc' => '平台统计仓库库存',
|
||||
'total_money' => WarehouseProductStorege::sum('nums'),
|
||||
'cash_title' => 1,
|
||||
'total_money' => $warehouseProductStorege['nums'],
|
||||
'cash_title' => $warehouseProductStorege['total_price'],
|
||||
'value' => [],
|
||||
'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[] = [
|
||||
'title' => '海吉星仓库库存',
|
||||
'desc' => '平台统计海吉星仓库库存',
|
||||
'total_money' => WarehouseProductStorege::where('warehouse_id', 1)->sum('nums'),
|
||||
'cash_title' => 1,
|
||||
'total_money' => $warehouseProductStorege_1['nums'],
|
||||
'cash_title' => $warehouseProductStorege_1['total_price'],
|
||||
'value' => [],
|
||||
'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[] = [
|
||||
'title' => '泸县集采集配库存',
|
||||
'desc' => '平台统计泸县集采集配库存',
|
||||
'total_money' => WarehouseProductStorege::where('warehouse_id', 2)->sum('nums'),
|
||||
'cash_title' => 1,
|
||||
'total_money' => $warehouseProductStorege_2['nums'],
|
||||
'cash_title' => $warehouseProductStorege_2['total_price'],
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
$storeBranchProduct = StoreBranchProduct::where('stock', '>', 0)->field('sum(stock) as stock,sum(total_price) as total_price')->find();
|
||||
$topData[] = [
|
||||
'title' => '总门店库存',
|
||||
'desc' => '平台统计门店库存',
|
||||
'total_money' => StoreBranchProduct::sum('stock'),
|
||||
'cash_title' => 1,
|
||||
|
||||
'total_money' =>$storeBranchProduct['stock'],
|
||||
'cash_title' => $storeBranchProduct['total_price'],
|
||||
'value' => [],
|
||||
'type' => 1,
|
||||
];
|
||||
@ -100,7 +100,6 @@ class WarehouseLogic extends BaseLogic
|
||||
$data['series'][$k]['desc'] = $v['desc'];
|
||||
$data['series'][$k]['total_value'] = $v['total_money'];
|
||||
$data['series'][$k]['total_money'] = $v['cash_title'] ?? '';
|
||||
|
||||
$data['series'][$k]['type'] = $v['type'];
|
||||
}
|
||||
return $data;
|
||||
|
@ -33,83 +33,94 @@ class WarehouseProductLogic extends BaseLogic
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function add(array $params,$type=1)
|
||||
public static function add(array $params, $type = 1)
|
||||
{
|
||||
// Db::startTrans();
|
||||
try {
|
||||
$before_nums = 0;
|
||||
$after_nums = 0;
|
||||
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storege) {
|
||||
if ($params['financial_pm'] == 0) {
|
||||
$after_nums = $storege['nums'] - $params['nums'];
|
||||
// if ($after_nums < 0) {
|
||||
// throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
|
||||
// }
|
||||
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();
|
||||
if(!$storeBranchProduct){
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
|
||||
if (!$storeProduct) {
|
||||
throw new BusinessException('商品不存在');
|
||||
$before_nums = 0;
|
||||
$after_nums = 0;
|
||||
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||
if ($storege) {
|
||||
if ($params['financial_pm'] == 0) {
|
||||
$after_nums = $storege['nums'] - $params['nums'];
|
||||
// if ($after_nums < 0) {
|
||||
// throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
|
||||
// }
|
||||
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();
|
||||
if (!$storeBranchProduct) {
|
||||
$storeProduct = StoreProduct::where('id', $params['product_id'])->findOrEmpty()->toArray();
|
||||
if (!$storeProduct) {
|
||||
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 {
|
||||
$after_nums = $storege['nums'] + $params['nums'];
|
||||
if($type==1){
|
||||
WarehouseProductStorege::where('id', $storege['id'])->inc('nums', $params['nums'])->update();
|
||||
$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([
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'nums' => $params['nums'],
|
||||
'total_price'=>$total_price
|
||||
]);
|
||||
}
|
||||
$before_nums = $storege['nums'];
|
||||
} else {
|
||||
$after_nums=$params['nums'];
|
||||
WarehouseProductStorege::create([
|
||||
$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();
|
||||
$data = [
|
||||
'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'],
|
||||
'financial_pm' => $params['financial_pm'],
|
||||
'batch' => $batch_count + 1,
|
||||
'nums' => $params['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();
|
||||
$data = [
|
||||
'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'],
|
||||
'financial_pm' => $params['financial_pm'],
|
||||
'batch' => $batch_count + 1,
|
||||
'nums' => $params['nums'],
|
||||
'before_nums' => $before_nums,
|
||||
'after_nums' => $after_nums,
|
||||
// 'price' => $params['price'] ?? '',
|
||||
'purchase' => $params['purchase'] ?? '',
|
||||
// 'cost' => $params['cost'] ?? '',
|
||||
'total_price' => $params['total_price'] ?? '',
|
||||
'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);
|
||||
'before_nums' => $before_nums,
|
||||
'after_nums' => $after_nums,
|
||||
// 'price' => $params['price'] ?? '',
|
||||
'purchase' => $params['purchase'] ?? '',
|
||||
// 'cost' => $params['cost'] ?? '',
|
||||
'total_price' => $params['total_price'] ?? '',
|
||||
'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']!=''){
|
||||
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']);
|
||||
// Db::commit();
|
||||
return $res;
|
||||
//更改采购订单状态
|
||||
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]);
|
||||
}
|
||||
// self::enter($res['id'], $params['financial_pm']);
|
||||
// Db::commit();
|
||||
return $res;
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
// Db::rollback();
|
||||
|
Loading…
x
Reference in New Issue
Block a user