优化商品入库和采购流程
- 修改了商品入库逻辑,支持未在门店的商品直接入库 - 优化了采购报价单操作,包括添加、编辑和查询相关功能 - 调整了仓库商品出库逻辑,支持财务相关操作 - 修复了一些与商品库存相关的逻辑问题
This commit is contained in:
parent
2e4bee3216
commit
4387eef6f1
@ -40,10 +40,8 @@ class PurchaseProductOfferController extends BaseAdminController
|
|||||||
{
|
{
|
||||||
$params = (new PurchaseProductOfferValidate())->post()->goCheck('add');
|
$params = (new PurchaseProductOfferValidate())->post()->goCheck('add');
|
||||||
$result = PurchaseProductOfferLogic::add($params);
|
$result = PurchaseProductOfferLogic::add($params);
|
||||||
if (true === $result) {
|
return $this->success('设置成功', [], 1, 1);
|
||||||
return $this->success('添加成功', [], 1, 1);
|
|
||||||
}
|
|
||||||
return $this->fail(PurchaseProductOfferLogic::getError());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,9 +5,11 @@ namespace app\admin\controller\system_store_storage;
|
|||||||
|
|
||||||
use app\admin\controller\BaseAdminController;
|
use app\admin\controller\BaseAdminController;
|
||||||
use app\admin\lists\system_store_storage\SystemStoreStorageLists;
|
use app\admin\lists\system_store_storage\SystemStoreStorageLists;
|
||||||
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
use app\admin\logic\system_store_storage\SystemStoreStorageLogic;
|
use app\admin\logic\system_store_storage\SystemStoreStorageLogic;
|
||||||
use app\admin\validate\system_store_storage\SystemStoreStorageValidate;
|
use app\admin\validate\system_store_storage\SystemStoreStorageValidate;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\system_store_storage\SystemStoreStorage;
|
use app\common\model\system_store_storage\SystemStoreStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,7 +58,7 @@ class SystemStoreStorageController extends BaseAdminController
|
|||||||
*/
|
*/
|
||||||
public function edit()
|
public function edit()
|
||||||
{
|
{
|
||||||
return $this->fail('暂不支持入库操作');
|
// return $this->fail('暂不支持入库操作');
|
||||||
|
|
||||||
// $params = (new SystemStoreStorageValidate())->post()->goCheck('edit');
|
// $params = (new SystemStoreStorageValidate())->post()->goCheck('edit');
|
||||||
// $params['admin_id']=$this->adminId;
|
// $params['admin_id']=$this->adminId;
|
||||||
@ -69,10 +71,21 @@ class SystemStoreStorageController extends BaseAdminController
|
|||||||
if($id==0){
|
if($id==0){
|
||||||
return $this->fail('参数错误');
|
return $this->fail('参数错误');
|
||||||
}
|
}
|
||||||
$res=SystemStoreStorage::where(['id' => $id])->update(['status'=>1,'staff_id'=>$this->adminId,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]);
|
|
||||||
if($res){
|
|
||||||
$find=SystemStoreStorage::where(['id' => $id])->find();
|
$find=SystemStoreStorage::where(['id' => $id])->find();
|
||||||
StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->inc('stock',$find['nums'])->update();
|
|
||||||
|
if($find){
|
||||||
|
$find->save(['status'=>1,'staff_id'=>$this->adminId,'mark'=>'入库时间:'.date('Y-m-d H:i:s',time())]);
|
||||||
|
$branch_product=StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->find();
|
||||||
|
if($branch_product){
|
||||||
|
$branch_product->save(['stock'=>$branch_product['stock']+$find['nums']]);
|
||||||
|
}else{
|
||||||
|
$storeProduct = StoreProduct::where('id', $find['product_id'])->findOrEmpty();
|
||||||
|
$storeBranchProduct = StoreProductLogic::ordinary(['id' => $find['product_id']], $find['store_id'], $this->adminId, $storeProduct);
|
||||||
|
$storeBranchProduct->stock = $find['nums'];
|
||||||
|
$storeBranchProduct->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return $this->success('操作成功',[]);
|
return $this->success('操作成功',[]);
|
||||||
}
|
}
|
||||||
return $this->fail('操作失败');
|
return $this->fail('操作失败');
|
||||||
|
@ -6,7 +6,7 @@ namespace app\admin\lists\beforehand_order;
|
|||||||
use app\admin\lists\BaseAdminDataLists;
|
use app\admin\lists\BaseAdminDataLists;
|
||||||
use app\common\model\beforehand_order\BeforehandOrder;
|
use app\common\model\beforehand_order\BeforehandOrder;
|
||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
use app\common\model\auth\Admin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预订单表列表
|
* 预订单表列表
|
||||||
@ -43,10 +43,16 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte
|
|||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return BeforehandOrder::where($this->searchWhere)
|
return BeforehandOrder::where($this->searchWhere)
|
||||||
->field(['id','order_id', 'uid','total_num', 'total_price', 'pay_price', 'deduction_price','create_time', 'status', 'mark'])
|
->field(['id','order_id', 'uid','total_num','total_price','admin_id', 'pay_price', 'deduction_price','create_time', 'status', 'mark'])
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()
|
->select()->each(function ($item){
|
||||||
|
if($item->admin_id){
|
||||||
|
$item->admin_name=Admin::where(['id'=>$item->admin_id])->value('name');
|
||||||
|
}else{
|
||||||
|
$item->admin_name='';
|
||||||
|
}
|
||||||
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ use app\common\model\beforehand_order\BeforehandOrder;
|
|||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
use app\common\model\store_product\StoreProduct;
|
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\supplier\Supplier;
|
||||||
use app\common\model\warehouse_product\WarehouseProduct;
|
use app\common\model\warehouse_product\WarehouseProduct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,6 +60,11 @@ class BeforehandOrderThreeLists extends BaseAdminDataLists implements ListsSearc
|
|||||||
}else{
|
}else{
|
||||||
$item['unit_name']=StoreProductUnit::where('id',$item['unit'])->value('name');
|
$item['unit_name']=StoreProductUnit::where('id',$item['unit'])->value('name');
|
||||||
}
|
}
|
||||||
|
if($item['supplier_id']){
|
||||||
|
$item['supplier_name']=Supplier::where('id',$item['supplier_id'])->value('mer_name');
|
||||||
|
}else{
|
||||||
|
$item['supplier_name']='';
|
||||||
|
}
|
||||||
return $item;
|
return $item;
|
||||||
})
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
|
@ -8,6 +8,7 @@ use app\common\model\beforehand_order\BeforehandOrder;
|
|||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
use app\common\model\store_product\StoreProduct;
|
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\supplier\Supplier;
|
||||||
use app\common\model\warehouse_product\WarehouseProduct;
|
use app\common\model\warehouse_product\WarehouseProduct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,6 +60,11 @@ class BeforehandOrderTwoLists extends BaseAdminDataLists implements ListsSearchI
|
|||||||
}else{
|
}else{
|
||||||
$item['unit_name']=StoreProductUnit::where('id',$item['unit'])->value('name');
|
$item['unit_name']=StoreProductUnit::where('id',$item['unit'])->value('name');
|
||||||
}
|
}
|
||||||
|
if($item['supplier_id']){
|
||||||
|
$item['supplier_name']=Supplier::where('id',$item['supplier_id'])->value('mer_name');
|
||||||
|
}else{
|
||||||
|
$item['supplier_name']='';
|
||||||
|
}
|
||||||
return $item;
|
return $item;
|
||||||
})
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
|
@ -6,6 +6,7 @@ namespace app\admin\lists\beforehand_order_cart_info;
|
|||||||
use app\admin\lists\BaseAdminDataLists;
|
use app\admin\lists\BaseAdminDataLists;
|
||||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||||
|
|
||||||
@ -53,6 +54,14 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe
|
|||||||
$item['store_name']=$find['store_name'];
|
$item['store_name']=$find['store_name'];
|
||||||
$item['image']=$find['image'];
|
$item['image']=$find['image'];
|
||||||
$item['unit']=$find['unit'];
|
$item['unit']=$find['unit'];
|
||||||
|
if($item->bhoid){
|
||||||
|
$status=PurchaseProductOffer::where('order_id',$item->bhoid)->where('product_id',$item->product_id)->value('status');
|
||||||
|
if($status==1){
|
||||||
|
$item->status_name='已完成';
|
||||||
|
}else{
|
||||||
|
$item->status_name='采购中';
|
||||||
|
}
|
||||||
|
}
|
||||||
return $item;
|
return $item;
|
||||||
})
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
|
@ -157,19 +157,15 @@ class BeforehandOrderLogic extends BaseLogic
|
|||||||
'nums' => $arr['cart_num'],
|
'nums' => $arr['cart_num'],
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'admin_id' => $admin_id,
|
'admin_id' => $admin_id,
|
||||||
|
'total_price' => $arr['total_price'],
|
||||||
|
'purchase' => $arr['price'],
|
||||||
|
'oid' => $res['id'],
|
||||||
|
'code' => $res['code'],
|
||||||
];
|
];
|
||||||
$storeProduct = StoreProduct::where('id', $arr['product_id'])->findOrEmpty()->toArray();
|
WarehouseProductLogic::setOutbound($data);
|
||||||
if ($arr['cart_num'] == 0) {
|
}
|
||||||
StoreProductLogic::ordinary($arr, $store_id, $admin_id, $storeProduct);
|
|
||||||
} else {
|
|
||||||
$data['total_price'] =$arr['total_price'];
|
|
||||||
$data['purchase'] = $storeProduct['purchase'];
|
|
||||||
$data['oid'] = $res['id'];
|
|
||||||
WarehouseProductLogic::add($data);
|
|
||||||
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
||||||
}
|
|
||||||
}
|
|
||||||
BeforehandOrder::update(['outbound_id' => $res['id']], ['id' => $params['bhoid']]);
|
BeforehandOrder::update(['outbound_id' => $res['id']], ['id' => $params['bhoid']]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
|
@ -5,6 +5,7 @@ namespace app\admin\logic\purchase_product_offer;
|
|||||||
|
|
||||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
|
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ class PurchaseProductOfferLogic extends BaseLogic
|
|||||||
'status' => 0,
|
'status' => 0,
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
BeforehandOrderCartInfo::where(['bhoid'=>$params['order_id'],'product_id'=>$params['product_id']])->update(['is_buyer'=>1]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -99,12 +100,20 @@ class PurchaseProductOfferLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
PurchaseProductOffer::update([
|
$offer=PurchaseProductOffer::where(['id'=>$params['id']])->find();
|
||||||
|
$offer->save([
|
||||||
'buyer_nums' => $params['buyer_nums'],
|
'buyer_nums' => $params['buyer_nums'],
|
||||||
'supplier_id' => $params['supplier_id'],
|
'supplier_id' => $params['supplier_id'],
|
||||||
'price' => $params['price'],
|
'price' => $params['purchase'],
|
||||||
'total_price' => $params['total_price'],
|
'total_price' => $params['total_price'],
|
||||||
],['id'=>$params['id']]);
|
]);
|
||||||
|
$find=BeforehandOrderCartInfo::where(['bhoid'=>$params['bhoid'],'product_id'=>$offer['product_id']])->find();
|
||||||
|
if($find){
|
||||||
|
$find->purchase=$params['purchase'];
|
||||||
|
$find->total_price=bcmul($find['cart_num'],$params['price'],2);
|
||||||
|
$find->price=$params['price'];
|
||||||
|
$find->save();
|
||||||
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
@ -141,6 +141,59 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置出库商品
|
||||||
|
*/
|
||||||
|
public static function setOutbound(array $params, $type = 1)
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$after_nums = 0;
|
||||||
|
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
|
||||||
|
if ($storege) {
|
||||||
|
SystemStoreStorage::create([
|
||||||
|
'store_id' => $params['store_id'],
|
||||||
|
'admin_id' => $params['admin_id'],
|
||||||
|
'staff_id' => 0,
|
||||||
|
'type' => 1,
|
||||||
|
'product_id' => $params['product_id'],
|
||||||
|
'nums' => $params['nums'],
|
||||||
|
'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']]);
|
||||||
|
} else {
|
||||||
|
throw new BusinessException('仓库商品不存在');
|
||||||
|
}
|
||||||
|
|
||||||
|
$batch_count = WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm'], 'store_id' => $params['store_id']])->count();
|
||||||
|
$data = [
|
||||||
|
'warehouse_id' => $params['warehouse_id'],
|
||||||
|
'supplier_id' => $params['supplier_id'] ?? 0,
|
||||||
|
'oid' => $params['oid'] ?? 0,
|
||||||
|
'store_id' => $params['store_id'] ?? 0,
|
||||||
|
'product_id' => $params['product_id'],
|
||||||
|
'financial_pm' => $params['financial_pm'],
|
||||||
|
'batch' => $batch_count + 1,
|
||||||
|
'nums' => $params['nums'],
|
||||||
|
'before_nums' => $storege['nums'],
|
||||||
|
'after_nums' => $after_nums,
|
||||||
|
'purchase' => $params['purchase'] ?? '',
|
||||||
|
'total_price' => $params['total_price'] ?? '',
|
||||||
|
'admin_id' => $params['admin_id'],
|
||||||
|
'code' => $params['code'] ?? '',
|
||||||
|
'status' => 1,
|
||||||
|
'mark' => $params['mark'] ?? '',
|
||||||
|
];
|
||||||
|
$res = WarehouseProduct::create($data);
|
||||||
|
Db::commit();
|
||||||
|
return $res;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
Db::rollback();
|
||||||
|
throw new BusinessException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 编辑商品仓储信息
|
* @notes 编辑商品仓储信息
|
||||||
@ -241,7 +294,8 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
* @param $id
|
* @param $id
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function settlement($id){
|
public static function settlement($id)
|
||||||
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
$find = WarehouseProduct::where(['id' => $id, 'financial_pm' => 1, 'is_pay' => 0])->find();
|
$find = WarehouseProduct::where(['id' => $id, 'financial_pm' => 1, 'is_pay' => 0])->find();
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
namespace app\api\controller\system_store_storage;
|
namespace app\api\controller\system_store_storage;
|
||||||
|
|
||||||
|
use app\admin\logic\store_product\StoreProductLogic;
|
||||||
use app\api\controller\BaseApiController;
|
use app\api\controller\BaseApiController;
|
||||||
use app\api\lists\system_store_storage\SystemStoreStorageLists;
|
use app\api\lists\system_store_storage\SystemStoreStorageLists;
|
||||||
use app\api\lists\system_store_storage\SystemStoreStorageGroupLists;
|
use app\api\lists\system_store_storage\SystemStoreStorageGroupLists;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\system_store\SystemStoreStaff;
|
use app\common\model\system_store\SystemStoreStaff;
|
||||||
use app\common\model\system_store_storage\SystemStoreStorage;
|
use app\common\model\system_store_storage\SystemStoreStorage;
|
||||||
|
|
||||||
@ -51,13 +52,26 @@ class SystemStoreStorageController extends BaseApiController
|
|||||||
/**
|
/**
|
||||||
* @notes 门店入库
|
* @notes 门店入库
|
||||||
*/
|
*/
|
||||||
public function warehousing_add() {
|
public function warehousing_add()
|
||||||
|
{
|
||||||
$params = $this->request->post();
|
$params = $this->request->post();
|
||||||
$find = SystemStoreStorage::where('id', $params['id'])->find();
|
$find = SystemStoreStorage::where('id', $params['id'])->find();
|
||||||
if ($find) {
|
if ($find) {
|
||||||
|
$id = SystemStoreStaff::where('uid', $this->userId)->value('id');
|
||||||
|
$find->staff_id = $id;
|
||||||
|
$find->mark = '入库时间:' . date('Y-m-d H:i:s');
|
||||||
$find->status = 1;
|
$find->status = 1;
|
||||||
$find->save();
|
$find->save();
|
||||||
StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->inc('stock',$find['nums'])->update();
|
|
||||||
|
$branch_product=StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->find();
|
||||||
|
if($branch_product){
|
||||||
|
$branch_product->save(['stock'=>$branch_product['stock']+$find['nums']]);
|
||||||
|
}else{
|
||||||
|
$storeProduct = StoreProduct::where('id', $find['product_id'])->findOrEmpty();
|
||||||
|
$storeBranchProduct = StoreProductLogic::ordinary(['id' => $find['product_id']], $find['store_id'], 0, $storeProduct);
|
||||||
|
$storeBranchProduct->stock = $find['nums'];
|
||||||
|
$storeBranchProduct->save();
|
||||||
|
}
|
||||||
return $this->success('操作成功');
|
return $this->success('操作成功');
|
||||||
}
|
}
|
||||||
return $this->fail('操作失败');
|
return $this->fail('操作失败');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user