feat:depot_sale

This commit is contained in:
LAPTOP-7SGDREK0\shiweijun
2025-02-07 15:09:03 +08:00
parent cc6f530c8e
commit f5667baa6e
4 changed files with 161 additions and 0 deletions

View File

@@ -117,4 +117,30 @@ class DepotController
{ {
return (new DepotService)->purchaseList(); return (new DepotService)->purchaseList();
} }
/**
* 销售出库
* @param DepotRequest $request
* @return array
* @throws Exception
*/
#[RequestMapping(path: "depot_sale", methods: "POST")]
#[Scene(scene: "depot_sale")]
public function depotSale(DepotRequest $request): array
{
return (new DepotService)->depotSale();
}
/**
* 销售出库数量修改
* @param DepotRequest $request
* @return array
* @throws Exception
*/
#[RequestMapping(path: "depot_sale_update", methods: "POST")]
#[Scene(scene: "sale_update")]
public function saleUpdate(DepotRequest $request): array
{
return (new DepotService)->saleUpdate();
}
} }

45
app/Model/DepotSale.php Normal file
View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\DbConnection\Model\Model;
/**
* @property int $id
* @property int $depot_id
* @property int $material_id
* @property int $dish_id
* @property string $sale_price
* @property string $number
* @property string $sum_price
* @property int $application_id
* @property int $city_id
* @property int $kitchen_id
* @property int $operator_id
* @property int $is_del
* @property string $create_time
* @property string $update_time
*/
class DepotSale extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'depot_sale';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['id' => 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'dish_id' => 'integer', 'application_id' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer'];
const string CREATED_AT = 'create_time';
const string UPDATED_AT = 'update_time';
}

View File

@@ -43,5 +43,7 @@ class DepotRequest extends FormRequest
'purchase_update' => ['id','number'], 'purchase_update' => ['id','number'],
'purchase_back' => ['id'], 'purchase_back' => ['id'],
'purchase_list' => ['limit','query_id','query_kitchen_id','type'], 'purchase_list' => ['limit','query_id','query_kitchen_id','type'],
'sale' => ['depot_id','material_id','dish_id','number','application_id','city_id','kitchen_id'],
'sale_update' => ['id','number'],
]; ];
} }

View File

@@ -5,10 +5,13 @@ declare(strict_types=1);
namespace App\Service\Admin\Depot; namespace App\Service\Admin\Depot;
use App\Constants\Admin\DepotCode; use App\Constants\Admin\DepotCode;
use App\Constants\Common\MaterialCode;
use App\Exception\ErrException; use App\Exception\ErrException;
use App\Model\Depot; use App\Model\Depot;
use App\Model\DepotPurchase; use App\Model\DepotPurchase;
use App\Model\DepotSale;
use App\Model\Material; use App\Model\Material;
use App\Model\MaterialApplication;
use App\Model\MaterialStock; use App\Model\MaterialStock;
use App\Model\Supplier; use App\Model\Supplier;
use App\Service\Admin\BaseService; use App\Service\Admin\BaseService;
@@ -34,6 +37,12 @@ class DepotService extends BaseService{
#[Inject] #[Inject]
protected DepotPurchase $DepotPurchaseModel; protected DepotPurchase $DepotPurchaseModel;
#[Inject]
protected DepotSale $DepotSaleModel;
#[inject]
protected MaterialApplication $MaterialApplicationModel;
public function handle() public function handle()
{ {
@@ -287,4 +296,83 @@ class DepotService extends BaseService{
return $this->return->success('success',$list); 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();
}
} }