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

This commit is contained in:
mkm 2024-08-11 16:59:36 +08:00
parent 9122fa3199
commit ffe38b81f1
5 changed files with 108 additions and 6 deletions

View File

@ -10,13 +10,14 @@ use app\common\model\store_product_unit\StoreProductUnit;
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;
/**
* 门店商品辅助表
* Class StoreBranchProductLists
* @package app\admin\listssystem_store
*/
class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchInterface
class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
{
@ -97,4 +98,42 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
->count();
}
/**
* @notes 导出文件名
* @return string
* @author 乔峰
* @date 2022/11/24 16:17
*/
public function setFileName(): string
{
if($this->request->get('store_id')){
$name=SystemStore::where('id',$this->request->get('store_id'))->value('name');
return $name.'商品列表';
}
return '门店商品列表';
}
/**
* @notes 导出字段
* @return string[]
* @author 乔峰
* @date 2022/11/24 16:17
*/
public function setExcelFields(): array
{
$data=[
'store_name' => '商品名称',
'store_info' => '规格',
'unit_name' => '单位',
'cate_name' => '分类',
'stock' => '库存',
'sales' => '销量',
'purchase'=>'供货价',
'cost'=>'商户价',
'vip_price'=>'会员价',
'price' => '零售价',
];
return $data;
}
}

View File

@ -7,6 +7,7 @@ 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;
@ -65,7 +66,9 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
->order(['id' => 'desc'])
->select()->each(function ($item) {
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
$item['stock'] = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
$nums=WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
$stock=StoreBranchProduct::where('store_id','<>','4')->where('product_id',$item['id'])->sum('stock');
$item['stock'] = bcadd($nums,$stock);
$item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name');
return $item;
})?->toArray();

View File

@ -10,13 +10,14 @@ use app\common\model\auth\Admin;
use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore;
use app\common\model\warehouse\Warehouse;
use app\common\lists\ListsExcelInterface;
/**
* 商品仓储信息列表
* Class WarehouseProductLists
* @package app\admin\listswarehouse_product
*/
class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInterface
class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface
{
public $ids;
@ -87,7 +88,9 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
$item->admin_name='';
}
if($item->product_id){
$item->store_name=StoreProduct::where('id',$item->product_id)->value('store_name');
$find=StoreProduct::where('id',$item->product_id)->field('image,store_name')->find();
$item->store_name=$find->store_name;
$item->image=$find->image;
}else{
$item->store_name='';
}
@ -121,5 +124,58 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
return WarehouseProduct::where($this->searchWhere)->count();
}
}
/**
* @notes 导出文件名
* @return string
* @author 乔峰
* @date 2022/11/24 16:17
*/
public function setFileName(): string
{
$financial_pm=$this->request->get('financial_pm');
if($financial_pm==1){
return '入库列表';
}
return '出库列表';
}
/**
* @notes 导出字段
* @return string[]
* @author 乔峰
* @date 2022/11/24 16:17
*/
public function setExcelFields(): array
{
$financial_pm=$this->request->get('financial_pm');
if($financial_pm==1){
$data=[
'admin_name' => '操作人员',
'warehouse_name' => '仓库',
'store_name' => '商品名称',
'financial_pm_name' => '出入库',
'batch' => '批次',
'nums' => '数量',
'manufacture' => '生产日期',
'expiration_date' => '保质期',
'purchase' => '采购价',
'price' => '零售',
'total_price' => '总价',
'create_time' => '操作时间',
];
}else{
$data=[
'admin_name' => '操作人员',
'warehouse_name' => '仓库',
'store_name' => '商品名称',
'financial_pm_name' => '出入库',
'system_store_name'=>'门店',
'nums' => '数量',
'create_time' => '操作时间',
];
}
return $data;
}
}

View File

@ -30,7 +30,7 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
public function setSearch(): array
{
return [
'=' => ['warehouse_id'],
'=' => ['warehouse_id','product_id'],
];
}

View File

@ -51,6 +51,11 @@ class StoreBranchProductLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
$StoreProduct=StoreBranchProduct::where('id', $params['id'])->find();
if($params['status']==1 &&$StoreProduct['price']==0){
self::setError('商品价格不能为0,无法上架');
return false;
}
Db::startTrans();
try {
$data=[
@ -60,7 +65,6 @@ class StoreBranchProductLogic extends BaseLogic
'unit'=>$params['unit'],
'status'=>$params['status'],
];
$StoreProduct=StoreBranchProduct::where('id', $params['id'])->find();
if(isset($params['cate_id'])){
if ($StoreProduct['cate_id'] != $params['cate_id']) {
self::store_product_cate_update($params['id'], $StoreProduct['cate_id'], $StoreProduct['store_id']);