feat: 添加了仓库产品确认操作

This commit is contained in:
mkm 2024-08-01 13:59:30 +08:00
parent a441b94e94
commit 75a2338337
11 changed files with 530 additions and 24 deletions

View File

@ -99,15 +99,16 @@ class StoreProductController extends BaseAdminController
$product_arr = $this->request->post('product_arr');
$store_arr = $this->request->post('store_arr');
$stock_type = $this->request->post('stock_type',1);
$warehouse_id = $this->request->post('warehouse_id');
if (count($store_arr) == 1) {
$store_id = $store_arr[0];
foreach ($product_arr as $key => $arr) {
Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId]);
Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId,'warehouse_id'=>$warehouse_id]);
}
} else {
foreach ($product_arr as $key => $arr) {
foreach ($store_arr as $k => $store_id) {
Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId]);
Redis::send('store-storage', ['product_arr' => $arr, 'store_id' => $store_id,'stock_type'=>$stock_type, 'admin_id' => $this->adminId,'warehouse_id'=>$warehouse_id]);
}
}
}

View File

@ -7,7 +7,7 @@ use app\admin\controller\BaseAdminController;
use app\admin\lists\warehouse_product\WarehouseProductLists;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\admin\validate\warehouse_product\WarehouseProductValidate;
use app\common\model\warehouse_product\WarehouseProduct;
/**
* 商品仓储信息控制器
@ -39,6 +39,7 @@ class WarehouseProductController extends BaseAdminController
public function add()
{
$params = (new WarehouseProductValidate())->post()->goCheck('add');
$params['admin_id']=$this->adminId;
$result = WarehouseProductLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
@ -56,6 +57,7 @@ class WarehouseProductController extends BaseAdminController
public function edit()
{
$params = (new WarehouseProductValidate())->post()->goCheck('edit');
$params['admin_id']=$this->adminId;
$result = WarehouseProductLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
@ -91,5 +93,16 @@ class WarehouseProductController extends BaseAdminController
return $this->data($result);
}
/**
* 确认操作
*/
public function enter(){
$id=$this->request->post('id');
$result = WarehouseProductLogic::enter($id);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(WarehouseProductLogic::getError());
return $this->success($result);
}
}

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\warehouse_product_storege;
use app\admin\controller\BaseAdminController;
use app\admin\lists\warehouse_product_storege\WarehouseProductStoregeLists;
use app\admin\logic\warehouse_product_storege\WarehouseProductStoregeLogic;
use app\admin\validate\warehouse_product_storege\WarehouseProductStoregeValidate;
/**
* 仓库商品存储控制器
* Class WarehouseProductStoregeController
* @package app\admin\controller\warehouse_product_storege
*/
class WarehouseProductStoregeController extends BaseAdminController
{
/**
* @notes 获取仓库商品存储列表
* @return \think\response\Json
* @author admin
* @date 2024/08/01 10:22
*/
public function lists()
{
return $this->dataLists(new WarehouseProductStoregeLists());
}
// /**
// * @notes 添加仓库商品存储
// * @return \think\response\Json
// * @author admin
// * @date 2024/08/01 10:22
// */
// public function add()
// {
// $params = (new WarehouseProductStoregeValidate())->post()->goCheck('add');
// $result = WarehouseProductStoregeLogic::add($params);
// if (true === $result) {
// return $this->success('添加成功', [], 1, 1);
// }
// return $this->fail(WarehouseProductStoregeLogic::getError());
// }
// /**
// * @notes 编辑仓库商品存储
// * @return \think\response\Json
// * @author admin
// * @date 2024/08/01 10:22
// */
// public function edit()
// {
// $params = (new WarehouseProductStoregeValidate())->post()->goCheck('edit');
// $result = WarehouseProductStoregeLogic::edit($params);
// if (true === $result) {
// return $this->success('编辑成功', [], 1, 1);
// }
// return $this->fail(WarehouseProductStoregeLogic::getError());
// }
// /**
// * @notes 删除仓库商品存储
// * @return \think\response\Json
// * @author admin
// * @date 2024/08/01 10:22
// */
// public function delete()
// {
// $params = (new WarehouseProductStoregeValidate())->post()->goCheck('delete');
// WarehouseProductStoregeLogic::delete($params);
// return $this->success('删除成功', [], 1, 1);
// }
// /**
// * @notes 获取仓库商品存储详情
// * @return \think\response\Json
// * @author admin
// * @date 2024/08/01 10:22
// */
// public function detail()
// {
// $params = (new WarehouseProductStoregeValidate())->goCheck('detail');
// $result = WarehouseProductStoregeLogic::detail($params);
// return $this->data($result);
// }
}

