131 lines
4.5 KiB
PHP
131 lines
4.5 KiB
PHP
<?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);
|
|
}
|
|
|
|
} |