From 51f5725afabdb73a6f109a0ea2c659c3fbdb349d Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 22 Aug 2024 17:28:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E7=BB=9F=E8=AE=A1=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/WorkbenchController.php | 5 +- .../lists/statistics/StoreProductLists.php | 145 ++++++++++++++++++ app/admin/logic/statistic/WarehouseLogic.php | 30 +--- .../model/store_product/StoreProduct.php | 1 - 4 files changed, 153 insertions(+), 28 deletions(-) create mode 100644 app/admin/lists/statistics/StoreProductLists.php diff --git a/app/admin/controller/WorkbenchController.php b/app/admin/controller/WorkbenchController.php index 0ea9348b..afbd03c5 100644 --- a/app/admin/controller/WorkbenchController.php +++ b/app/admin/controller/WorkbenchController.php @@ -14,6 +14,7 @@ namespace app\admin\controller; +use app\admin\lists\statistics\StoreProductLists; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupLists; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupMonthLists; use app\admin\logic\statistic\ProductStatisticLogic; @@ -287,7 +288,7 @@ class WorkbenchController extends BaseAdminController */ public function warehouse_list() { - $data=WarehouseLogic::warehouse_list(); - return $this->data($data); + return $this->dataLists(new StoreProductLists()); + } } diff --git a/app/admin/lists/statistics/StoreProductLists.php b/app/admin/lists/statistics/StoreProductLists.php new file mode 100644 index 00000000..d5f04386 --- /dev/null +++ b/app/admin/lists/statistics/StoreProductLists.php @@ -0,0 +1,145 @@ + ['cate_id', 'is_show', 'bar_code'], + '<=' => ['stock'], + '%like%' => ['store_name'], + ]; + } + + + /** + * @notes 获取商品列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function lists(): array + { + $class_all = $this->request->get('class_all'); + if ($class_all) { + //查3级别的 + $arr = Cate::where('pid', $class_all)->column('id'); + if ($arr) { + $arr2 = Cate::where('pid', 'in', $arr)->column('id'); + $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; + } else { + $this->searchWhere[] = ['cate_id', '=', $class_all]; + } + } + $list = StoreProduct::where($this->searchWhere) + ->alias('p') // 为 StoreProduct 表设置别名 + ->limit($this->limitOffset, $this->limitLength) + + ->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) AS sales, + (SELECT SUM(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id) AS store_stock, + (SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id) AS warehouse_stock, + (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id) AS total_purchase, + (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=1) 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) AS total_outstanding_amount') + ->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; + $item->total_purchase=$item->total_purchase??0; + }) + ->toArray(); + return $list; + } + + + /** + * @notes 获取商品列表数量 + * @return int + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function count(): int + { + $export=$this->request->get('export'); + if($export==1){ + $class_all = $this->request->get('class_all'); + if ($class_all) { + //查3级别的 + $arr = Cate::where('pid', $class_all)->column('id'); + if ($arr) { + $arr2 = Cate::where('pid', 'in', $arr)->column('id'); + $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; + } else { + $this->searchWhere[] = ['cate_id', '=', $class_all]; + } + } + } + return StoreProduct::where($this->searchWhere)->count(); + } + + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + return '商品列表'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $data = [ + 'store_name' => '商品名称', + 'cate_name'=>'分类', + 'unit_name'=>'单位', + 'stock' => '库存', + 'purchase' => '采购价', + 'cost' => '商户', + 'price' => '零售', + ]; + return $data; + } +} diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index a7ff4ec4..d2ba2d0a 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -47,12 +47,12 @@ 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'); + $store_stock_1 = StoreBranchProduct::where('stock', '>', 0)->sum('stock'); + $store_stock_2 = WarehouseProductStorege::where('nums', '>', 0)->sum('nums'); $topData[] = [ 'title' => '总商品库存', 'desc' => '平台统计商品总库存、含门店仓库', - 'total_money' => bcadd($store_stock_1,$store_stock_2,2), + 'total_money' => bcadd($store_stock_1, $store_stock_2, 2), 'cash_title' => 0, 'value' => [], 'type' => 1, @@ -68,7 +68,7 @@ class WarehouseLogic extends BaseLogic $topData[] = [ 'title' => '海吉星仓库库存', 'desc' => '平台统计海吉星仓库库存', - 'total_money' => WarehouseProductStorege::where('warehouse_id',1)->sum('nums'), + 'total_money' => WarehouseProductStorege::where('warehouse_id', 1)->sum('nums'), 'cash_title' => 0, 'value' => [], 'type' => 1, @@ -76,7 +76,7 @@ class WarehouseLogic extends BaseLogic $topData[] = [ 'title' => '泸县集采集配库存', 'desc' => '平台统计泸县集采集配库存', - 'total_money' => WarehouseProductStorege::where('warehouse_id',2)->sum('nums'), + 'total_money' => WarehouseProductStorege::where('warehouse_id', 2)->sum('nums'), 'cash_title' => 0, 'value' => [], 'type' => 1, @@ -103,24 +103,4 @@ class WarehouseLogic extends BaseLogic return $data; } - public static function warehouse_list() - { - $list = StoreProduct::where('is_show', 1) - ->field('id,store_name,image') - ->select()->each(function ($item) { - // $item->sales = StoreOrderCartInfo::where('product_id', $item['id'])->where('is_pay',1)->sum('cart_num'); - // $store_stock = StoreBranchProduct::where('product_id', $item['id'])->sum('stock'); - // $warehouse_stock = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums'); - // $item->store_stock=$store_stock; - // $item->warehouse_stock=$warehouse_stock; - // $item->total_stock=$store_stock+$warehouse_stock; - // $item->total_purchase=WarehouseProduct::where('product_id', $item['id'])->sum('total_price'); - // $item->total_completed_amount=WarehouseProduct::where('product_id', $item['id'])->where('is_pay',1)->sum('total_price'); - // $item->total_outstanding_amount=WarehouseProduct::where('product_id', $item['id'])->where('is_pay',0)->sum('total_price'); - // sum(branch_product.stock) as store_stock,sum(w_p.total_price) as total_purchase, - })->toArray(); - return $list; - } - - } diff --git a/app/common/model/store_product/StoreProduct.php b/app/common/model/store_product/StoreProduct.php index 871b88ca..dc810fdd 100644 --- a/app/common/model/store_product/StoreProduct.php +++ b/app/common/model/store_product/StoreProduct.php @@ -5,7 +5,6 @@ namespace app\common\model\store_product; use app\common\model\BaseModel; use app\common\model\store_category\StoreCategory; -use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product_unit\StoreProductUnit; use think\model\concern\SoftDelete;