feat: 修改了商品库存统计逻辑
This commit is contained in:
parent
e02639f2ab
commit
8939b40586
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
// 计算总库存
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user