feat(WarehouseProduct): 重构仓库商品逻辑,优化库存处理,添加商品调拨功能

This commit is contained in:
mkm 2024-08-15 21:24:54 +08:00
parent ae2dcb759e
commit 2ce567684f
3 changed files with 67 additions and 14 deletions

View File

@ -38,10 +38,22 @@ class WarehouseProductController extends BaseAdminController
*/ */
public function add() public function add()
{ {
$params = (new WarehouseProductValidate())->post()->goCheck('add'); $params = $this->request->post();
$params['admin_id']=$this->adminId;
$params['store_id']=0; foreach($params['product_arr'] as $k=>$v){
$result = WarehouseProductLogic::add($params); $data['admin_id']=$this->adminId;
$data['store_id']=0;
$data['supplier_id']=$params['supplier_id'];
$data['warehouse_id']=$params['warehouse_id'];
$data['code']=$params['code'];
$data['product_id']=$v['product_id'];
$data['nums']=$v['nums'];
$data['purchase']=$v['purchase'];
$data['total_price']=$v['total_price'];
$data['financial_pm']=1;
WarehouseProductLogic::add($data);
}
if (WarehouseProductLogic::hasError()) { if (WarehouseProductLogic::hasError()) {
return $this->fail(WarehouseProductLogic::getError()); return $this->fail(WarehouseProductLogic::getError());
}else{ }else{

View File

@ -11,13 +11,14 @@ use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\warehouse\Warehouse; use app\common\model\warehouse\Warehouse;
use app\common\lists\ListsSortInterface; use app\common\lists\ListsSortInterface;
use app\common\lists\ListsExcelInterface;
/** /**
* 仓库商品存储列表 * 仓库商品存储列表
* Class WarehouseProductStoregeLists * Class WarehouseProductStoregeLists
* @package app\admin\listswarehouse_product_storege * @package app\admin\listswarehouse_product_storege
*/ */
class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSearchInterface,ListsSortInterface class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface, ListsExcelInterface
{ {
public $ids; public $ids;
public $store_name; public $store_name;
@ -31,7 +32,7 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['warehouse_id','product_id'], '=' => ['warehouse_id', 'product_id'],
]; ];
} }
/** /**
@ -49,7 +50,7 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
*/ */
public function setDefaultOrder(): array public function setDefaultOrder(): array
{ {
return [ 'id' => 'desc','nums' => 'desc',]; return ['id' => 'desc', 'nums' => 'desc',];
} }
/** /**
@ -101,6 +102,11 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
$item->rose = $find->rose; $item->rose = $find->rose;
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name'); $item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name');
}else{
$item->store_name = '';
$item->cate_name = '';
$item->unit_name = '';
$item->store_info = '';
} }
$item['stock'] = $item['nums']; $item['stock'] = $item['nums'];
return $item; return $item;
@ -127,4 +133,37 @@ class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSe
return WarehouseProductStorege::where($this->searchWhere)->count(); return WarehouseProductStorege::where($this->searchWhere)->count();
} }
} }
/**
* @notes 导出文件名
* @return string
* @author 乔峰
* @date 2022/11/24 16:17
*/
public function setFileName(): string
{
return '仓库商品列表';
}
/**
* @notes 导出字段
* @return string[]
* @author 乔峰
* @date 2022/11/24 16:17
*/
public function setExcelFields(): array
{
$data = [
'store_name' => '商品名称',
'cate_name' => '分类',
'unit_name' => '单位',
'store_info' => '规格',
'nums' => '数量',
];
return $data;
}
} }

View File

@ -34,7 +34,7 @@ class WarehouseProductLogic extends BaseLogic
public static function add(array $params) public static function add(array $params)
{ {
// Db::startTrans(); // Db::startTrans();
// try { try {
$before_nums = 0; $before_nums = 0;
$after_nums = 0; $after_nums = 0;
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find(); $storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
@ -51,6 +51,7 @@ class WarehouseProductLogic extends BaseLogic
} }
$before_nums = $storege['nums']; $before_nums = $storege['nums'];
} else { } else {
$after_nums=$params['nums'];
WarehouseProductStorege::create([ WarehouseProductStorege::create([
'warehouse_id' => $params['warehouse_id'], 'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'], 'product_id' => $params['product_id'],
@ -91,12 +92,13 @@ class WarehouseProductLogic extends BaseLogic
// self::enter($res['id'], $params['financial_pm']); // self::enter($res['id'], $params['financial_pm']);
// Db::commit(); // Db::commit();
return $res; return $res;
// } catch (\Exception $e) { } catch (\Throwable $e) {
// Db::rollback(); throw new BusinessException($e->getMessage());
// Log::error($e->getMessage().',file:'.$e->getFile().',line:'.$e->getLine()); // Db::rollback();
// self::setError($e->getMessage()); // Log::error($e->getMessage().',file:'.$e->getFile().',line:'.$e->getLine());
// return false; // self::setError($e->getMessage());
// } // return false;
}
} }