Merge branch 'dev' into branch-dev
This commit is contained in:
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);
|
||||
}
|
||||
|
||||
}
|
||||
129
app/Service/Api/Material/DishService.php
Normal file
129
app/Service/Api/Material/DishService.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Material;
|
||||
|
||||
use App\Constants\Common\DishCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Dish;
|
||||
use App\Model\MaterialApplication;
|
||||
use App\Service\Api\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class DishService extends BaseService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Dish
|
||||
*/
|
||||
#[Inject]
|
||||
protected Dish $DishModel;
|
||||
|
||||
#[Inject]
|
||||
protected MaterialApplication $MaterialApplication;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function add(): array
|
||||
{
|
||||
$dish_name = $this->request->input('dish_name');
|
||||
$profile = $this->request->input('profile');
|
||||
$pre_quantity = (int)$this->request->input('pre_quantity');
|
||||
$price = (double)$this->request->input('price');
|
||||
$side_dish = $this->request->input('side_dish');
|
||||
$flavor = $this->request->input('flavor');
|
||||
$date = $this->request->input('date');
|
||||
$city_id = (int)$this->request->input('city_id');
|
||||
$kitchen_id = (int)$this->request->input('kitchen_id');
|
||||
$chef_id = $this->userId;
|
||||
|
||||
$dish = new Dish();
|
||||
$dish ->dish = $dish_name;
|
||||
$dish ->profile = $profile;
|
||||
$dish ->pre_quantity = $pre_quantity;
|
||||
$dish ->price = $price;
|
||||
$dish ->side_dish = $side_dish;
|
||||
$dish ->flavor = $flavor;
|
||||
$dish ->date = $date;
|
||||
$dish ->city_id = $city_id;
|
||||
$dish ->kitchen_id = $kitchen_id;
|
||||
$dish ->chef_id = $chef_id;
|
||||
|
||||
if (!$dish->save()) throw new ErrException('菜品添加失败');
|
||||
|
||||
return $this->return->success('success');
|
||||
}
|
||||
|
||||
public function edit(): array
|
||||
{
|
||||
$dish_id = (int)$this->request->input('id');
|
||||
$dish_name = $this->request->input('dish_name');
|
||||
$profile = $this->request->input('profile');
|
||||
$pre_quantity = (int)$this->request->input('pre_quantity');
|
||||
$price = (double)$this->request->input('price');
|
||||
$side_dish = $this->request->input('side_dish');
|
||||
$flavor = $this->request->input('flavor');
|
||||
|
||||
$info = $this->DishModel->getInfoById($dish_id);
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
|
||||
if (!empty($dish_name)) {
|
||||
$info->dish = $dish_name;
|
||||
}
|
||||
if (!empty($profile)) {
|
||||
$info->profile = $profile;
|
||||
}
|
||||
if (!empty($pre_quantity)) {
|
||||
$info->pre_quantity = $pre_quantity;
|
||||
}
|
||||
if (!empty($price)) {
|
||||
$info->price = $price;
|
||||
}
|
||||
if (!empty($side_dish)) {
|
||||
$info->side_dish = $side_dish;
|
||||
}
|
||||
if (!empty($flavor)) {
|
||||
$info->flavor = $flavor;
|
||||
}
|
||||
if (!$info->save()) throw new ErrException('菜品修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function delete(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$info = $this->DishModel->getInfoById($id);
|
||||
$application = $this->MaterialApplication
|
||||
->where('dish_id', $id)
|
||||
->where('is_del', DishCode::IS_NO_DEL)
|
||||
->first();
|
||||
if (!empty($application)) throw new ErrException('该菜品存在申请材料');
|
||||
|
||||
$info->is_del = DishCode::IS_DELETE;
|
||||
|
||||
if (!$info->save()) throw new ErrException('菜品删除失败');
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
public function list(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit');
|
||||
$chef_id = $this->userId;
|
||||
$list = $this->DishModel
|
||||
->where('chef_id', $chef_id)
|
||||
->orderBy('date','desc')
|
||||
->paginate($limit)->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
}
|
||||
131
app/Service/Api/Material/MaterialService.php
Normal file
131
app/Service/Api/Material/MaterialService.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Material;
|
||||
|
||||
use App\Constants\Common\MaterialCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Material;
|
||||
use App\Model\MaterialApplication;
|
||||
use App\Service\Api\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class MaterialService extends BaseService{
|
||||
|
||||
/**
|
||||
* @var Material
|
||||
*/
|
||||
#[Inject]
|
||||
protected Material $MaterialModel;
|
||||
|
||||
#[Inject]
|
||||
protected MaterialApplication $MaterialApplication;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function materialList(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$name = $this->request->input('query_name');
|
||||
$kitchenId = $this->request->input('query_kitchen_id');
|
||||
|
||||
$list = $this
|
||||
->MaterialModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('status',MaterialCode::ENABLE)
|
||||
->when(!empty($name), function ($query) use ($name) {
|
||||
$query->where('name', 'like', "%$name%");
|
||||
})
|
||||
->when(!empty($kitchenId), function ($query) use ($kitchenId) {
|
||||
$query->where('kitchen_id', $kitchenId);
|
||||
})
|
||||
->paginate($limit,['bar_code','name','unit','standard'])
|
||||
->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
public function materialApplication(): array
|
||||
{
|
||||
$material_id = (int)$this->request->input('material_id');
|
||||
$dish_id = (int)$this->request->input('dish_id');
|
||||
$number = (double)$this->request->input('number');
|
||||
$processing = $this->request->input('processing');
|
||||
$status = MaterialCode::UN_AUDIT;
|
||||
$city_id = (int)$this->request->input('city_id');
|
||||
$kitchen_id = (int)$this->request->input('kitchen_id');
|
||||
|
||||
$materialApplication = new MaterialApplication();
|
||||
$materialApplication->material_id = $material_id;
|
||||
$materialApplication->dish_id = $dish_id;
|
||||
$materialApplication->number = $number;
|
||||
$materialApplication->processing = $processing;
|
||||
$materialApplication->status = $status;
|
||||
$materialApplication->city_id = $city_id;
|
||||
$materialApplication->kitchen_id = $kitchen_id;
|
||||
$materialApplication->operator_id = $this->userId;
|
||||
|
||||
if (!$materialApplication->save())
|
||||
throw new ErrException('申请失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function applicationEdit(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$number = (int)$this->request->input('number');
|
||||
$processing = $this->request->input('processing');
|
||||
|
||||
$info = $this->MaterialApplication->getInfoById($id);
|
||||
|
||||
if (!empty($number)){
|
||||
$info->number = $number;
|
||||
if($number < $info->al_number){
|
||||
throw new ErrException('申请数量不能小于出库数量');
|
||||
}
|
||||
}
|
||||
if (!empty($processing)){
|
||||
$info->processing = $processing;
|
||||
}
|
||||
if($info->status == MaterialCode::AUDIT_REFUSE){
|
||||
$info->status = MaterialCode::UN_AUDIT;
|
||||
}
|
||||
|
||||
if (!$info->save()) throw new ErrException('申请修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function applicationDelete(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$info = $this->MaterialApplication->getInfoById($id);
|
||||
$info->is_del = 2;
|
||||
if ($info->status == MaterialCode::ALL_OUT || $info->status == MaterialCode::PART_OUT) throw new ErrException("已进行出库");
|
||||
if (!$info->save()) throw new ErrException('材料有出库,申请删除失败');
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function applicationList(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$dishId = (int)$this->request->input('dish_id');
|
||||
$list = $this->MaterialApplication
|
||||
->leftJoin('material', 'material.id', '=', 'material_id')
|
||||
->leftJoin('dish', 'dish.id', '=', 'dish_id')
|
||||
->leftJoin('admin_user', 'admin_user.id', '=', 'operator_id')
|
||||
->where('material_application.is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('material_application.operator_id', $this->userId)
|
||||
->where('material_application.dish_id', $dishId)
|
||||
->paginate($limit,['material_application.*','material.name as material_name','dish.dish as dish_name','admin_user.chinese_name as operator_name'])
|
||||
->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user