feat:material_application
This commit is contained in:
@@ -26,4 +26,14 @@ class MaterialCode extends AbstractConstants
|
|||||||
*/
|
*/
|
||||||
const int DISABLE = 2;
|
const int DISABLE = 2;
|
||||||
|
|
||||||
|
const int UN_AUDIT = 1;
|
||||||
|
const int AUDITED = 2;
|
||||||
|
|
||||||
|
const int AUDIT_REFUSE = 3;
|
||||||
|
|
||||||
|
const int PART_OUT = 4;
|
||||||
|
|
||||||
|
const int ALL_OUT = 5;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -30,5 +30,53 @@ class MaterialController
|
|||||||
return (new MaterialService())->materialList();
|
return (new MaterialService())->materialList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请材料
|
||||||
|
* @param MaterialRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "application", methods: "POST")]
|
||||||
|
#[Scene(scene: "material_application")]
|
||||||
|
public function materialApplication(MaterialRequest $request): array
|
||||||
|
{
|
||||||
|
return (new MaterialService())->materialApplication();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改申请材料
|
||||||
|
* @param MaterialRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "application_edit", methods: "POST")]
|
||||||
|
#[Scene(scene: "application_edit")]
|
||||||
|
public function materialApplicationEdit(MaterialRequest $request): array
|
||||||
|
{
|
||||||
|
return (new MaterialService())->applicationEdit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除申请材料
|
||||||
|
* @param MaterialRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "application_delete", methods: "POST")]
|
||||||
|
#[Scene(scene: "application_delete")]
|
||||||
|
public function materialApplicationDelete(MaterialRequest $request): array
|
||||||
|
{
|
||||||
|
return (new MaterialService())->applicationDelete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个人申请材料列表
|
||||||
|
* @param MaterialRequest $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "application_list", methods: "GET")]
|
||||||
|
#[Scene(scene: "application_list")]
|
||||||
|
public function applicationList(MaterialRequest $request): array
|
||||||
|
{
|
||||||
|
return (new MaterialService())->applicationList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
49
app/Model/MaterialApplication.php
Normal file
49
app/Model/MaterialApplication.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Model;
|
||||||
|
|
||||||
|
use Hyperf\Database\Model\Builder;
|
||||||
|
use Hyperf\DbConnection\Model\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property int $material_id
|
||||||
|
* @property int $dish_id
|
||||||
|
* @property int $num
|
||||||
|
* @property string $processing
|
||||||
|
* @property int $status
|
||||||
|
* @property int $city_id
|
||||||
|
* @property int $kitchen_id
|
||||||
|
* @property int $operator_id
|
||||||
|
* @property int $is_del
|
||||||
|
* @property string $create_time
|
||||||
|
* @property string $update_time
|
||||||
|
*/
|
||||||
|
class MaterialApplication extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*/
|
||||||
|
protected ?string $table = 'material_application';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*/
|
||||||
|
protected array $fillable = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that should be cast to native types.
|
||||||
|
*/
|
||||||
|
protected array $casts = ['id' => 'integer', 'material_id' => 'integer', 'dish_id' => 'integer', 'num' => 'integer', 'status' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer'];
|
||||||
|
|
||||||
|
const CREATED_AT = 'create_time';
|
||||||
|
|
||||||
|
const UPDATED_AT = 'update_time';
|
||||||
|
|
||||||
|
public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null
|
||||||
|
{
|
||||||
|
return $this->where('id', $id)->first();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,5 +29,9 @@ class MaterialRequest extends FormRequest
|
|||||||
|
|
||||||
protected array $scenes = [
|
protected array $scenes = [
|
||||||
'material_list' => ['limit','query_name'],
|
'material_list' => ['limit','query_name'],
|
||||||
|
'material_application' => ['material_id','dish_id','number','processing','city_id','kitchen_id'],
|
||||||
|
'application_edit' => ['id','material_id','dish_id','number','processing'],
|
||||||
|
'application_delete' => ['id'],
|
||||||
|
'application_list' => ['limit'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ declare(strict_types=1);
|
|||||||
namespace App\Service\Api\Material;
|
namespace App\Service\Api\Material;
|
||||||
|
|
||||||
use App\Constants\Common\MaterialCode;
|
use App\Constants\Common\MaterialCode;
|
||||||
|
use App\Exception\ErrException;
|
||||||
use App\Model\Material;
|
use App\Model\Material;
|
||||||
|
use App\Model\MaterialApplication;
|
||||||
use App\Service\Api\BaseService;
|
use App\Service\Api\BaseService;
|
||||||
use Hyperf\Di\Annotation\Inject;
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
|
||||||
@@ -17,6 +19,9 @@ class MaterialService extends BaseService{
|
|||||||
#[Inject]
|
#[Inject]
|
||||||
protected Material $MaterialModel;
|
protected Material $MaterialModel;
|
||||||
|
|
||||||
|
#[Inject]
|
||||||
|
protected MaterialApplication $MaterialApplication;
|
||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -39,6 +44,80 @@ class MaterialService extends BaseService{
|
|||||||
return $this->return->success('success',$list);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -413,4 +413,28 @@ id=1&pre_quantity=300&price=12
|
|||||||
### 厨师查看排菜
|
### 厨师查看排菜
|
||||||
GET {{host}}/api/dish/list?limit=10
|
GET {{host}}/api/dish/list?limit=10
|
||||||
content-type: application/json
|
content-type: application/json
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
### 厨师申请材料
|
||||||
|
POST {{host}}/api/material/application
|
||||||
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
material_id=1&dish_id=1&number=50&city_id=1&kitchen_id=1
|
||||||
|
|
||||||
|
### 厨师修改申请材料
|
||||||
|
POST {{host}}/api/material/application_edit
|
||||||
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
id=1&material_id=1&dish_id=1&number=50&processing=切碎
|
||||||
|
|
||||||
|
### 厨师删除申请材料
|
||||||
|
POST {{host}}/api/material/application_delete?id=1
|
||||||
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
### 个人申请材料列表
|
||||||
|
GET {{host}}/api/material/application_list?limit=10
|
||||||
|
content-type: application/json
|
||||||
Authorization: Bearer {{admin_token}}
|
Authorization: Bearer {{admin_token}}
|
||||||
Reference in New Issue
Block a user