feat:material_application
This commit is contained in:
@@ -5,7 +5,9 @@ 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;
|
||||
|
||||
@@ -17,6 +19,9 @@ class MaterialService extends BaseService{
|
||||
#[Inject]
|
||||
protected Material $MaterialModel;
|
||||
|
||||
#[Inject]
|
||||
protected MaterialApplication $MaterialApplication;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -39,6 +44,80 @@ class MaterialService extends BaseService{
|
||||
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 = (int)$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->num = $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');
|
||||
$material_id = (int)$this->request->input('material_id');
|
||||
$dish_id = (int)$this->request->input('dish_id');
|
||||
$number = (int)$this->request->input('number');
|
||||
$processing = $this->request->input('processing');
|
||||
|
||||
$info = $this->MaterialApplication->getInfoById($id);
|
||||
|
||||
if (!empty($material_id)){
|
||||
$info->material_id = $material_id;
|
||||
}
|
||||
if (!empty($dish_id)){
|
||||
$info->dish_id = $dish_id;
|
||||
}
|
||||
if (!empty($number)){
|
||||
$info->num = $number;
|
||||
}
|
||||
if (!empty($processing)){
|
||||
$info->processing = $processing;
|
||||
}
|
||||
$info->operator_id = $this->userId;
|
||||
|
||||
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) throw new ErrException("已全部出库");
|
||||
if (!$info->save()) throw new ErrException('申请删除失败');
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function applicationList(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$list = $this->MaterialApplication
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('id', $this->userId)
|
||||
->paginate($limit)->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user