refactor(warehouse): 重构仓库相关逻辑

- 修改了 SystemStoreStorageController 中的 lists 方法,使用 StoreWarehouseProductLists 替代 SystemStoreStorageLists
- 更新了 SystemStoreStorageLogic 中的数据查询,使用 WarehouseProduct 替代 SystemStoreStorage
- 调整了 WarehouseProductLogic 中的入库逻辑,注释掉了创建 SystemStoreStorage 记录的部分
- 修改了 WarehouseProductLogic 中的保存逻辑,将状态设置为 0
This commit is contained in:
mkm 2025-02-11 10:43:12 +08:00
parent 51e848718f
commit 66b74b6e7c
4 changed files with 204 additions and 18 deletions

View File

@ -5,6 +5,7 @@ namespace app\admin\controller\system_store_storage;
use app\admin\controller\BaseAdminController;
use app\admin\lists\system_store_storage\SystemStoreStorageLists;
use app\admin\lists\warehouse_product\StoreWarehouseProductLists;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\system_store_storage\SystemStoreStorageLogic;
use app\admin\validate\system_store_storage\SystemStoreStorageValidate;
@ -29,7 +30,8 @@ class SystemStoreStorageController extends BaseAdminController
*/
public function lists()
{
return $this->dataLists(new SystemStoreStorageLists());
// return $this->dataLists(new SystemStoreStorageLists());
return $this->dataLists(new StoreWarehouseProductLists());
}

View File

@ -0,0 +1,182 @@
<?php
namespace app\admin\lists\warehouse_product;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\lists\ListsSearchInterface;
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;
use app\common\model\store_category\StoreCategory;
use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\supplier\Supplier;
/**
* 商品仓储信息列表
* Class StoreWarehouseProductLists
* @package app\admin\listswarehouse_product
*/
class StoreWarehouseProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
{
public $ids;
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/07/31 16:55
*/
public function setSearch(): array
{
return [
'=' => ['store_id', 'status',],
'between_time' => 'create_time'
];
}
/**
* @notes 获取商品仓储信息列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/07/31 16:55
*/
public function lists(): array
{
if ($this->request->get('product_name')) {
$product_name = $this->request->get('product_name');
$ids = StoreProduct::where('store_name', 'like', '%' . $product_name . '%')->withTrashed()->column('id');
if ($ids) {
$this->searchWhere[] = ['product_id', 'in', $ids];
$this->ids = $ids;
} else {
return [];
}
}
$this->searchWhere[] = ['financial_pm', '=',0];
$this->searchWhere[] = ['order_type', 'in',[1, 2, 3, 4, 8]];
return WarehouseProduct::where($this->searchWhere)
->field(['id', 'admin_id', 'store_id','product_id', 'nums', 'status', 'mark', 'create_time',])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
// ->withTrashed()
->select()->each(function ($item) {
$item->store_name = '';
$item->image = '';
$item->unit_name = '';
if ($item->store_id > 0) {
$item->system_store_name = SystemStore::where('id', $item->store_id)->value('name');
} else {
$item->system_store_name = '';
}
if ($item->status == 0) {
$item->status_name = '未确认';
} elseif ($item->status == 1) {
$item->status_name = '已确认';
}
if ($item->admin_id) {
$item->admin_name = Admin::where('id', $item->admin_id)->value('name');
} else {
$item->admin_name = '';
}
if ($item->product_id) {
$find = StoreProduct::where('id', $item->product_id)->field('image,store_name,unit')->withTrashed()->find();
if($find){
$item->store_name = $find->store_name;
$item->image = $find->image;
$item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name');
}
}
})
->toArray();
}
/**
* @notes 获取商品仓储信息数量
* @return int
* @author admin
* @date 2024/07/31 16:55
*/
public function count(): int
{
if ($this->ids) {
return WarehouseProduct::whereIn('id', $this->ids)->where($this->searchWhere)->count();
} else {
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' => '仓库',
'supplier_name' => '供应商',
'store_name' => '商品名称',
'financial_pm_name' => '出入库',
'code' => '入库单',
'batch' => '批次',
'nums' => '数量',
'manufacture' => '生产日期',
'expiration_date' => '保质期',
'purchase' => '采购价',
'price' => '零售',
'total_price' => '总价',
'create_time' => '操作时间',
];
} else {
$data = [
'id' => 'id',
'admin_name' => '操作人员',
'warehouse_name' => '仓库',
'store_name' => '商品名称',
'top_cate_name' => '分类',
'store_info' => '规格',
'unit_name' => '单位',
'financial_pm_name' => '出入库',
'code' => '出库单',
'system_store_name' => '门店',
'nums' => '数量',
'purchase' => '供货价',
'price' => '零售价',
'total_price' => '供货总价',
'create_time' => '操作时间',
];
}
return $data;
}
}

View File

@ -63,7 +63,8 @@ class SystemStoreStorageLogic extends BaseLogic
{
Db::startTrans();
try {
$find=SystemStoreStorage::where(['id' => $params['id']])->find();
$find= WarehouseProduct::where(['id' => $params['id']])->find();
// $find=SystemStoreStorage::where(['id' => $params['id']])->find();
if($find){
// if($find['order_type']==1){
$find->save(['status'=>1,'staff_id'=>$params['staff_id']??0,'admin_id'=>$params['admin_id']??0,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]);
@ -103,7 +104,8 @@ class SystemStoreStorageLogic extends BaseLogic
$productIds = StoreProduct::where('store_name', 'like', '%' . $params['product_name'] . '%')->column('id');
$where[] = ['product_id', 'in', $productIds];
}
$list = SystemStoreStorage::where($where)->column('id');
// $list = SystemStoreStorage::where($where)->column('id');
$list = WarehouseProduct::where($where)->column('id');
foreach ($list as $item) {
$params['id'] = $item;
self::edit($params, $adminId);

View File

@ -129,20 +129,20 @@ class WarehouseProductLogic extends BaseLogic
if ($params['order_type'] != 6) {
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
if ($storege) {
if (($params['store_id'] == 3 && in_array($params['order_type'], [1, 2, 3, 4, 8])) || in_array($params['order_type'], [1, 4])) {
SystemStoreStorage::create([
'store_id' => $params['store_id'],
'admin_id' => $params['admin_id'],
'order_type' => $params['order_type'],
'staff_id' => 0,
'type' => 1,
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'outbound_id' => $params['oid'] ?? 0,
'warehouse_id' =>1,
'status' => 0
]);
}
// if (($params['store_id'] == 3 && in_array($params['order_type'], [1, 2, 3, 4, 8])) || in_array($params['order_type'], [1, 4])) {
// SystemStoreStorage::create([
// 'store_id' => $params['store_id'],
// 'admin_id' => $params['admin_id'],
// 'order_type' => $params['order_type'],
// 'staff_id' => 0,
// 'type' => 1,
// 'product_id' => $params['product_id'],
// 'nums' => $params['nums'],
// 'outbound_id' => $params['oid'] ?? 0,
// 'warehouse_id' =>1,
// 'status' => 0
// ]);
// }
$after_nums = bcsub($storege['nums'], $params['nums']);
$total_price = bcmul($after_nums, $params['purchase'], 2);
WarehouseProductStorege::update(['nums' => bcsub($storege['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storege['id']]);
@ -180,7 +180,7 @@ class WarehouseProductLogic extends BaseLogic
'admin_id' => $params['admin_id'],
'code' => $params['code'] ?? '',
'unit' => $params['unit'] ?? 0,
'status' => 1,
'status' => 0,
'mark' => $params['mark'] ?? '',
'order_type' => $params['order_type'] ?? '',
];