feat:depotPurchase
This commit is contained in:
@@ -187,6 +187,32 @@ class DepotService extends BaseService{
|
||||
|
||||
}
|
||||
|
||||
public function purchaseUpdate():array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$info = $this->DepotPurchaseModel->getDepotPurchase($id);
|
||||
$old_number = $info->number;
|
||||
|
||||
$number = (double)$this->request->input('number');
|
||||
$sum_price = $info->purchase_price * $number;
|
||||
|
||||
$info->number = $number;
|
||||
$info->sum_price = $sum_price;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('material_id',$info->material_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = $materialStock->current_stock + $number - $old_number;
|
||||
|
||||
if (!$info->save() || !$materialStock->save()) throw new ErrException('采购数量修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
public function purchaseBack():array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
@@ -223,6 +249,8 @@ class DepotService extends BaseService{
|
||||
if (empty($materialStock))
|
||||
throw new ErrException('库存更改异常');
|
||||
else{
|
||||
if ($materialStock->current_stock < $depotPurchase->number)
|
||||
throw new ErrException('库存数量小于退货数量');
|
||||
//库存减少
|
||||
$materialStock->current_stock = $materialStock->current_stock - $depotPurchase->number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user