feat:depot_recycle
This commit is contained in:
@@ -484,7 +484,10 @@ class DepotService extends BaseService{
|
||||
throw new ErrException('回收数量不能大于出库数量');
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->getMaterial($materialId,$depotId,$supplierId);
|
||||
->where('material_id',$materialId)
|
||||
->where('depot_id',$depotId)
|
||||
->where('supplier_id',$supplierId)
|
||||
->first();
|
||||
|
||||
$depotRecycle = new DepotRecycle();
|
||||
$depotRecycle->depot_id = $depotId;
|
||||
@@ -534,7 +537,10 @@ class DepotService extends BaseService{
|
||||
$info->sum_price = $sum_price;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->getMaterial($info->material_id,$info->depot_id,$info->supplier_id);
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = $materialStock->current_stock + $number - $old_number;
|
||||
|
||||
@@ -543,6 +549,8 @@ class DepotService extends BaseService{
|
||||
->first();
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number + $number - $old_number;
|
||||
if ($saleInfo->back_number > $saleInfo->number)
|
||||
throw new ErrException('回收数量不能大于出库数量');
|
||||
|
||||
if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) throw new ErrException('商品回收数量修改失败');
|
||||
|
||||
@@ -564,7 +572,10 @@ class DepotService extends BaseService{
|
||||
$info->is_del = MaterialCode::IS_DEL;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->getMaterial($info->material_id,$info->depot_id,$info->supplier_id);
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = $materialStock->current_stock - $info->number;
|
||||
|
||||
@@ -586,6 +597,9 @@ class DepotService extends BaseService{
|
||||
$id = (int)$this->request->input('query_id');
|
||||
$kitchenId = (int)$this->request->input('query_kitchen_id');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$list = $this->DepotRecycleModel
|
||||
->leftJoin('depot','depot_recycle.depot_id','=','depot.id')
|
||||
->leftJoin('material','depot_recycle.material_id','=','material.id')
|
||||
@@ -604,4 +618,78 @@ class DepotService extends BaseService{
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
public function recycleAudit():array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$status = (int)$this->request->input('status');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$info = $this->DepotRecycleModel
|
||||
->where('id',$id)
|
||||
->first();
|
||||
|
||||
if ($info->status != MaterialCode::AUDITED){
|
||||
if ($status == MaterialCode::AUDITED){
|
||||
$saleInfo = $this->DepotSaleModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('id',$info->sale_id)
|
||||
->first();
|
||||
|
||||
if (empty($saleInfo)){
|
||||
throw new ErrException('无出库记录');
|
||||
}
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number + $info->number;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
if (empty($materialStock)){
|
||||
$materialStock = new MaterialStock();
|
||||
$materialStock->depot_id = $info->depotId;
|
||||
$materialStock->material_id = $info->materialId;
|
||||
$materialStock->supplier_id = $info->supplierId;
|
||||
$materialStock->current_stock = $info->number;
|
||||
$materialStock->unit_price = $info->recycle_price;
|
||||
}
|
||||
else
|
||||
$materialStock->current_stock = $materialStock->current_stock + $info->number;
|
||||
|
||||
if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常');
|
||||
|
||||
}
|
||||
}
|
||||
if ($info->status == MaterialCode::AUDITED){
|
||||
if ($status == MaterialCode::UN_AUDIT || $status == MaterialCode::AUDIT_REFUSE){
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = $materialStock->current_stock - $info->number;
|
||||
|
||||
$saleInfo = $this->DepotSaleModel
|
||||
->where('id',$info->sale_id)
|
||||
->first();
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number - $info->number;
|
||||
|
||||
if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常');
|
||||
}
|
||||
}
|
||||
|
||||
$info->status = $status;
|
||||
|
||||
if (!$info->save()) throw new ErrException('回收审核异常');
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user