View File

@ -6,7 +6,8 @@ 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;
/**
* 商品仓储信息列表
@ -43,10 +44,33 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
public function lists(): array
{
return WarehouseProduct::where($this->searchWhere)
->field(['id', 'warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'total_price', 'status'])
->field(['id', 'admin_id','warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'total_price', 'manufacture','expiration_date','status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->select()->each(function ($item){
if($item->financial_pm==0){
$item->financial_pm_name='出库';
}else{
$item->financial_pm_name='入库';
}
if($item->status==0){
$item->status_name='未确认';
}else{
$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){
$item->store_name=StoreProduct::where('id',$item->product_id)->value('store_name');
}else{
$item->store_name='';
}
$item->expiration_date=$item->expiration_date?date('Y-m-d',$item->expiration_date):'';
$item->manufacture=$item->manufacture?date('Y-m-d',$item->manufacture):'';
})
->toArray();
}

View File

@ -0,0 +1,85 @@
<?php
namespace app\admin\lists\warehouse_product_storege;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use app\common\lists\ListsSearchInterface;
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;
/**
* 仓库商品存储列表
* Class WarehouseProductStoregeLists
* @package app\admin\listswarehouse_product_storege
*/
class WarehouseProductStoregeLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author admin
* @date 2024/08/01 10:22
*/
public function setSearch(): array
{
return [
// '=' => ['warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status'],
];
}
/**
* @notes 获取仓库商品存储列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author admin
* @date 2024/08/01 10:22
*/
public function lists(): array
{
return WarehouseProductStorege::where($this->searchWhere)
->field(['id', 'warehouse_id', 'product_id', 'nums', 'price', 'total_price', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function ($item){
$item->warehouse_name = Warehouse::where('id',$item->warehouse_id)->value('name');
$find= StoreProduct::where('id',$item->product_id)->find();
if($find){
$item->store_name = $find->store_name;
$item->image = $find->image;
$item->bar_code = $find->bar_code;
$item->price = $find->price;
$item->cost = $find->cost;
$item->purchase = $find->purchase;
$item->store_info = $find->store_info;
$item->rose = $find->rose;
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
$item['cate_name'] = StoreCategory::where('id', $find['cate_id'])->value('name');
}
$item['stock']=$item['nums'];
return $item;
})
->toArray();
}
/**
* @notes 获取仓库商品存储数量
* @return int
* @author admin
* @date 2024/08/01 10:22
*/
public function count(): int
{
return WarehouseProductStorege::where($this->searchWhere)->count();
}
}

View File

