feat:depot_sale
This commit is contained in:
@@ -5,10 +5,13 @@ declare(strict_types=1);
|
||||
namespace App\Service\Admin\Depot;
|
||||
|
||||
use App\Constants\Admin\DepotCode;
|
||||
use App\Constants\Common\MaterialCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Depot;
|
||||
use App\Model\DepotPurchase;
|
||||
use App\Model\DepotSale;
|
||||
use App\Model\Material;
|
||||
use App\Model\MaterialApplication;
|
||||
use App\Model\MaterialStock;
|
||||
use App\Model\Supplier;
|
||||
use App\Service\Admin\BaseService;
|
||||
@@ -34,6 +37,12 @@ class DepotService extends BaseService{
|
||||
#[Inject]
|
||||
protected DepotPurchase $DepotPurchaseModel;
|
||||
|
||||
#[Inject]
|
||||
protected DepotSale $DepotSaleModel;
|
||||
|
||||
#[inject]
|
||||
protected MaterialApplication $MaterialApplicationModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -287,4 +296,83 @@ class DepotService extends BaseService{
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
public function depotSale():array
|
||||
{
|
||||
$depotId = (int)$this->request->input('depot_id');
|
||||
$materialId = (int)$this->request->input('material_id');
|
||||
$supplierId = (int)$this->request->input('supplier_id');
|
||||
$number = (double)$this->request->input('number');
|
||||
$applicationId = (int)$this->request->input('application_id');
|
||||
$cityId = (int)$this->request->input('city_id');
|
||||
$kitchenId = (int)$this->request->input('kitchen_id');
|
||||
|
||||
$applicationInfo = $this->MaterialApplicationModel
|
||||
->where('application_id',$applicationId)
|
||||
->first();
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('depot_id',$depotId)
|
||||
->where('material_id',$materialId)
|
||||
->where('supplier_id',$supplierId)
|
||||
->first();
|
||||
|
||||
$depotSale = new DepotSale();
|
||||
$depotSale->depot_id = $depotId;
|
||||
$depotSale->dish_id = $applicationInfo->dish_id;
|
||||
$depotSale->material_id = $materialId;
|
||||
$depotSale->sale_price = $materialStock->unit_price;
|
||||
$depotSale->number = $number;
|
||||
$depotSale->sum_price = $depotSale->sale_price * $number;
|
||||
$depotSale->city_id = $cityId;
|
||||
$depotSale->kitchen_id = $kitchenId;
|
||||
$depotSale->operator_id = $this->adminId;
|
||||
|
||||
//库存减少
|
||||
$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->status = MaterialCode::PART_OUT;
|
||||
else if ($number > $applicationInfo->num)
|
||||
|
||||
if (!$depotSale->save() || !$materialStock->save()) throw new ErrException('商品出库异常');
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
public function saleUpdate():array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$info = $this->DepotSaleModel
|
||||
->where('id',$id)
|
||||
->first();
|
||||
|
||||
$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 + $old_number - $number;
|
||||
|
||||
if (!$info->save() || !$materialStock->save()) throw new ErrException('商品出库数量修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user