feat:depotPurchase
This commit is contained in:
@@ -80,6 +80,19 @@ class DepotController
|
||||
return (new DepotService)->purchase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购修改
|
||||
* @param DepotRequest $request
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
#[RequestMapping(path: "depot_purchase_update", methods: "POST")]
|
||||
#[Scene(scene: "purchase_update")]
|
||||
public function purchaseUpdate(DepotRequest $request): array
|
||||
{
|
||||
return (new DepotService)->purchaseUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购退货
|
||||
* @param DepotRequest $request
|
||||
|
||||
@@ -29,6 +29,8 @@ class DepotRequest extends FormRequest
|
||||
'city_id' => 'required|integer|exists:system_city,id',
|
||||
'kitchen_id' => 'required|integer|exists:kitchen,id',
|
||||
'id' => 'required|integer',
|
||||
'purchase_price' => 'required',
|
||||
'number' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -38,6 +40,7 @@ class DepotRequest extends FormRequest
|
||||
'depot_edit' => ['id','name'],
|
||||
'depot_delete' => ['id'],
|
||||
'purchase' => ['depot_id','material_id','supplier_id','purchase_price','number','city_id','kitchen_id'],
|
||||
'purchase_update' => ['id','number'],
|
||||
'purchase_back' => ['id'],
|
||||
'purchase_list' => ['limit','query_id','query_kitchen_id','type'],
|
||||
];
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -389,10 +389,10 @@ Authorization: Bearer {{admin_token}}
|
||||
|
||||
depot_id=1&material_id=1&supplier_id=1&purchase_price=60&number=2&city_id=1&kitchen_id=1
|
||||
|
||||
### 采购退货
|
||||
POST {{host}}/admin/depot/depot_purchase_back
|
||||
### 采购数量修改
|
||||
POST {{host}}/admin/depot/depot_purchase_update
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
id=6
|
||||
id=1&number=8
|
||||
|
||||
|
||||
Reference in New Issue
Block a user