@ -5,6 +5,8 @@ namespace app\admin\logic\warehouse_product;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\logic\BaseLogic;
use app\common\model\store_product\StoreProduct;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use think\facade\Db;
@ -28,17 +30,22 @@ class WarehouseProductLogic extends BaseLogic
{
Db::startTrans();
try {
WarehouseProduct::create([
$res=WarehouseProduct::create([
'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'],
'financial_pm' => $params['financial_pm'],
'batch' => $params['batch'],
'nums' => $params['nums'],
'price' => $params['price'],
'total_price' => $params['total_price'],
'status' => $params['status']
'price' => $params['price']??'',
'total_price' => $params['total_price']??'',
'admin_id' => $params['admin_id'],
'code' => $params['code']??'',
'manufacture' => $params['manufacture']?strtotime($params['manufacture']):'',
'expiration_date' =>$params['expiration_date']?strtotime($params['expiration_date']):'',
'status' => $params['status']??0,
'mark' => $params['mark']??'',
]);
self::enter($res['id']);
Db::commit();
return true;
} catch (\Exception $e) {
@ -67,8 +74,11 @@ class WarehouseProductLogic extends BaseLogic
'batch' => $params['batch'],
'nums' => $params['nums'],
'price' => $params['price'],
'admin_id' => $params['admin_id'],
'total_price' => $params['total_price'],
'status' => $params['status']
'code' => $params['code'],
'manufacture' => strtotime($params['manufacture']),
'expiration_date' => strtotime($params['expiration_date']),
]);
Db::commit();
@ -79,6 +89,40 @@ class WarehouseProductLogic extends BaseLogic
return false;
}
}
/**
* @notes 确认商品仓储信息
* @param array $params
* @author admin
* @date 2024/07/31 16:55
*/
public static function enter($id)
{
Db::startTrans();
try {
$find=WarehouseProduct::where('id',$id)->find();
$find->status=1;
$find->save();
StoreProduct::where('id',$find['product_id'])->inc('stock',$find['nums'])->update();
$storege=WarehouseProductStorege::where('warehouse_id',$find['warehouse_id'])->where('product_id',$find['product_id'])->find();
if($storege){
$storege->nums=$storege->nums+$find['nums'];
$storege->save();
}else{
WarehouseProductStorege::create([
'warehouse_id' => $find['warehouse_id'],
'product_id' => $find['product_id'],
'nums' => $find['nums'],
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
@ -103,6 +147,12 @@ class WarehouseProductLogic extends BaseLogic
*/
public static function detail($params): array
{
return WarehouseProduct::findOrEmpty($params['id'])->toArray();
$data= WarehouseProduct::findOrEmpty($params['id'])->toArray();
if($data){
$data['manufacture']=date('Y-m-d',$data['manufacture']);
$data['expiration_date']=date('Y-m-d',$data['expiration_date']);
}
return $data;
}
}

View File

@ -0,0 +1,104 @@
<?php
namespace app\admin\logic\warehouse_product_storege;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 仓库商品存储逻辑
* Class WarehouseProductStoregeLogic
* @package app\admin\logic\warehouse_product_storege
*/
class WarehouseProductStoregeLogic extends BaseLogic
{
/**
* @notes 添加仓库商品存储
* @param array $params
* @return bool
* @author admin
* @date 2024/08/01 10:22
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
WarehouseProductStorege::create([
'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'price' => $params['price'],
'total_price' => $params['total_price'],
'status' => $params['status']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑仓库商品存储
* @param array $params
* @return bool
* @author admin
* @date 2024/08/01 10:22
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
WarehouseProductStorege::where('id', $params['id'])->update([
'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'price' => $params['price'],
'total_price' => $params['total_price'],
'status' => $params['status']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除仓库商品存储
* @param array $params
* @return bool
* @author admin
* @date 2024/08/01 10:22
*/
public static function delete(array $params): bool
{
return WarehouseProductStorege::destroy($params['id']);
}
/**
* @notes 获取仓库商品存储详情
* @param $params
* @return array
* @author admin
* @date 2024/08/01 10:22
*/
public static function detail($params): array
{
return WarehouseProductStorege::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -56,7 +56,7 @@ class WarehouseProductValidate extends BaseValidate
*/
public function sceneAdd()
{
return $this->only(['warehouse_id','product_id','financial_pm','batch','nums','price','total_price','status']);
return $this->only(['warehouse_id','product_id','financial_pm','batch','nums','price','total_price']);
}
@ -68,7 +68,7 @@ class WarehouseProductValidate extends BaseValidate
*/
public function sceneEdit()
{
return $this->only(['id','warehouse_id','product_id','financial_pm','batch','nums','price','total_price','status']);
return $this->only(['id','warehouse_id','product_id','financial_pm','batch','nums','price','total_price']);
}

View File

@ -0,0 +1,94 @@
<?php
namespace app\admin\validate\warehouse_product_storege;
use app\common\validate\BaseValidate;
/**
* 仓库商品存储验证器
* Class WarehouseProductStoregeValidate
* @package app\admin\validate\warehouse_product_storege
*/
class WarehouseProductStoregeValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'warehouse_id' => 'require',
'product_id' => 'require',
'nums' => 'require',
'price' => 'require',
'total_price' => 'require',
'status' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'warehouse_id' => '仓库ID',
'product_id' => '商品ID',
'nums' => '数量',
'price' => '价格',
'total_price' => '价格',
'status' => '状态',
];
/**
* @notes 添加场景
* @return WarehouseProductStoregeValidate
* @author admin
* @date 2024/08/01 10:22
*/
public function sceneAdd()
{
return $this->only(['warehouse_id','product_id','nums','price','total_price','status']);
}
/**
* @notes 编辑场景
* @return WarehouseProductStoregeValidate
* @author admin
* @date 2024/08/01 10:22
*/
public function sceneEdit()
{
return $this->only(['id','warehouse_id','product_id','nums','price','total_price','status']);
}
/**
* @notes 删除场景
* @return WarehouseProductStoregeValidate
* @author admin
* @date 2024/08/01 10:22
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return WarehouseProductStoregeValidate
* @author admin
* @date 2024/08/01 10:22
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\warehouse_product_storege;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 仓库商品存储
* Class WarehouseProductStorege
* @package app\common\model\warehouse_product_storege
*/
class WarehouseProductStorege extends BaseModel
{
use SoftDelete;
protected $name = 'warehouse_product_storege';
protected $deleteTime = 'delete_time';
}

View File

@ -3,12 +3,14 @@
namespace app\queue\redis;
use app\admin\logic\store_product\StoreProductLogic;
use app\admin\logic\warehouse_product\WarehouseProductLogic;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_branch_product_attr_value\StoreBranchProductAttrValue;
use app\common\model\store_branch_product_exchange\StoreBranchProductExchange;
use app\common\model\store_product\StoreProduct;
use app\common\model\store_product_attr_value\StoreProductAttrValue;
use app\common\model\system_store_storage\SystemStoreStorage;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use Webman\RedisQueue\Consumer;
use support\Log;
use think\facade\Db;
@ -31,6 +33,7 @@ class StoreStorageSend implements Consumer
$store_id = $data['store_id'];
$stock_type = $data['stock_type'];
$admin_id = $data['admin_id'];
$warehouse_id = $data['warehouse_id'];
$find = StoreProduct::where('id', $product_arr['id'])->findOrEmpty()->toArray();
if($stock_type == 1){
$this->ordinary($product_arr,$store_id,$admin_id,$find);
@ -40,7 +43,7 @@ class StoreStorageSend implements Consumer
}
/**普通 */
public function ordinary($product_arr,$store_id,$admin_id,$find){
public function ordinary($product_arr,$store_id,$admin_id,$find,$warehouse_id){
$store_find = StoreBranchProduct::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray();
if ($find && !$store_find) {
$attr_value = StoreProductAttrValue::where('product_id', $product_arr['id'])->findOrEmpty();
@ -82,7 +85,7 @@ class StoreStorageSend implements Consumer
];
StoreBranchProductAttrValue::create($arr);
if ($product_arr['stock'] > 0) {
$this->storage($find, $store_id, $admin_id, $product_arr);
$this->storage($find, $store_id, $admin_id, $product_arr,$warehouse_id);
}
StoreProductLogic::updateGoodsclass($find['cate_id'],$store_id);
Db::commit();
@ -109,7 +112,7 @@ class StoreStorageSend implements Consumer
}
/**兑换 */
public function exchange($product_arr,$store_id,$admin_id,$find){
public function exchange($product_arr,$store_id,$admin_id,$find,$warehouse_id){
$store_find = StoreBranchProductExchange::where(['product_id' => $product_arr['id'], 'store_id' => $store_id])->findOrEmpty()->toArray();
if ($find && !$store_find) {
Db::startTrans();
@ -133,7 +136,7 @@ class StoreStorageSend implements Consumer
];
StoreBranchProductExchange::create($product);
if ($product_arr['stock'] > 0) {
$this->storage($find, $store_id, $admin_id, $product_arr);
$this->storage($find, $store_id, $admin_id, $product_arr,$warehouse_id);
}
// StoreProductLogic::updateGoodsclass($find['cate_id'],$store_id);
Db::commit();
@ -158,7 +161,7 @@ class StoreStorageSend implements Consumer
}
}
}
public function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1)
public function storage($find, $store_id, $admin_id, $product_arr,$stock_type=1,$warehouse_id=0)
{
$storage = [
'product_id' => $product_arr['id'],
@ -167,12 +170,27 @@ class StoreStorageSend implements Consumer
'admin_id' => $admin_id,
'type' => $stock_type,
];
if ($find['stock'] < $product_arr['stock']) {
$storage['status'] = -1;
$storage['mark'] = '库存不足,主库存为:' . $find['stock'];
$data=[
'warehouse_id'=>$warehouse_id,
'product_id' => $product_arr['id'],
'financial_pm' => 0,
'batch' => $product_arr['batch']??1,
'nums' => $product_arr['stock'],
'status' =>1,
'admin_id' =>$admin_id,
];
$warehouse=WarehouseProductStorege::where('warehouse_id',$warehouse_id)->where('product_id',$product_arr['id'])->find();
if ($warehouse) {
if($warehouse['nums']< $product_arr['stock']){
$storage['status'] = -1;
$storage['mark'] = '库存不足,分库存为:' .$warehouse['nums'];
$data['mark'] = '库存不足,分库存为:' .$warehouse['nums'].' 总仓库存为:'.$find['stock'];
}
SystemStoreStorage::create($storage);
WarehouseProductLogic::add($data);
} else {
SystemStoreStorage::create($storage);
WarehouseProductLogic::add($data);
StoreProduct::where('id', $product_arr['id'])->dec('stock', $product_arr['stock'])->update();
}
}