feat:depot_recycle
This commit is contained in:
@@ -219,4 +219,16 @@ class DepotController
|
||||
{
|
||||
return (new DepotService)->recycleList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 回收审核
|
||||
* @param DepotRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "recycle_audit", methods: "POST")]
|
||||
#[Scene(scene: "recycle_audit")]
|
||||
public function recycleAudit(DepotRequest $request): array
|
||||
{
|
||||
return (new DepotService)->recycleAudit();
|
||||
}
|
||||
}
|
||||
|
||||
73
app/Controller/Api/DepotController.php
Normal file
73
app/Controller/Api/DepotController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\Middleware\Api\JwtAuthMiddleware;
|
||||
use App\Request\Admin\DepotRequest;
|
||||
use App\Service\Api\Depot\DepotService;
|
||||
use Exception;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
#[Controller(prefix: 'api/depot')]
|
||||
#[Middlewares([
|
||||
JwtAuthMiddleware::class,
|
||||
])]
|
||||
class DepotController
|
||||
{
|
||||
/**
|
||||
* 回收
|
||||
* @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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
@@ -43,4 +44,9 @@ class DepotRecycle extends Model
|
||||
const string CREATED_AT = 'create_time';
|
||||
|
||||
const string UPDATED_AT = 'update_time';
|
||||
|
||||
public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('id', $id)->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
@@ -44,4 +45,9 @@ class DepotSale extends Model
|
||||
const string CREATED_AT = 'create_time';
|
||||
|
||||
const string UPDATED_AT = 'update_time';
|
||||
|
||||
public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('id', $id)->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ class DepotRequest extends FormRequest
|
||||
'supplier_id' => 'required|integer|exists:supplier,id',
|
||||
'application_id' => 'required|integer|exists:material_application,id',
|
||||
'sale_id' => 'required|integer|exists:depot_sale,id',
|
||||
'status' => 'required|integer',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -56,5 +57,6 @@ class DepotRequest extends FormRequest
|
||||
'recycle_update' => ['id','number'],
|
||||
'recycle_delete' => ['id'],
|
||||
'recycle_list' => ['limit','query_id','query_kitchen_id'],
|
||||
'recycle_audit' => ['id','status'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -484,7 +484,10 @@ class DepotService extends BaseService{
|
||||
throw new ErrException('回收数量不能大于出库数量');
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->getMaterial($materialId,$depotId,$supplierId);
|
||||
->where('material_id',$materialId)
|
||||
->where('depot_id',$depotId)
|
||||
->where('supplier_id',$supplierId)
|
||||
->first();
|
||||
|
||||
$depotRecycle = new DepotRecycle();
|
||||
$depotRecycle->depot_id = $depotId;
|
||||
@@ -534,7 +537,10 @@ class DepotService extends BaseService{
|
||||
$info->sum_price = $sum_price;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->getMaterial($info->material_id,$info->depot_id,$info->supplier_id);
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = $materialStock->current_stock + $number - $old_number;
|
||||
|
||||
@@ -543,6 +549,8 @@ class DepotService extends BaseService{
|
||||
->first();
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number + $number - $old_number;
|
||||
if ($saleInfo->back_number > $saleInfo->number)
|
||||
throw new ErrException('回收数量不能大于出库数量');
|
||||
|
||||
if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) throw new ErrException('商品回收数量修改失败');
|
||||
|
||||
@@ -564,7 +572,10 @@ class DepotService extends BaseService{
|
||||
$info->is_del = MaterialCode::IS_DEL;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->getMaterial($info->material_id,$info->depot_id,$info->supplier_id);
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = $materialStock->current_stock - $info->number;
|
||||
|
||||
@@ -586,6 +597,9 @@ class DepotService extends BaseService{
|
||||
$id = (int)$this->request->input('query_id');
|
||||
$kitchenId = (int)$this->request->input('query_kitchen_id');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$list = $this->DepotRecycleModel
|
||||
->leftJoin('depot','depot_recycle.depot_id','=','depot.id')
|
||||
->leftJoin('material','depot_recycle.material_id','=','material.id')
|
||||
@@ -604,4 +618,78 @@ class DepotService extends BaseService{
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
public function recycleAudit():array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$status = (int)$this->request->input('status');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$info = $this->DepotRecycleModel
|
||||
->where('id',$id)
|
||||
->first();
|
||||
|
||||
if ($info->status != MaterialCode::AUDITED){
|
||||
if ($status == MaterialCode::AUDITED){
|
||||
$saleInfo = $this->DepotSaleModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('id',$info->sale_id)
|
||||
->first();
|
||||
|
||||
if (empty($saleInfo)){
|
||||
throw new ErrException('无出库记录');
|
||||
}
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number + $info->number;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
if (empty($materialStock)){
|
||||
$materialStock = new MaterialStock();
|
||||
$materialStock->depot_id = $info->depotId;
|
||||
$materialStock->material_id = $info->materialId;
|
||||
$materialStock->supplier_id = $info->supplierId;
|
||||
$materialStock->current_stock = $info->number;
|
||||
$materialStock->unit_price = $info->recycle_price;
|
||||
}
|
||||
else
|
||||
$materialStock->current_stock = $materialStock->current_stock + $info->number;
|
||||
|
||||
if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常');
|
||||
|
||||
}
|
||||
}
|
||||
if ($info->status == MaterialCode::AUDITED){
|
||||
if ($status == MaterialCode::UN_AUDIT || $status == MaterialCode::AUDIT_REFUSE){
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$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 (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常');
|
||||
}
|
||||
}
|
||||
|
||||
$info->status = $status;
|
||||
|
||||
if (!$info->save()) throw new ErrException('回收审核异常');
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
}
|
||||
139
app/Service/Api/Depot/DepotService.php
Normal file
139
app/Service/Api/Depot/DepotService.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Depot;
|
||||
|
||||
use App\Constants\Common\MaterialCode;
|
||||
use App\Constants\Common\RoleCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Depot;
|
||||
use App\Model\DepotRecycle;
|
||||
use App\Model\DepotSale;
|
||||
use App\Model\MaterialStock;
|
||||
use App\Service\Api\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class DepotService extends BaseService{
|
||||
|
||||
#[Inject]
|
||||
protected Depot $DepotModel;
|
||||
|
||||
#[Inject]
|
||||
protected DepotSale $DepotSaleModel;
|
||||
|
||||
#[Inject]
|
||||
protected DepotRecycle $DepotRecycleModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
$saleInfo = $this->DepotSaleModel->getInfoById($saleId);
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number + $number;
|
||||
if ($saleInfo->back_number > $saleInfo->number)
|
||||
throw new ErrException('回收数量不能大于出库数量');
|
||||
|
||||
$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::UN_AUDIT;
|
||||
$depotRecycle->city_id = $cityId;
|
||||
$depotRecycle->kitchen_id = $kitchenId;
|
||||
$depotRecycle->operator_id = $this->userId;
|
||||
|
||||
if (!$depotRecycle->save()) throw new ErrException('回收发生异常');
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
public function recycleUpdate():array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$number = (double)$this->request->input('number');
|
||||
|
||||
$info = $this->DepotRecycleModel->getInfoById($id);
|
||||
|
||||
if ($info->status == MaterialCode::AUDITED) throw new ErrException('记录已审核通过');
|
||||
|
||||
$old_number = $info->number;
|
||||
$sum_price = $info->recycle_price * $number;
|
||||
$info->number = $number;
|
||||
$info->sum_price = $sum_price;
|
||||
$info->status = MaterialCode::UN_AUDIT;
|
||||
|
||||
$saleInfo = $this->DepotSaleModel->getInfoById($info->sale_id);
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number + $number - $old_number;
|
||||
if ($saleInfo->back_number > $saleInfo->number) throw new ErrException('回收数量不能大于出库数量');
|
||||
|
||||
if (!$info->save()) throw new ErrException('商品回收数量修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
public function recycleDelete():array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->DepotRecycleModel->getInfoById($id);
|
||||
if ($info->status == MaterialCode::AUDITED) throw new ErrException('该记录已审核通过');
|
||||
|
||||
$info->is_del = MaterialCode::IS_DEL;
|
||||
|
||||
if (!$info->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)
|
||||
->where('depot_recycle.operator_id',$this->userId)
|
||||
->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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -485,7 +485,7 @@ Authorization: Bearer {{admin_token}}
|
||||
id=2&number=2
|
||||
|
||||
### 管理员删除回收
|
||||
POST {{host}}/admin/depot/recycle_delete?id=2
|
||||
POST {{host}}/admin/depot/recycle_delete?id=3
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
@@ -494,3 +494,34 @@ GET {{host}}/admin/depot/recycle_list?limit=10&query_kitchen_id=1
|
||||
content-type: application/json
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 管理员审核回收
|
||||
POST {{host}}/admin/depot/recycle_audit
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
id=3&status=2
|
||||
|
||||
### 厨师回收商品
|
||||
POST {{host}}/api/depot/depot_recycle
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
material_id=1&supplier_id=1&number=3&sale_id=2&city_id=1&kitchen_id=1
|
||||
|
||||
### 厨师修改回收数量
|
||||
POST {{host}}/api/depot/recycle_update
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
id=3&number=3
|
||||
|
||||
### 厨师删除回收
|
||||
POST {{host}}/api/depot/recycle_delete?id=3
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 厨师查看回收列表
|
||||
GET {{host}}/api/depot/recycle_list?limit=10&query_kitchen_id=1
|
||||
content-type: application/json
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user