feat: 新增库存和价值更新功能
This commit is contained in:
parent
2d10a79e54
commit
e3b6bb9831
@ -339,4 +339,17 @@ class WorkbenchController extends BaseAdminController
|
|||||||
return $this->data([], '操作失败', 400);
|
return $this->data([], '操作失败', 400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 更新库存和价值
|
||||||
|
*/
|
||||||
|
public function stock_product_price()
|
||||||
|
{
|
||||||
|
$parmas = $this->request->get();
|
||||||
|
$res = WarehouseLogic::stockProductPrice($parmas);
|
||||||
|
if($res){
|
||||||
|
return $this->success('操作成功,请刷新页面',[],1,1);
|
||||||
|
}else{
|
||||||
|
return $this->fail('操作失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,4 +232,47 @@ class WarehouseLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function stockProductPrice($parmas){
|
||||||
|
|
||||||
|
$arr1=WarehouseProductStorege::where('nums','>',0)->select();
|
||||||
|
foreach ($arr1 as $k=>$v){
|
||||||
|
$find=StoreProduct::where('id',$v['product_id'])->find();
|
||||||
|
if($find&& $find['price']>0){
|
||||||
|
$total_price=bcmul($find['price'],$v['nums'],2);
|
||||||
|
$price=$find['price'];
|
||||||
|
}else{
|
||||||
|
$total_price=0;
|
||||||
|
$price=0;
|
||||||
|
}
|
||||||
|
WarehouseProductStorege::where('id',$v['id'])->update(['price'=>$price,'total_price'=>$total_price]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$arr2=StoreBranchProduct::where('stock','>',0)->select();
|
||||||
|
foreach ($arr2 as $k=>$v){
|
||||||
|
if($v['price']>0){
|
||||||
|
$total_price=bcmul($v['price'],$v['stock'],2);
|
||||||
|
}else{
|
||||||
|
$total_price=0;
|
||||||
|
}
|
||||||
|
StoreBranchProduct::where('id',$v['id'])->update(['total_price'=>$total_price]);
|
||||||
|
}
|
||||||
|
$arr3=WarehouseProductStorege::where('nums','>',0)->field('product_id,sum(nums) as nums')->select();
|
||||||
|
foreach ($arr3 as $k=>$v){
|
||||||
|
StoreProduct::where('id',$v['product_id'])->update(['stock'=>$v['nums']]);
|
||||||
|
}
|
||||||
|
$arr4=StoreBranchProduct::where('stock','>',0)->field('product_id,sum(stock) as stock')->select();
|
||||||
|
foreach ($arr4 as $k=>$v){
|
||||||
|
$find=StoreProduct::where('id',$v['product_id'])->find();
|
||||||
|
if($find){
|
||||||
|
$stock=bcadd($find['stock'],$v['stock'],2);
|
||||||
|
$find->total_price=bcmul($find['purchase'],$v['stock'],2);
|
||||||
|
$find->stock=$stock;
|
||||||
|
$find->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user