feat:depot_sale
This commit is contained in:
@@ -307,7 +307,7 @@ class DepotService extends BaseService{
|
||||
$kitchenId = (int)$this->request->input('kitchen_id');
|
||||
|
||||
$applicationInfo = $this->MaterialApplicationModel
|
||||
->where('application_id',$applicationId)
|
||||
->where('id',$applicationId)
|
||||
->first();
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
@@ -320,9 +320,11 @@ class DepotService extends BaseService{
|
||||
$depotSale->depot_id = $depotId;
|
||||
$depotSale->dish_id = $applicationInfo->dish_id;
|
||||
$depotSale->material_id = $materialId;
|
||||
$depotSale->supplier_id = $supplierId;
|
||||
$depotSale->sale_price = $materialStock->unit_price;
|
||||
$depotSale->number = $number;
|
||||
$depotSale->sum_price = $depotSale->sale_price * $number;
|
||||
$depotSale->application_id = $applicationId;
|
||||
$depotSale->city_id = $cityId;
|
||||
$depotSale->kitchen_id = $kitchenId;
|
||||
$depotSale->operator_id = $this->adminId;
|
||||
@@ -330,16 +332,13 @@ class DepotService extends BaseService{
|
||||
//库存减少
|
||||
$materialStock->current_stock = $materialStock->current_stock - $number;
|
||||
|
||||
// $numberList = $this->DepotSaleModel
|
||||
// ->where('application_id',$applicationId)
|
||||
// ->where('is_del',DepotCode::IS_NO_DEL)
|
||||
|
||||
|
||||
if ($number < $applicationInfo->num)
|
||||
$applicationInfo->al_number = $number + $applicationInfo->al_number;
|
||||
if ($applicationInfo->al_number < $applicationInfo->number)
|
||||
$applicationInfo->status = MaterialCode::PART_OUT;
|
||||
else if ($number > $applicationInfo->num)
|
||||
else
|
||||
$applicationInfo->status = MaterialCode::ALL_OUT;
|
||||
|
||||
if (!$depotSale->save() || !$materialStock->save()) throw new ErrException('商品出库异常');
|
||||
if (!$depotSale->save() || !$materialStock->save() ||!$applicationInfo->save()) throw new ErrException('商品出库异常');
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
@@ -351,11 +350,14 @@ class DepotService extends BaseService{
|
||||
$info = $this->DepotSaleModel
|
||||
->where('id',$id)
|
||||
->first();
|
||||
$applicationInfo = $this->MaterialApplicationModel
|
||||
->where('id',$info->application_id)
|
||||
->first();
|
||||
|
||||
$old_number = $info->number;
|
||||
|
||||
$number = (double)$this->request->input('number');
|
||||
$sum_price = $info->purchase_price * $number;
|
||||
$sum_price = $info->sale_price * $number;
|
||||
|
||||
$info->number = $number;
|
||||
$info->sum_price = $sum_price;
|
||||
@@ -368,11 +370,74 @@ class DepotService extends BaseService{
|
||||
|
||||
$materialStock->current_stock = $materialStock->current_stock + $old_number - $number;
|
||||
|
||||
if (!$info->save() || !$materialStock->save()) throw new ErrException('商品出库数量修改失败');
|
||||
$applicationInfo->al_number = $applicationInfo->al_number + $number - $old_number;
|
||||
if ($applicationInfo->al_number < $applicationInfo->number)
|
||||
$applicationInfo->status = MaterialCode::PART_OUT;
|
||||
else
|
||||
$applicationInfo->status = MaterialCode::ALL_OUT;
|
||||
|
||||
if (!$info->save() || !$materialStock->save() || !$applicationInfo->save()) throw new ErrException('商品出库数量修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function saleDelete():array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$info = $this->DepotSaleModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('id',$id)
|
||||
->first();
|
||||
|
||||
$applicationInfo = $this->MaterialApplicationModel
|
||||
->where('id',$info->application_id)
|
||||
->first();
|
||||
|
||||
$applicationInfo->al_number = $applicationInfo->al_number - $info->number;
|
||||
if ($applicationInfo->al_number < $applicationInfo->number)
|
||||
$applicationInfo->status = MaterialCode::PART_OUT;
|
||||
else if ($applicationInfo->al_number == 0.00)
|
||||
$applicationInfo->status = MaterialCode::AUDITED;
|
||||
|
||||
$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 + $info->number;
|
||||
|
||||
$info->is_del = MaterialCode::IS_DEL;
|
||||
|
||||
if (!$applicationInfo->save() || !$materialStock->save() || !$info->save()) throw new ErrException('商品出库数量删除失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function saleList():array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$id = (int)$this->request->input('query_id');
|
||||
$kitchenId = (int)$this->request->input('query_kitchen_id');
|
||||
|
||||
$list = $this->DepotSaleModel
|
||||
->leftJoin('material','depot_sale.material_id','=','material.id')
|
||||
->leftJoin('supplier','depot_sale.supplier_id','=','supplier.id')
|
||||
->leftJoin('dish','depot_sale.dish_id','=','dish.id')
|
||||
->leftJoin('depot','depot_sale.depot_id','=','depot.id')
|
||||
->leftJoin('admin_user','depot_sale.operator_id','=','admin_user.id')
|
||||
->where('depot_sale.is_del',MaterialCode::IS_NO_DEL)
|
||||
->when($id,function ($query) use ($id) {
|
||||
$query->where('depot_sale.id',$id);
|
||||
})
|
||||
->when($kitchenId,function ($query) use ($kitchenId) {
|
||||
$query->where('depot_sale.kitchen_id',$kitchenId);
|
||||
})
|
||||
->paginate($limit,['depot_sale.*','material.name as material_name','supplier.name as supplier_name','dish.dish as dish_name','admin_user.chinese_name as operator_name','depot.name as depot_name'])
|
||||
->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user