From 14ffe6248757da6c33146cfc29b25a541d507768 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 1 Sep 2024 18:04:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E7=BB=9F=E8=AE=A1=E5=92=8C=E8=B4=9F=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/logic/statistic/WarehouseLogic.php | 85 +++++++++----------- 1 file changed, 40 insertions(+), 45 deletions(-) diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index f73e4224c..31b1c3e92 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -56,8 +56,8 @@ class WarehouseLogic extends BaseLogic $topData[] = [ 'title' => '总商品库存', 'desc' => '平台统计商品总库存、含门店仓库', - 'total_money' => bcadd($warehouseProductStorege['nums'],$storeBranchProduct['stock'],2), - 'cash_title' => bcadd($warehouseProductStorege['total_price'],$storeBranchProduct['total_price'],2), + 'total_money' => bcadd($warehouseProductStorege['nums'], $storeBranchProduct['stock'], 2), + 'cash_title' => bcadd($warehouseProductStorege['total_price'], $storeBranchProduct['total_price'], 2), 'value' => [], 'type' => 1, ]; @@ -193,14 +193,14 @@ class WarehouseLogic extends BaseLogic $list = StoreProduct::where('stock', '<', 0)->page($parmas['page_no'], 15)->select()->toArray(); $count = StoreProduct::where('stock', '<', 0)->count(); } elseif ($parmas['type'] == 2) { - $where[]=['stock','<',0]; - if(isset($parmas['store_id']) && $parmas['store_id'] > 0){ - $where[]=['store_id','=',$parmas['store_id']]; + $where[] = ['stock', '<', 0]; + if (isset($parmas['store_id']) && $parmas['store_id'] > 0) { + $where[] = ['store_id', '=', $parmas['store_id']]; } - $store_arr=getenv('NO_STORE_STATISTICS'); - if($store_arr){ - $store_arr=explode(',',$store_arr); - $where[]=['store_id','not in',$store_arr]; + $store_arr = getenv('NO_STORE_STATISTICS'); + if ($store_arr) { + $store_arr = explode(',', $store_arr); + $where[] = ['store_id', 'not in', $store_arr]; } $list = StoreBranchProduct::where($where)->page($parmas['page_no'], 15)->select() ->each(function ($item) { @@ -220,60 +220,55 @@ class WarehouseLogic extends BaseLogic $count = WarehouseProductStorege::where('nums', '<', 0)->count(); } return ['lists' => $list, 'count' => $count]; - } + } /** * 负库存更新归0 */ public static function updateNegativeZero($parmas) { if ($parmas['type'] == 1) { - $res = StoreProduct::where('id',$parmas['id'])->update(['stock'=>0]); + $res = StoreProduct::where('id', $parmas['id'])->update(['stock' => 0]); } elseif ($parmas['type'] == 2) { - $res=StoreBranchProduct::where('id',$parmas['id'])->update(['stock'=>0]); + $res = StoreBranchProduct::where('id', $parmas['id'])->update(['stock' => 0]); } elseif ($parmas['type'] == 3) { - $res = WarehouseProductStorege::where('id',$parmas['id'])->update(['nums'=>0]); + $res = WarehouseProductStorege::where('id', $parmas['id'])->update(['nums' => 0]); } return $res; } - public static function stockProductPrice($parmas){ - $arr1=WarehouseProductStorege::where('nums','>',0)->select(); - foreach ($arr1 as $k=>$v){ - $find=StoreProduct::where('id',$v['product_id'])->find(); - if($find&& $find['price']>0){ - $total_price=bcmul($find['price'],$v['nums'],2); - $price=$find['price']; - }else{ - $total_price=0; - $price=0; + public static function stockProductPrice($parmas) + { + $arr1 = WarehouseProductStorege::where('nums', '>', 0)->select(); + foreach ($arr1 as $k => $v) { + $find = StoreProduct::where('id', $v['product_id'])->find(); + if ($find && $find['price'] > 0) { + $total_price = bcmul($find['price'], $v['nums'], 2); + $price = $find['price']; + } else { + $total_price = 0; + $price = 0; } - WarehouseProductStorege::where('id',$v['id'])->update(['price'=>$price,'total_price'=>$total_price]); + WarehouseProductStorege::where('id', $v['id'])->update(['price' => $price, 'total_price' => $total_price]); } - $arr2=StoreBranchProduct::where('stock','>',0)->select(); - foreach ($arr2 as $k=>$v){ - if($v['price']>0){ - $total_price=bcmul($v['price'],$v['stock'],2); - }else{ - $total_price=0; + $arr2 = StoreBranchProduct::where('stock', '>', 0)->select(); + foreach ($arr2 as $k => $v) { + if ($v['price'] > 0) { + $total_price = bcmul($v['price'], $v['stock'], 2); + } else { + $total_price = 0; } - StoreBranchProduct::where('id',$v['id'])->update(['total_price'=>$total_price]); + StoreBranchProduct::where('id', $v['id'])->update(['total_price' => $total_price]); } - $arr3=WarehouseProductStorege::where('nums','>',0)->field('product_id,sum(nums) as nums')->group('product_id')->select(); - foreach ($arr3 as $k=>$v){ - StoreProduct::where('id',$v['product_id'])->update(['stock'=>$v['nums']]); - } - $arr4=StoreBranchProduct::where('stock','>',0)->field('product_id,sum(stock) as stock')->group('product_id')->order('stock desc')->select(); - foreach ($arr4 as $k=>$v){ - $find=StoreProduct::where('id',$v['product_id'])->find(); - if($find){ - $stock=bcadd($find['stock'],$v['stock'],2); - $find->total_price=bcmul($find['purchase'],$v['stock'],2); - $find->stock=$stock; - $find->save(); - } + $arr3 = StoreProduct::where('stock', '>=', 0)->select(); + foreach ($arr3 as $k => $v) { + $stock = StoreBranchProduct::where('product_id', $v['id'])->where('stock', '>', 0)->sum('stock'); + $nums = WarehouseProductStorege::where('nums', '>', 0)->where('product_id', $v['id'])->sum('nums'); + $stock2 = bcadd($stock, $nums, 2); + bcmul($v['purchase'], $stock2, 2); + StoreProduct::where('id', $v['id'])->update(['stock' => $stock2, 'total_price' => $v]); } + return true; } - }