feat:depot_sale
This commit is contained in:
@@ -125,7 +125,7 @@ class DepotController
|
||||
* @throws Exception
|
||||
*/
|
||||
#[RequestMapping(path: "depot_sale", methods: "POST")]
|
||||
#[Scene(scene: "depot_sale")]
|
||||
#[Scene(scene: "sale")]
|
||||
public function depotSale(DepotRequest $request): array
|
||||
{
|
||||
return (new DepotService)->depotSale();
|
||||
@@ -137,10 +137,35 @@ class DepotController
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
#[RequestMapping(path: "depot_sale_update", methods: "POST")]
|
||||
#[RequestMapping(path: "sale_update", methods: "POST")]
|
||||
#[Scene(scene: "sale_update")]
|
||||
public function saleUpdate(DepotRequest $request): array
|
||||
{
|
||||
return (new DepotService)->saleUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 销售出库删除
|
||||
* @param DepotRequest $request
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
#[RequestMapping(path: "sale_delete", methods: "POST")]
|
||||
#[Scene(scene: "sale_delete")]
|
||||
public function saleDelete(DepotRequest $request): array
|
||||
{
|
||||
return (new DepotService)->saleDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 出库列表
|
||||
* @param DepotRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "sale_list", methods: "GET")]
|
||||
#[Scene(scene: "sale_list")]
|
||||
public function saleList(DepotRequest $request): array
|
||||
{
|
||||
return (new DepotService)->saleList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ use Hyperf\DbConnection\Model\Model;
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $depot_id
|
||||
* @property int $material_id
|
||||
* @property int $material_id
|
||||
* @property int $supplier_id
|
||||
* @property int $dish_id
|
||||
* @property string $sale_price
|
||||
* @property string $number
|
||||
@@ -37,7 +38,7 @@ class DepotSale extends Model
|
||||
/**
|
||||
* 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'];
|
||||
protected array $casts = ['id' => 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'supplier_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';
|
||||
|
||||
|
||||
@@ -43,7 +43,9 @@ class DepotRequest extends FormRequest
|
||||
'purchase_update' => ['id','number'],
|
||||
'purchase_back' => ['id'],
|
||||
'purchase_list' => ['limit','query_id','query_kitchen_id','type'],
|
||||
'sale' => ['depot_id','material_id','dish_id','number','application_id','city_id','kitchen_id'],
|
||||
'sale' => ['depot_id','material_id','supplier_id','number','application_id','city_id','kitchen_id'],
|
||||
'sale_update' => ['id','number'],
|
||||
'sale_delete' => ['id'],
|
||||
'sale_list' => ['limit','query_id','query_kitchen_id'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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