feat:depot_recycle
This commit is contained in:
@@ -14,4 +14,5 @@ class RoleCode
|
|||||||
const int MARKETPLACE = 6;
|
const int MARKETPLACE = 6;
|
||||||
const int CHEF = 7;
|
const int CHEF = 7;
|
||||||
const int DRIVER = 8;
|
const int DRIVER = 8;
|
||||||
|
const int WAREHOUSE = 9;
|
||||||
}
|
}
|
||||||
@@ -168,4 +168,55 @@ class DepotController
|
|||||||
{
|
{
|
||||||
return (new DepotService)->saleList();
|
return (new DepotService)->saleList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回收
|
||||||
|
* @param DepotRequest $request
|
||||||
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "depot_recycle", methods: "POST")]
|
||||||
|
#[Scene(scene: "recycle")]
|
||||||
|
public function depotRecycle(DepotRequest $request): array
|
||||||
|
{
|
||||||
|
return (new DepotService)->recycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回收修改数量
|
||||||
|
* @param DepotRequest $request
|
||||||
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "recycle_update", methods: "POST")]
|
||||||
|
#[Scene(scene: "recycle_update")]
|
||||||
|
public function recycleUpdate(DepotRequest $request): array
|
||||||
|
{
|
||||||
|
return (new DepotService)->recycleUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回收删除
|
||||||
|
* @param DepotRequest $request
|
||||||
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "recycle_delete", methods: "POST")]
|
||||||
|
#[Scene(scene: "recycle_delete")]
|
||||||
|
public function recycleDelete(DepotRequest $request): array
|
||||||
|
{
|
||||||
|
return (new DepotService)->recycleDelete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回收列表
|
||||||
|
* @param DepotRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "recycle_list", methods: "GET")]
|
||||||
|
#[Scene(scene: "recycle_list")]
|
||||||
|
public function recycleList(DepotRequest $request): array
|
||||||
|
{
|
||||||
|
return (new DepotService)->recycleList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
46
app/Model/DepotRecycle.php
Normal file
46
app/Model/DepotRecycle.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?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 $supplier_id
|
||||||
|
* @property string $recycle_price
|
||||||
|
* @property string $number
|
||||||
|
* @property string $sum_price
|
||||||
|
* @property int $sale_id
|
||||||
|
* @property int $status
|
||||||
|
* @property int $city_id
|
||||||
|
* @property int $kitchen_id
|
||||||
|
* @property int $operator_id
|
||||||
|
* @property int $is_del
|
||||||
|
* @property \Carbon\Carbon $create_time
|
||||||
|
* @property \Carbon\Carbon $update_time
|
||||||
|
*/
|
||||||
|
class DepotRecycle extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*/
|
||||||
|
protected ?string $table = 'depot_recycle';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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', 'supplier_id' => 'integer', 'sale_id' => 'integer', 'status' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer', 'create_time' => 'datetime', 'update_time' => 'datetime'];
|
||||||
|
|
||||||
|
const string CREATED_AT = 'create_time';
|
||||||
|
|
||||||
|
const string UPDATED_AT = 'update_time';
|
||||||
|
}
|
||||||
@@ -13,7 +13,8 @@ use Hyperf\DbConnection\Model\Model;
|
|||||||
* @property int $supplier_id
|
* @property int $supplier_id
|
||||||
* @property int $dish_id
|
* @property int $dish_id
|
||||||
* @property string $sale_price
|
* @property string $sale_price
|
||||||
* @property string $number
|
* @property string $number
|
||||||
|
* @property string $back_number
|
||||||
* @property string $sum_price
|
* @property string $sum_price
|
||||||
* @property int $application_id
|
* @property int $application_id
|
||||||
* @property int $city_id
|
* @property int $city_id
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ class DepotRequest extends FormRequest
|
|||||||
'id' => 'required|integer',
|
'id' => 'required|integer',
|
||||||
'purchase_price' => 'required',
|
'purchase_price' => 'required',
|
||||||
'number' => 'required',
|
'number' => 'required',
|
||||||
|
'depot_id' => 'required|integer|exists:depot,id',
|
||||||
|
'material_id' => 'required|integer|exists:material,id',
|
||||||
|
'supplier_id' => 'required|integer|exists:supplier,id',
|
||||||
|
'application_id' => 'required|integer|exists:material_application,id',
|
||||||
|
'sale_id' => 'required|integer|exists:depot_sale,id',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,5 +52,9 @@ class DepotRequest extends FormRequest
|
|||||||
'sale_update' => ['id','number'],
|
'sale_update' => ['id','number'],
|
||||||
'sale_delete' => ['id'],
|
'sale_delete' => ['id'],
|
||||||
'sale_list' => ['limit','query_id','query_kitchen_id'],
|
'sale_list' => ['limit','query_id','query_kitchen_id'],
|
||||||
|
'recycle' =>['material_id','supplier_id','number','sale_id','city_id','kitchen_id'],
|
||||||
|
'recycle_update' => ['id','number'],
|
||||||
|
'recycle_delete' => ['id'],
|
||||||
|
'recycle_list' => ['limit','query_id','query_kitchen_id'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ namespace App\Service\Admin\Depot;
|
|||||||
|
|
||||||
use App\Constants\Admin\DepotCode;
|
use App\Constants\Admin\DepotCode;
|
||||||
use App\Constants\Common\MaterialCode;
|
use App\Constants\Common\MaterialCode;
|
||||||
|
use App\Constants\Common\RoleCode;
|
||||||
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\DepotRecycle;
|
||||||
use App\Model\DepotSale;
|
use App\Model\DepotSale;
|
||||||
use App\Model\Material;
|
use App\Model\Material;
|
||||||
use App\Model\MaterialApplication;
|
use App\Model\MaterialApplication;
|
||||||
@@ -40,6 +42,10 @@ class DepotService extends BaseService{
|
|||||||
#[Inject]
|
#[Inject]
|
||||||
protected DepotSale $DepotSaleModel;
|
protected DepotSale $DepotSaleModel;
|
||||||
|
|
||||||
|
|
||||||
|
#[Inject]
|
||||||
|
protected DepotRecycle $DepotRecycleModel;
|
||||||
|
|
||||||
#[inject]
|
#[inject]
|
||||||
protected MaterialApplication $MaterialApplicationModel;
|
protected MaterialApplication $MaterialApplicationModel;
|
||||||
|
|
||||||
@@ -306,6 +312,9 @@ class DepotService extends BaseService{
|
|||||||
$cityId = (int)$this->request->input('city_id');
|
$cityId = (int)$this->request->input('city_id');
|
||||||
$kitchenId = (int)$this->request->input('kitchen_id');
|
$kitchenId = (int)$this->request->input('kitchen_id');
|
||||||
|
|
||||||
|
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||||
|
throw new ErrException('该角色没有权限');
|
||||||
|
|
||||||
$applicationInfo = $this->MaterialApplicationModel
|
$applicationInfo = $this->MaterialApplicationModel
|
||||||
->where('id',$applicationId)
|
->where('id',$applicationId)
|
||||||
->first();
|
->first();
|
||||||
@@ -347,6 +356,10 @@ class DepotService extends BaseService{
|
|||||||
public function saleUpdate():array
|
public function saleUpdate():array
|
||||||
{
|
{
|
||||||
$id = (int)$this->request->input('id');
|
$id = (int)$this->request->input('id');
|
||||||
|
|
||||||
|
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||||
|
throw new ErrException('该角色没有权限');
|
||||||
|
|
||||||
$info = $this->DepotSaleModel
|
$info = $this->DepotSaleModel
|
||||||
->where('id',$id)
|
->where('id',$id)
|
||||||
->first();
|
->first();
|
||||||
@@ -384,6 +397,10 @@ class DepotService extends BaseService{
|
|||||||
public function saleDelete():array
|
public function saleDelete():array
|
||||||
{
|
{
|
||||||
$id = (int)$this->request->input('id');
|
$id = (int)$this->request->input('id');
|
||||||
|
|
||||||
|
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||||
|
throw new ErrException('该角色没有权限');
|
||||||
|
|
||||||
$info = $this->DepotSaleModel
|
$info = $this->DepotSaleModel
|
||||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||||
->where('id',$id)
|
->where('id',$id)
|
||||||
@@ -394,10 +411,10 @@ class DepotService extends BaseService{
|
|||||||
->first();
|
->first();
|
||||||
|
|
||||||
$applicationInfo->al_number = $applicationInfo->al_number - $info->number;
|
$applicationInfo->al_number = $applicationInfo->al_number - $info->number;
|
||||||
if ($applicationInfo->al_number < $applicationInfo->number)
|
if ($applicationInfo->al_number <= 0)
|
||||||
$applicationInfo->status = MaterialCode::PART_OUT;
|
|
||||||
else if ($applicationInfo->al_number == 0.00)
|
|
||||||
$applicationInfo->status = MaterialCode::AUDITED;
|
$applicationInfo->status = MaterialCode::AUDITED;
|
||||||
|
else if ($applicationInfo->al_number < $applicationInfo->number)
|
||||||
|
$applicationInfo->status = MaterialCode::PART_OUT;
|
||||||
|
|
||||||
$materialStock = $this->MaterialStockModel
|
$materialStock = $this->MaterialStockModel
|
||||||
->where('depot_id',$info->depot_id)
|
->where('depot_id',$info->depot_id)
|
||||||
@@ -439,5 +456,152 @@ class DepotService extends BaseService{
|
|||||||
return $this->return->success('success',$list);
|
return $this->return->success('success',$list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function recycle():array
|
||||||
|
{
|
||||||
|
$materialId = (int)$this->request->input('material_id');
|
||||||
|
$supplierId = (int)$this->request->input('supplier_id');
|
||||||
|
$number = (double)$this->request->input('number');
|
||||||
|
$saleId = (int)$this->request->input('sale_id');
|
||||||
|
$cityId = (int)$this->request->input('city_id');
|
||||||
|
$kitchenId = (int)$this->request->input('kitchen_id');
|
||||||
|
$depotInfo = $this->DepotModel
|
||||||
|
->getInfoByName('回收仓库',$kitchenId);
|
||||||
|
if (empty($depotInfo))
|
||||||
|
throw new ErrException('未创建回收仓库');
|
||||||
|
else
|
||||||
|
$depotId = $depotInfo->id;
|
||||||
|
|
||||||
|
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||||
|
throw new ErrException('该角色没有权限');
|
||||||
|
|
||||||
|
$saleInfo = $this->DepotSaleModel
|
||||||
|
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||||
|
->where('id',$saleId)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$saleInfo->back_number = $saleInfo->back_number + $number;
|
||||||
|
if ($saleInfo->back_number > $saleInfo->number)
|
||||||
|
throw new ErrException('回收数量不能大于出库数量');
|
||||||
|
|
||||||
|
$materialStock = $this->MaterialStockModel
|
||||||
|
->getMaterial($materialId,$depotId,$supplierId);
|
||||||
|
|
||||||
|
$depotRecycle = new DepotRecycle();
|
||||||
|
$depotRecycle->depot_id = $depotId;
|
||||||
|
$depotRecycle->material_id = $materialId;
|
||||||
|
$depotRecycle->supplier_id = $supplierId;
|
||||||
|
$depotRecycle->recycle_price = $saleInfo->sale_price;
|
||||||
|
$depotRecycle->number = $number;
|
||||||
|
$depotRecycle->sum_price = $saleInfo->sale_price * $number;
|
||||||
|
$depotRecycle->sale_id = $saleId;
|
||||||
|
$depotRecycle->status = MaterialCode::AUDITED;
|
||||||
|
$depotRecycle->city_id = $cityId;
|
||||||
|
$depotRecycle->kitchen_id = $kitchenId;
|
||||||
|
$depotRecycle->operator_id = $this->adminId;
|
||||||
|
|
||||||
|
if (empty($materialStock)){
|
||||||
|
$materialStock = new MaterialStock();
|
||||||
|
$materialStock->depot_id = $depotId;
|
||||||
|
$materialStock->material_id = $materialId;
|
||||||
|
$materialStock->supplier_id = $supplierId;
|
||||||
|
$materialStock->current_stock = $number;
|
||||||
|
$materialStock->unit_price = $depotRecycle->recycle_price;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$materialStock->current_stock = $materialStock->current_stock + $number;
|
||||||
|
|
||||||
|
if (!$saleInfo->save() || !$depotRecycle->save() || !$materialStock->save()) throw new ErrException('回收发生异常');
|
||||||
|
|
||||||
|
return $this->return->success();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function recycleUpdate():array
|
||||||
|
{
|
||||||
|
$id = (int)$this->request->input('id');
|
||||||
|
$number = (double)$this->request->input('number');
|
||||||
|
|
||||||
|
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||||
|
throw new ErrException('该角色没有权限');
|
||||||
|
|
||||||
|
$info = $this->DepotRecycleModel
|
||||||
|
->where('id',$id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$old_number = $info->number;
|
||||||
|
$sum_price = $info->recycle_price * $number;
|
||||||
|
$info->number = $number;
|
||||||
|
$info->sum_price = $sum_price;
|
||||||
|
|
||||||
|
$materialStock = $this->MaterialStockModel
|
||||||
|
->getMaterial($info->material_id,$info->depot_id,$info->supplier_id);
|
||||||
|
|
||||||
|
$materialStock->current_stock = $materialStock->current_stock + $number - $old_number;
|
||||||
|
|
||||||
|
$saleInfo = $this->DepotSaleModel
|
||||||
|
->where('id',$info->sale_id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$saleInfo->back_number = $saleInfo->back_number + $number - $old_number;
|
||||||
|
|
||||||
|
if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) throw new ErrException('商品回收数量修改失败');
|
||||||
|
|
||||||
|
return $this->return->success();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function recycleDelete():array
|
||||||
|
{
|
||||||
|
$id = (int)$this->request->input('id');
|
||||||
|
|
||||||
|
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||||
|
throw new ErrException('该角色没有权限');
|
||||||
|
|
||||||
|
$info = $this->DepotRecycleModel
|
||||||
|
->where('id',$id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$info->is_del = MaterialCode::IS_DEL;
|
||||||
|
|
||||||
|
$materialStock = $this->MaterialStockModel
|
||||||
|
->getMaterial($info->material_id,$info->depot_id,$info->supplier_id);
|
||||||
|
|
||||||
|
$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 (!$info->save() || !$materialStock->save() || !$saleInfo->save())
|
||||||
|
throw new ErrException('商品回收删除失败');
|
||||||
|
|
||||||
|
return $this->return->success();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function recycleList():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->DepotRecycleModel
|
||||||
|
->leftJoin('depot','depot_recycle.depot_id','=','depot.id')
|
||||||
|
->leftJoin('material','depot_recycle.material_id','=','material.id')
|
||||||
|
->leftJoin('supplier','depot_recycle.supplier_id','=','supplier.id')
|
||||||
|
->leftJoin('admin_user','depot_recycle.operator_id','=','admin_user.id')
|
||||||
|
->where('depot_recycle.is_del',MaterialCode::IS_NO_DEL)
|
||||||
|
->when($id,function ($query) use ($id) {
|
||||||
|
$query->where('depot_recycle.id',$id);
|
||||||
|
})
|
||||||
|
->when($kitchenId > 0,function($query) use($kitchenId){
|
||||||
|
$query->where('depot_recycle.kitchen_id',$kitchenId);
|
||||||
|
})
|
||||||
|
->paginate($limit,['depot_recycle.*','material.name as material_name','supplier.name as supplier_name','admin_user.chinese_name as operator_name','depot.name as depot_name'])
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return $this->return->success('success',$list);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -470,3 +470,27 @@ GET {{host}}/admin/depot/sale_list?limit=10&query_kitchen_id=1
|
|||||||
content-type: application/json
|
content-type: application/json
|
||||||
Authorization: Bearer {{admin_token}}
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
### 管理员回收商品
|
||||||
|
POST {{host}}/admin/depot/depot_recycle
|
||||||
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
material_id=1&supplier_id=1&number=1&sale_id=2&city_id=1&kitchen_id=1
|
||||||
|
|
||||||
|
### 管理员修改回收数量
|
||||||
|
POST {{host}}/admin/depot/recycle_update
|
||||||
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
id=2&number=2
|
||||||
|
|
||||||
|
### 管理员删除回收
|
||||||
|
POST {{host}}/admin/depot/recycle_delete?id=2
|
||||||
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
### 管理员查看回收列表
|
||||||
|
GET {{host}}/admin/depot/recycle_list?limit=10&query_kitchen_id=1
|
||||||
|
content-type: application/json
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user