From 8939b40586c0aa52e41f5736e7ca3cebf300b156 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 24 Aug 2024 15:12:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=BA=93=E5=AD=98=E7=BB=9F=E8=AE=A1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/WorkbenchController.php | 17 +- .../lists/statistics/StoreProductLists.php | 23 ++- app/admin/logic/statistic/WarehouseLogic.php | 147 +++++++++++------- 3 files changed, 121 insertions(+), 66 deletions(-) diff --git a/app/admin/controller/WorkbenchController.php b/app/admin/controller/WorkbenchController.php index c6d88fa77..450b5db9c 100644 --- a/app/admin/controller/WorkbenchController.php +++ b/app/admin/controller/WorkbenchController.php @@ -300,19 +300,26 @@ class WorkbenchController extends BaseAdminController */ public function total_warehouse_list() { - $parmas=$this->request->get(); - $data =WarehouseLogic::total_warehouse_list($parmas,$parmas['type']??1); + $parmas = $this->request->get(); + $data = WarehouseLogic::total_warehouse_list($parmas, $parmas['type'] ?? 1); return $this->data($data); } - /** + /** * 统计门店仓库总库存 * @return array */ public function total_warehouse_product_list() { - $parmas=$this->request->get(); - $data =WarehouseLogic::total_warehouse_product_list($parmas,$parmas['type']??1); + $parmas = $this->request->get(); + $data = WarehouseLogic::total_warehouse_product_list($parmas, $parmas['type'] ?? 1); + return $this->data($data); + } + + public function negative_inventory() + { + $parmas = $this->request->get(); + $data = WarehouseLogic::negativeInventory($parmas); return $this->data($data); } } diff --git a/app/admin/lists/statistics/StoreProductLists.php b/app/admin/lists/statistics/StoreProductLists.php index 05306e6e2..fb3586f91 100644 --- a/app/admin/lists/statistics/StoreProductLists.php +++ b/app/admin/lists/statistics/StoreProductLists.php @@ -13,13 +13,14 @@ use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\system_store\SystemStore; use app\common\model\warehouse_product_storege\WarehouseProductStorege; use app\common\lists\ListsExcelInterface; +use app\common\lists\ListsSortInterface; /** * 商品列表列表 * Class StoreProductLists * @package app\admin\listsstore_product */ -class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface +class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface,ListsSortInterface { @@ -33,11 +34,26 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa { return [ '=' => ['cate_id', 'is_show', 'bar_code'], - '<=' => ['stock'], '%like%' => ['store_name'], ]; } - + /** + * @notes 设置支持排序字段 + * @return string[] + * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; + */ + public function setSortFields(): array + { + return ['stock' => 'stock']; + } + /** + * @notes 设置默认排序 + * @return string[] + */ + public function setDefaultOrder(): array + { + return [ 'p.id' => 'desc','p.stock' => 'desc',]; + } /** * @notes 获取商品列表列表 @@ -71,6 +87,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.delete_time IS NULL) AS total_purchase, (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=1 AND wp.delete_time IS NULL) AS total_completed_amount, (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=0 AND wp.delete_time IS NULL) AS total_outstanding_amount') + ->order($this->sortOrder) ->select() ->each(function ($item) { // 计算总库存 diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index 8d5f4a1ff..67d1ef0a9 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -52,7 +52,7 @@ class WarehouseLogic extends BaseLogic $topData[] = [ 'title' => '总商品库存', 'desc' => '平台统计商品总库存、含门店仓库', - 'total_money' =>$toreProduct['stock'], + 'total_money' => $toreProduct['stock'], 'cash_title' => $toreProduct['total_price'], 'value' => [], 'type' => 1, @@ -66,7 +66,7 @@ class WarehouseLogic extends BaseLogic 'value' => [], 'type' => 1, ]; - $warehouseProductStorege_1 = WarehouseProductStorege::where('nums', '>', 0)->where('warehouse_id',1)->field('sum(nums) as nums,sum(total_price) as total_price')->find(); + $warehouseProductStorege_1 = WarehouseProductStorege::where('nums', '>', 0)->where('warehouse_id', 1)->field('sum(nums) as nums,sum(total_price) as total_price')->find(); $topData[] = [ 'title' => '海吉星仓库库存', 'desc' => '平台统计海吉星仓库库存', @@ -75,7 +75,7 @@ class WarehouseLogic extends BaseLogic 'value' => [], 'type' => 1, ]; - $warehouseProductStorege_2 = WarehouseProductStorege::where('nums', '>', 0)->where('warehouse_id',2)->field('sum(nums) as nums,sum(total_price) as total_price')->find(); + $warehouseProductStorege_2 = WarehouseProductStorege::where('nums', '>', 0)->where('warehouse_id', 2)->field('sum(nums) as nums,sum(total_price) as total_price')->find(); $topData[] = [ 'title' => '泸县集采集配库存', 'desc' => '平台统计泸县集采集配库存', @@ -88,7 +88,7 @@ class WarehouseLogic extends BaseLogic $topData[] = [ 'title' => '总门店库存', 'desc' => '平台统计门店库存', - 'total_money' =>$storeBranchProduct['stock'], + 'total_money' => $storeBranchProduct['stock'], 'cash_title' => $storeBranchProduct['total_price'], 'value' => [], 'type' => 1, @@ -109,73 +109,104 @@ class WarehouseLogic extends BaseLogic * 统计门店仓库总库存 * @return array */ - public static function total_warehouse_list($parmas,$type=1) { - if($type==1){ - $list=StoreBranchProduct::where('stock','>',0)->where('product_id',$parmas['product_id']) - ->select()->each(function ($item){ - $item->system_store = SystemStore::where('id',$item['store_id'])->value('name'); - $item->total_price = bcmul($item->purchase,$item->stock,2); - }); - $count=StoreBranchProduct::where('stock','>',0)->where('product_id',$parmas['product_id']) - ->count(); - }else{ - $list=WarehouseProductStorege::where('nums','>',0)->where('product_id',$parmas['product_id'])->select()->each(function ($item){ - $item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name'); - $find = StoreProduct::where('id',$item['product_id'])->find(); - $item->store_name=$find['store_name']; - $item->image=$find['image']; - $item->purchase=$find['purchase']; - if($find['purchase']>0 && $item->nums>0){ - $item->total_price = bcmul($find['purchase'],$item->nums,2); - }else{ + public static function total_warehouse_list($parmas, $type = 1) + { + if ($type == 1) { + $list = StoreBranchProduct::where('stock', '>', 0)->where('product_id', $parmas['product_id']) + ->select()->each(function ($item) { + $item->system_store = SystemStore::where('id', $item['store_id'])->value('name'); + $item->total_price = bcmul($item->purchase, $item->stock, 2); + }); + $count = StoreBranchProduct::where('stock', '>', 0)->where('product_id', $parmas['product_id']) + ->count(); + } else { + $list = WarehouseProductStorege::where('nums', '>', 0)->where('product_id', $parmas['product_id'])->select()->each(function ($item) { + $item->warehouse_name = Warehouse::where('id', $item['warehouse_id'])->value('name'); + $find = StoreProduct::where('id', $item['product_id'])->find(); + $item->store_name = $find['store_name']; + $item->image = $find['image']; + $item->purchase = $find['purchase']; + if ($find['purchase'] > 0 && $item->nums > 0) { + $item->total_price = bcmul($find['purchase'], $item->nums, 2); + } else { $item->total_price = 0; } }); - $count=WarehouseProductStorege::where('nums','>',0)->where('product_id',$parmas['product_id'])->count(); + $count = WarehouseProductStorege::where('nums', '>', 0)->where('product_id', $parmas['product_id'])->count(); } - return ['lists'=>$list,'count'=>$count]; + return ['lists' => $list, 'count' => $count]; } /** * 统计商品采购总价 已结未结 * @return array */ - public static function total_warehouse_product_list($parmas,$type=1) { - $list=[]; - $count=0; - if($type==1){ + public static function total_warehouse_product_list($parmas, $type = 1) + { + $list = []; + $count = 0; + if ($type == 1) { //总采购价 - $where=[['product_id','=',$parmas['product_id']],['nums','>',0],['financial_pm','=',1]]; - $list=WarehouseProduct::where($where)->select()->each(function ($item){ - $item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name'); - $item->supplier_name = Supplier::where('id',$item['supplier_id'])->value('mer_name'); - $find = StoreProduct::where('id',$item['product_id'])->find(); - $item->store_name=$find['store_name']; - $item->image=$find['image']; + $where = [['product_id', '=', $parmas['product_id']], ['nums', '>', 0], ['financial_pm', '=', 1]]; + $list = WarehouseProduct::where($where)->select()->each(function ($item) { + $item->warehouse_name = Warehouse::where('id', $item['warehouse_id'])->value('name'); + $item->supplier_name = Supplier::where('id', $item['supplier_id'])->value('mer_name'); + $find = StoreProduct::where('id', $item['product_id'])->find(); + $item->store_name = $find['store_name']; + $item->image = $find['image']; }); - $count=WarehouseProduct::where($where)->count(); - }elseif($type==2){ - //已结算采购价 - $where=[['product_id','=',$parmas['product_id']],['nums','>',0],['financial_pm','=',1],['is_pay','=',1]]; - $list=WarehouseProduct::where($where)->select()->each(function ($item){ - $item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name'); - $item->supplier_name = Supplier::where('id',$item['supplier_id'])->value('mer_name'); - $find = StoreProduct::where('id',$item['product_id'])->find(); - $item->store_name=$find['store_name']; - $item->image=$find['image']; + $count = WarehouseProduct::where($where)->count(); + } elseif ($type == 2) { + //已结算采购价 + $where = [['product_id', '=', $parmas['product_id']], ['nums', '>', 0], ['financial_pm', '=', 1], ['is_pay', '=', 1]]; + $list = WarehouseProduct::where($where)->select()->each(function ($item) { + $item->warehouse_name = Warehouse::where('id', $item['warehouse_id'])->value('name'); + $item->supplier_name = Supplier::where('id', $item['supplier_id'])->value('mer_name'); + $find = StoreProduct::where('id', $item['product_id'])->find(); + $item->store_name = $find['store_name']; + $item->image = $find['image']; }); - $count=WarehouseProduct::where($where)->count(); - }elseif($type==3){ - //未结算采购价 - $where=[['product_id','=',$parmas['product_id']],['nums','>',0],['financial_pm','=',1],['is_pay','=',0]]; - $list=WarehouseProduct::where($where)->select()->each(function ($item){ - $item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name'); - $item->supplier_name = Supplier::where('id',$item['supplier_id'])->value('mer_name'); - $find = StoreProduct::where('id',$item['product_id'])->find(); - $item->store_name=$find['store_name']; - $item->image=$find['image']; + $count = WarehouseProduct::where($where)->count(); + } elseif ($type == 3) { + //未结算采购价 + $where = [['product_id', '=', $parmas['product_id']], ['nums', '>', 0], ['financial_pm', '=', 1], ['is_pay', '=', 0]]; + $list = WarehouseProduct::where($where)->select()->each(function ($item) { + $item->warehouse_name = Warehouse::where('id', $item['warehouse_id'])->value('name'); + $item->supplier_name = Supplier::where('id', $item['supplier_id'])->value('mer_name'); + $find = StoreProduct::where('id', $item['product_id'])->find(); + $item->store_name = $find['store_name']; + $item->image = $find['image']; }); - $count=WarehouseProduct::where($where)->count(); + $count = WarehouseProduct::where($where)->count(); } - return ['lists'=>$list,'count'=>$count]; + return ['lists' => $list, 'count' => $count]; + } + + /** + * 负库存检测 + */ + public static function negativeInventory($parmas) + { + if ($parmas['type'] == 1) { + $list = StoreProduct::where('stock', '<', 0)->page($parmas['page_no'], 15)->select()->toArray(); + $count = StoreProduct::where('stock', '<', 0)->count(); + } elseif ($parmas['type'] == 2) { + $list = StoreBranchProduct::where('stock', '<', 0)->page($parmas['page_no'], 15)->select() + ->each(function ($item) { + $item->remark = SystemStore::where('id', $item['store_id'])->value('name'); + }) + ->toArray(); + $count = StoreBranchProduct::where('stock', '<', 0)->count(); + } elseif ($parmas['type'] == 3) { + $list = WarehouseProductStorege::where('nums', '<', 0)->page($parmas['page_no'], 15)->select() + ->each(function ($item) { + $find = StoreProduct::where('id', $item['product_id'])->find(); + $item->store_name = $find['store_name']; + $item->image = $find['image']; + $item->stock = $item['nums']; + $item->remark = Warehouse::where('id', $item['warehouse_id'])->value('name'); + })->toArray(); + $count = WarehouseProductStorege::where('nums', '<', 0)->count(); + } + return ['lists' => $list, 'count' => $count]; } }