feat: 修改了商品库存统计逻辑

This commit is contained in:
mkm 2024-08-24 15:12:53 +08:00
parent e02639f2ab
commit 8939b40586
3 changed files with 121 additions and 66 deletions

View File

@ -315,4 +315,11 @@ class WorkbenchController extends BaseAdminController
$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);
}
}

View File

@ -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) {
// 计算总库存

View File

@ -109,7 +109,8 @@ class WarehouseLogic extends BaseLogic
* 统计门店仓库总库存
* @return array
*/
public static function total_warehouse_list($parmas,$type=1) {
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) {
@ -139,7 +140,8 @@ class WarehouseLogic extends BaseLogic
* 统计商品采购总价 已结未结
* @return array
*/
public static function total_warehouse_product_list($parmas,$type=1) {
public static function total_warehouse_product_list($parmas, $type = 1)
{
$list = [];
$count = 0;
if ($type == 1) {
@ -178,4 +180,33 @@ class WarehouseLogic extends BaseLogic
}
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];
}
}