From 12b4544233ae2da735f21ca3751cfd1ac70a87cb Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 24 Aug 2024 11:30:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91=E5=B9=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=80=BB=E9=87=87=E8=B4=AD=E4=BB=B7=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lists/statistics/StoreProductLists.php | 5 +- app/admin/logic/statistic/WarehouseLogic.php | 31 ++-- .../WarehouseProductLogic.php | 141 ++++++++++-------- 3 files changed, 93 insertions(+), 84 deletions(-) diff --git a/app/admin/lists/statistics/StoreProductLists.php b/app/admin/lists/statistics/StoreProductLists.php index 06350317a..05306e6e2 100644 --- a/app/admin/lists/statistics/StoreProductLists.php +++ b/app/admin/lists/statistics/StoreProductLists.php @@ -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; } diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index 23ec94f00..f9058cda7 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -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; diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 277a10efa..6d168d8e1 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -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();