feat: 修改商品与仓库库存逻辑,优化库存管理,增强代码安全性与结构

This commit is contained in:
mkm 2024-08-11 20:11:20 +08:00
parent 262c730674
commit ade922f4d5
3 changed files with 24 additions and 8 deletions

View File

@ -34,7 +34,6 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
'=' => ['product_id', 'cate_id', 'store_id', 'status'],
'%pipe_like%' => ['store_name_code' => 'store_name|bar_code'],
'%like%' => ['store_name'],
'<=' => ['stock'],
];
}
/**
@ -44,7 +43,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
*/
public function setSortFields(): array
{
return ['stock' => 'stock',];
return ['stock' => 'stock'];
}
/**
* @notes 设置默认排序
@ -52,7 +51,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
*/
public function setDefaultOrder(): array
{
return ['sort' => 'desc', 'stock' => 'desc', 'id' => 'desc'];
return [ 'id' => 'desc','stock' => 'desc',];
}
/**
* @notes 获取门店列表列表

View File

@ -10,13 +10,14 @@ use app\common\model\store_category\StoreCategory;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\warehouse\Warehouse;
use app\common\lists\ListsSortInterface;
/**
* 仓库商品存储列表
* Class WarehouseProductStoregeLists
* @package app\admin\listswarehouse_product_storege
*/
class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSearchInterface
class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSearchInterface,ListsSortInterface
{
public $ids;
public $store_name;
@ -33,7 +34,23 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
'=' => ['warehouse_id','product_id'],
];
}
/**
* @notes 设置支持排序字段
* @return string[]
* @remark 格式: ['前端传过来的字段名' => '数据库中的字段名'];
*/
public function setSortFields(): array
{
return ['nums' => 'nums'];
}
/**
* @notes 设置默认排序
* @return string[]
*/
public function setDefaultOrder(): array
{
return [ 'id' => 'desc','nums' => 'desc',];
}
/**
* @notes 获取仓库商品存储列表
@ -58,7 +75,7 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
return WarehouseProductStorege::where($this->searchWhere)
->field(['id', 'warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->order($this->sortOrder)
->select()->each(function ($item) {
$item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name');
$find = StoreProduct::where('id', $item->product_id)->find();

View File

@ -29,10 +29,10 @@ trait ListsSortTrait
return $defaultOrder;
}
if ($this->orderBy = 'desc') {
if ($this->orderBy == 'desc') {
return [$field => 'desc'];
}
if ($this->orderBy = 'asc') {
if ($this->orderBy == 'asc') {
return [$field => 'asc'];
}
return $defaultOrder;