feat:depotPurchase

This commit is contained in:
LAPTOP-7SGDREK0\shiweijun
2025-02-05 16:11:00 +08:00
parent ec15f9b13d
commit 3f7d8f5cad
6 changed files with 94 additions and 18 deletions

View File

@@ -135,10 +135,11 @@ class DepotService extends BaseService{
if (empty($materialInfo)) throw new ErrException("材料不存在");
$supplierId = (int)$this->request->input('supplier_id');
$supplierInfo = $this->SupplierModel->getInfoById($supplierId);
if (empty($supplierInfo)) throw new ErrException('供应商不存在');
if (!empty($supplierId)){
$supplierInfo = $this->SupplierModel->getInfoById($supplierId);
if (empty($supplierInfo)) throw new ErrException('供应商不存在');
}
$type = (int)$this->request->input('type');
$purchase_price = (double)$this->request->input('purchase_price');
$number = (double)$this->request->input('number');
@@ -153,7 +154,7 @@ class DepotService extends BaseService{
$depotPurchase->depot_id = $depotId;
$depotPurchase->material_id = $materialId;
$depotPurchase->supplier_id = $supplierId;
$depotPurchase->type = $type;
$depotPurchase->type = 1;
$depotPurchase->purchase_price = $purchase_price;
$depotPurchase->number = $number;
$depotPurchase->sum_price = $sum_price;
@@ -176,14 +177,8 @@ class DepotService extends BaseService{
$materialStock->unit_price = $purchase_price;
}
else{
//采购入
if ($depotPurchase->type == 1){
$materialStock->current_stock = $materialStock->current_stock + $number;
}
//采购退货
else
$materialStock->current_stock = $materialStock->current_stock - $number;
//库存增加
$materialStock->current_stock = $materialStock->current_stock + $number;
}
if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败');
@@ -192,6 +187,51 @@ class DepotService extends BaseService{
}
public function purchaseBack():array
{
$id = (int)$this->request->input('id');
$number = (double)$this->request->input('number');
$info = $this->DepotPurchaseModel->getDepotPurchase($id);
if (!empty($info)){
$depotPurchase = new DepotPurchase();
$depotPurchase->depot_id = $info->depot_id;
$depotPurchase->material_id = $info->material_id;
$depotPurchase->supplier_id = $info->supplier_id;
$depotPurchase->type = 2;
$depotPurchase->purchase_price = $info->purchase_price;
if (empty($number)){
$depotPurchase->number = $info->number;
}
else{
if ($info->number >= $number)
$depotPurchase->number = $number;
else
throw new ErrException('采购退货数量不能大于进货数量');
}
$depotPurchase->sum_price = $depotPurchase->purchase_price * $depotPurchase->number;
$depotPurchase->city_id = $info->city_id;
$depotPurchase->kitchen_id = $info->kitchen_id;
$depotPurchase->operator_id = $this->adminId;
}
$materialStock = $this->MaterialStockModel
->where('depot_id',$depotPurchase->depot_id)
->where('material_id',$depotPurchase->material_id)
->where('supplier_id',$depotPurchase->supplier_id)
->first();
if (empty($materialStock))
throw new ErrException('库存更改异常');
else{
//库存减少
$materialStock->current_stock = $materialStock->current_stock - $depotPurchase->number;
}
if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购退货失败');
return $this->return->success();
}
public function purchaseList():array
{
$limit = (int)$this->request->input('limit', 10);