feat: 修改商品库存逻辑,优化库存检查与错误处理,增强代码安全性

This commit is contained in:
mkm 2024-08-11 17:55:09 +08:00
parent ffe38b81f1
commit 262c730674

View File

@ -11,13 +11,14 @@ use app\common\model\system_store\SystemStore;
use app\common\lists\ListsSearchInterface;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\lists\ListsExcelInterface;
use app\common\lists\ListsSortInterface;
/**
* 门店商品辅助表
* Class StoreBranchProductLists
* @package app\admin\listssystem_store
*/
class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface, ListsSortInterface
{
@ -36,8 +37,23 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
'<=' => ['stock'],
];
}
/**
* @notes 设置支持排序字段
* @return string[]
* @remark 格式: ['前端传过来的字段名' => '数据库中的字段名'];
*/
public function setSortFields(): array
{
return ['stock' => 'stock',];
}
/**
* @notes 设置默认排序
* @return string[]
*/
public function setDefaultOrder(): array
{
return ['sort' => 'desc', 'stock' => 'desc', 'id' => 'desc'];
}
/**
* @notes 获取门店列表列表
* @return array
@ -71,7 +87,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
$query->where('store_id', $this->adminInfo['store_id']);
})
->limit($this->limitOffset, $this->limitLength)
->order(['sort' => 'desc','stock'=>'desc','id' => 'desc'])
->order($this->sortOrder)
->select()
->each(function ($item) {
$item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name');