优化商品入库和采购流程

- 修改了商品入库逻辑,支持未在门店的商品直接入库
- 优化了采购报价单操作,包括添加、编辑和查询相关功能
- 调整了仓库商品出库逻辑,支持财务相关操作
- 修复了一些与商品库存相关的逻辑问题
This commit is contained in:
mkm 2024-10-07 13:30:14 +08:00
parent 2e4bee3216
commit 4387eef6f1
10 changed files with 219 additions and 108 deletions

View File

@ -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());
} }

View File

@ -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())]); $find=SystemStoreStorage::where(['id' => $id])->find();
if($res){
$find=SystemStoreStorage::where(['id' => $id])->find(); if($find){
StoreBranchProduct::where(['product_id'=>$find['product_id'],'store_id'=>$find['store_id']])->inc('stock',$find['nums'])->update(); $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('操作失败');

View File

@ -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();
} }

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -35,9 +35,9 @@ class BeforehandOrderLogic extends BaseLogic
Db::startTrans(); Db::startTrans();
try { try {
$datas = []; $datas = [];
$total_num=0; $total_num = 0;
$total_price=0; $total_price = 0;
$uid=$params['uid'] ?? 0; $uid = $params['uid'] ?? 0;
foreach ($params['product_arr'] as $k => $v) { foreach ($params['product_arr'] as $k => $v) {
$datas[$k]['product_id'] = $v['product_id']; $datas[$k]['product_id'] = $v['product_id'];
$datas[$k]['uid'] = $uid; $datas[$k]['uid'] = $uid;
@ -45,13 +45,13 @@ class BeforehandOrderLogic extends BaseLogic
$datas[$k]['price'] = $v['purchase']; $datas[$k]['price'] = $v['purchase'];
$datas[$k]['total_price'] = $v['total_price']; $datas[$k]['total_price'] = $v['total_price'];
$datas[$k]['create_time'] = time(); $datas[$k]['create_time'] = time();
$datas[$k]['update_time'] =time(); $datas[$k]['update_time'] = time();
$total_num += $v['nums']; $total_num += $v['nums'];
$total_price += $v['total_price']; $total_price += $v['total_price'];
} }
$order = BeforehandOrder::create([ $order = BeforehandOrder::create([
'order_id' => getNewOrderId('YG'), 'order_id' => getNewOrderId('YG'),
'admin_id' => $params['admin_id']??0, 'admin_id' => $params['admin_id'] ?? 0,
'uid' => $uid, 'uid' => $uid,
'total_num' => $total_num, 'total_num' => $total_num,
'total_price' => $total_price, 'total_price' => $total_price,
@ -59,7 +59,7 @@ class BeforehandOrderLogic extends BaseLogic
'pay_type' => 0, 'pay_type' => 0,
'deduction_price' => 0, 'deduction_price' => 0,
'paid' => 0, 'paid' => 0,
'mark' => $params['mark']??'' 'mark' => $params['mark'] ?? ''
]); ]);
foreach ($datas as $k => $v) { foreach ($datas as $k => $v) {
$datas[$k]['bhoid'] = $order['id']; $datas[$k]['bhoid'] = $order['id'];
@ -119,58 +119,54 @@ class BeforehandOrderLogic extends BaseLogic
*/ */
public static function createOutboundOrder(array $params): bool public static function createOutboundOrder(array $params): bool
{ {
$warehouse_id= $params['warehouse_id']; $warehouse_id = $params['warehouse_id'];
$store_id= $params['store_id']; $store_id = $params['store_id'];
$admin_id= $params['admin_id']; $admin_id = $params['admin_id'];
$delivery_time= $params['delivery_time']; $delivery_time = $params['delivery_time'];
$mark= $params['remark']??''; $mark = $params['remark'] ?? '';
$order=BeforehandOrder::where('id', $params['bhoid'])->find(); $order = BeforehandOrder::where('id', $params['bhoid'])->find();
if(!$order){ if (!$order) {
throw new BusinessException('该订单不存在'); throw new BusinessException('该订单不存在');
} }
if($order['outbound_id']>0){ if ($order['outbound_id'] > 0) {
throw new BusinessException('该订单已创建出库单'); throw new BusinessException('该订单已创建出库单');
} }
$info=BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select(); $info = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select();
Db::startTrans(); Db::startTrans();
try { try {
$arr = [ $arr = [
'oid' => 0, 'oid' => 0,
'warehouse_id' => $warehouse_id,
'store_id' => $store_id,
'supplier_id' => 0,
'code' => getNewOrderId('CK'),
'admin_id' => $admin_id,
'financial_pm' => 0,
'batch' => 0,
'mark' => $mark,
];
$arr['delivery_time'] = strtotime($delivery_time);
$res = WarehouseOrder::create($arr);
foreach ($info as $key => $arr) {
$data = [
'warehouse_id' => $warehouse_id, 'warehouse_id' => $warehouse_id,
'product_id' => $arr['product_id'],
'store_id' => $store_id, 'store_id' => $store_id,
'supplier_id' => 0,
'code' => getNewOrderId('CK'),
'admin_id' => $admin_id,
'financial_pm' => 0, 'financial_pm' => 0,
'batch' => 0, 'batch' => 1,
'mark' => $mark, 'nums' => $arr['cart_num'],
'status' => 1,
'admin_id' => $admin_id,
'total_price' => $arr['total_price'],
'purchase' => $arr['price'],
'oid' => $res['id'],
'code' => $res['code'],
]; ];
$arr['delivery_time'] = strtotime($delivery_time); WarehouseProductLogic::setOutbound($data);
$res = WarehouseOrder::create($arr); }
foreach ($info as $key => $arr) { $finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
$data = [ WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
'warehouse_id' => $warehouse_id, BeforehandOrder::update(['outbound_id' => $res['id']], ['id' => $params['bhoid']]);
'product_id' => $arr['product_id'],
'store_id' => $store_id,
'financial_pm' => 0,
'batch' => 1,
'nums' => $arr['cart_num'],
'status' => 1,
'admin_id' => $admin_id,
];
$storeProduct = StoreProduct::where('id', $arr['product_id'])->findOrEmpty()->toArray();
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();
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
}
}
BeforehandOrder::update(['outbound_id'=>$res['id']],['id'=>$params['bhoid']]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Throwable $e) { } catch (\Throwable $e) {

View File

@ -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) {

View File

@ -52,7 +52,7 @@ class WarehouseProductLogic extends BaseLogic
// if ($after_nums < 0) { // if ($after_nums < 0) {
// throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']); // throw new BusinessException('库存不足,warehouse_id:'.$params['warehouse_id'].'product_id:'.$params['product_id']);
// } // }
WarehouseProductStorege::update(['nums'=>$after_nums, 'total_price' => $total_price],['id'=> $storege['id']]); WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storege['id']]);
//门店加库存 //门店加库存
$storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find(); $storeBranchProduct = StoreBranchProduct::where('product_id', $params['product_id'])->where('store_id', $params['store_id'])->find();
@ -74,7 +74,7 @@ class WarehouseProductLogic extends BaseLogic
throw new BusinessException('商品不存在'); throw new BusinessException('商品不存在');
} }
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2); $total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price],['id'=>$storege['id']]); WarehouseProductStorege::update(['nums' => $after_nums, 'total_price' => $total_price], ['id' => $storege['id']]);
} }
} }
$before_nums = $storege['nums']; $before_nums = $storege['nums'];
@ -85,16 +85,16 @@ class WarehouseProductLogic extends BaseLogic
throw new BusinessException('商品不存在'); throw new BusinessException('商品不存在');
} }
$total_price = bcmul($after_nums, $storeProduct['purchase'], 2); $total_price = bcmul($after_nums, $storeProduct['purchase'], 2);
$data=[ $data = [
'warehouse_id' => $params['warehouse_id'], 'warehouse_id' => $params['warehouse_id'],
'product_id' => $params['product_id'], 'product_id' => $params['product_id'],
'nums' => $params['nums'], 'nums' => $params['nums'],
'total_price'=>$total_price 'total_price' => $total_price
]; ];
if($params['financial_pm']==0){ if ($params['financial_pm'] == 0) {
$data['nums']=-$params['nums']; $data['nums'] = -$params['nums'];
} }
$storege=WarehouseProductStorege::create($data); $storege = WarehouseProductStorege::create($data);
} }
$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(); $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 = [ $data = [
@ -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 编辑商品仓储信息
@ -156,28 +209,28 @@ class WarehouseProductLogic extends BaseLogic
try { try {
$before_nums = 0; $before_nums = 0;
$after_nums = 0; $after_nums = 0;
$find=WarehouseOrder::where('id',$params['oid'])->find(); $find = WarehouseOrder::where('id', $params['oid'])->find();
if($find){ if ($find) {
$res = WarehouseProduct::where('id', $params['id'])->find(); $res = WarehouseProduct::where('id', $params['id'])->find();
if($find['financial_pm']==1){ if ($find['financial_pm'] == 1) {
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->dec('nums',$res['nums'])->update(); WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $res['nums'])->update();
StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->dec('stock',$res['nums'])->update(); StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->dec('stock', $res['nums'])->update();
$warehouseProductStorege=WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->find(); $warehouseProductStorege = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->find();
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->inc('nums',$params['nums'])->update(); WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $params['nums'])->update();
StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->inc('stock',$params['nums'])->update(); StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->inc('stock', $params['nums'])->update();
$before_nums=$warehouseProductStorege['nums']; $before_nums = $warehouseProductStorege['nums'];
$after_nums=$warehouseProductStorege['nums']+$params['nums']; $after_nums = $warehouseProductStorege['nums'] + $params['nums'];
}else{ } else {
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->inc('nums',$res['nums'])->update(); WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update();
StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->dec('stock',$res['nums'])->update(); StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->dec('stock', $res['nums'])->update();
$warehouseProductStorege=WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->find(); $warehouseProductStorege = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->find();
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->where('product_id',$res['product_id'])->dec('nums',$params['nums'])->update(); WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $params['nums'])->update();
StoreBranchProduct::where('store_id',$res['store_id'])->where('product_id',$res['product_id'])->inc('stock',$params['nums'])->update(); StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->inc('stock', $params['nums'])->update();
$before_nums=$warehouseProductStorege['nums']; $before_nums = $warehouseProductStorege['nums'];
$after_nums=bcsub($warehouseProductStorege['nums'],$params['nums'],2); $after_nums = bcsub($warehouseProductStorege['nums'], $params['nums'], 2);
} }
WarehouseProduct::where('id', $params['id'])->update([ WarehouseProduct::where('id', $params['id'])->update([
'nums' => $params['nums'], 'nums' => $params['nums'],
@ -241,14 +294,15 @@ 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();
if($find){ if ($find) {
$find->is_pay=1; $find->is_pay = 1;
$find->save(); $find->save();
} else{ } else {
throw new BusinessException('没有查到出入库信息'); throw new BusinessException('没有查到出入库信息');
} }
Db::commit(); Db::commit();

View File

@ -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;
@ -25,11 +26,11 @@ class SystemStoreStorageController extends BaseApiController
*/ */
public function lists() public function lists()
{ {
$store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); $store_id = SystemStoreStaff::where('uid', $this->userId)->value('store_id');
if(!$store_id){ if (!$store_id) {
return $this->fail('请先绑定店铺'); return $this->fail('请先绑定店铺');
} }
$this->request->__set('store_id',$store_id); $this->request->__set('store_id', $store_id);
return $this->dataLists(new SystemStoreStorageLists()); return $this->dataLists(new SystemStoreStorageLists());
} }
/** /**
@ -40,24 +41,37 @@ class SystemStoreStorageController extends BaseApiController
*/ */
public function group_lists() public function group_lists()
{ {
$store_id=SystemStoreStaff::where('uid',$this->userId)->value('store_id'); $store_id = SystemStoreStaff::where('uid', $this->userId)->value('store_id');
if(!$store_id){ if (!$store_id) {
return $this->fail('请先绑定店铺'); return $this->fail('请先绑定店铺');
} }
$this->request->__set('store_id',$store_id); $this->request->__set('store_id', $store_id);
return $this->dataLists(new SystemStoreStorageGroupLists()); return $this->dataLists(new SystemStoreStorageGroupLists());
} }
/** /**
* @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) {
$find->status=1; $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->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('操作失败');