feat: 修改仓库库存统计方式
This commit is contained in:
parent
c9f7d1a996
commit
51f5725afa
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
namespace app\admin\controller;
|
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\StoreOrderCartInfoGroupLists;
|
||||||
use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupMonthLists;
|
use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupMonthLists;
|
||||||
use app\admin\logic\statistic\ProductStatisticLogic;
|
use app\admin\logic\statistic\ProductStatisticLogic;
|
||||||
@ -287,7 +288,7 @@ class WorkbenchController extends BaseAdminController
|
|||||||
*/
|
*/
|
||||||
public function warehouse_list()
|
public function warehouse_list()
|
||||||
{
|
{
|
||||||
$data=WarehouseLogic::warehouse_list();
|
return $this->dataLists(new StoreProductLists());
|
||||||
return $this->data($data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
145
app/admin/lists/statistics/StoreProductLists.php
Normal file
145
app/admin/lists/statistics/StoreProductLists.php
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\lists\statistics;
|
||||||
|
|
||||||
|
|
||||||
|
use app\admin\lists\BaseAdminDataLists;
|
||||||
|
use app\common\model\cate\Cate;
|
||||||
|
use app\common\model\store_product\StoreProduct;
|
||||||
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_category\StoreCategory;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品列表列表
|
||||||
|
* Class StoreProductLists
|
||||||
|
* @package app\admin\listsstore_product
|
||||||
|
*/
|
||||||
|
class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 设置搜索条件
|
||||||
|
* @return \string[][]
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/05/31 10:53
|
||||||
|
*/
|
||||||
|
public function setSearch(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'=' => ['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;
|
||||||
|
}
|
||||||
|
}
|
@ -103,24 +103,4 @@ class WarehouseLogic extends BaseLogic
|
|||||||
return $data;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ namespace app\common\model\store_product;
|
|||||||
|
|
||||||
use app\common\model\BaseModel;
|
use app\common\model\BaseModel;
|
||||||
use app\common\model\store_category\StoreCategory;
|
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 app\common\model\store_product_unit\StoreProductUnit;
|
||||||
use think\model\concern\SoftDelete;
|
use think\model\concern\SoftDelete;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user