feat:dish depot
This commit is contained in:
17
app/Constants/Admin/DepotCode.php
Normal file
17
app/Constants/Admin/DepotCode.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Constants\Admin;
|
||||
|
||||
use Hyperf\Constants\AbstractConstants;
|
||||
use Hyperf\Constants\Annotation\Constants;
|
||||
|
||||
#[Constants]
|
||||
class DepotCode extends AbstractConstants
|
||||
{
|
||||
/***
|
||||
* @var int 1=未删除 2=已删除
|
||||
*/
|
||||
const int IS_NO_DEL = 1;
|
||||
|
||||
const int IS_DEL = 2;
|
||||
}
|
||||
13
app/Constants/Common/DishCode.php
Normal file
13
app/Constants/Common/DishCode.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Constants\Common;
|
||||
|
||||
class DishCode
|
||||
{
|
||||
/***
|
||||
* @var int 1=未删除 2=已删除
|
||||
*/
|
||||
const int IS_NO_DEL = 1;
|
||||
const int IS_DELETE = 2;
|
||||
|
||||
}
|
||||
69
app/Controller/Admin/DepotController.php
Normal file
69
app/Controller/Admin/DepotController.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Middleware\Admin\JwtAuthMiddleware;
|
||||
use App\Request\Admin\DepotRequest;
|
||||
use App\Service\Admin\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: 'admin/depot')]
|
||||
#[Middlewares([
|
||||
JwtAuthMiddleware::class,
|
||||
])]
|
||||
class DepotController
|
||||
{
|
||||
|
||||
/**
|
||||
* 仓库列表
|
||||
* @param DepotRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "depot_list", methods: "GET")]
|
||||
#[Scene(scene: "depot_list")]
|
||||
public function list(DepotRequest $request): array
|
||||
{
|
||||
return (new DepotService)->depotList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加仓库
|
||||
* @param DepotRequest $request
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
#[RequestMapping(path: "depot_add", methods: "POST")]
|
||||
#[Scene(scene: "depot_add")]
|
||||
public function add(DepotRequest $request): array
|
||||
{
|
||||
return (new DepotService)->add();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改仓库
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "depot_edit", methods: "POST")]
|
||||
#[Scene(scene: "depot_edit")]
|
||||
public function edit(DepotRequest $request): array
|
||||
{
|
||||
return (new DepotService)->edit();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除仓库
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "depot_delete", methods: "GET")]
|
||||
#[Scene(scene: "depot_delete")]
|
||||
public function delete(DepotRequest $request): array
|
||||
{
|
||||
return (new DepotService)->delete();
|
||||
}
|
||||
}
|
||||
33
app/Controller/Admin/DishController.php
Normal file
33
app/Controller/Admin/DishController.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Middleware\Admin\JwtAuthMiddleware;
|
||||
use App\Request\Admin\DishRequest;
|
||||
use App\Service\Admin\Good\DishService;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\Validation\Annotation\Scene;
|
||||
|
||||
#[Controller(prefix: 'admin/dish')]
|
||||
#[Middlewares([
|
||||
JwtAuthMiddleware::class,
|
||||
])]
|
||||
class DishController
|
||||
{
|
||||
/**
|
||||
* @param DishRequest $request
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path: "list", methods: "GET")]
|
||||
#[Scene(scene: "list")]
|
||||
public function list(DishRequest $request): array
|
||||
{
|
||||
return (new DishService)->dishList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
59
app/Model/Depot.php
Normal file
59
app/Model/Depot.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Constants\Admin\DepotCode;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property int $city_id
|
||||
* @property int $kitchen_id
|
||||
* @property int $is_del
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
class Depot extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'depot';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'is_del' => 'integer'];
|
||||
|
||||
const CREATED_AT = 'create_time';
|
||||
|
||||
const UPDATED_AT = 'update_time';
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return \Hyperf\Database\Model\Model|Builder|null
|
||||
*/
|
||||
public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('id',$id)->where('is_del',DepotCode::IS_NO_DEL)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param int $kitchen_id
|
||||
* @return \Hyperf\Database\Model\Model|Builder|null
|
||||
*/
|
||||
public function getInfoByName(string $name,int $kitchen_id): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('name', $name)->where('kitchen_id',$kitchen_id)->where('is_del',DepotCode::IS_NO_DEL)->first();
|
||||
}
|
||||
}
|
||||
46
app/Model/Dish.php
Normal file
46
app/Model/Dish.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $dish
|
||||
* @property string $profile
|
||||
* @property int $pre_quantity
|
||||
* @property string $price
|
||||
* @property string $side_dish
|
||||
* @property string $flavor
|
||||
* @property int $cycle_id
|
||||
* @property int $status
|
||||
* @property int $city_id
|
||||
* @property int $kitchen_id
|
||||
* @property int $chef_id
|
||||
* @property int $is_del
|
||||
* @property string $create_time
|
||||
* @property string $update_time
|
||||
*/
|
||||
class Dish extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'dish';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'pre_quantity' => 'integer', 'cycle_id' => 'integer', 'status' => 'integer', 'city_id' => 'integer','kitchen_id' => 'integer', 'chef_id' => 'integer', 'is_del' => 'integer'];
|
||||
|
||||
const string CREATED_AT = 'create_time';
|
||||
|
||||
const string UPDATED_AT = 'update_time';
|
||||
}
|
||||
41
app/Request/Admin/DepotRequest.php
Normal file
41
app/Request/Admin/DepotRequest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request\Admin;
|
||||
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class DepotRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'limit' => 'required|integer',
|
||||
'query_id' => 'sometimes|integer',
|
||||
'query_kitchen_id' => 'sometimes|integer',
|
||||
'name' => 'required|string',
|
||||
'city_id' => 'required|integer|exists:system_city,id',
|
||||
'kitchen_id' => 'required|integer|exists:kitchen,id',
|
||||
'id' => 'required|integer',
|
||||
];
|
||||
}
|
||||
|
||||
protected array $scenes = [
|
||||
'depot_list' => ['limit','query_id','query_kitchen_id'],
|
||||
'depot_add' => ['name','city_id','kitchen_id'],
|
||||
'depot_edit' => ['id','name','city_id','kitchen_id'],
|
||||
'depot_delete' => ['id'],
|
||||
];
|
||||
}
|
||||
39
app/Request/Admin/DishRequest.php
Normal file
39
app/Request/Admin/DishRequest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request\Admin;
|
||||
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class DishRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'limit' => 'required|integer',
|
||||
'query_id' => 'sometimes|integer',
|
||||
'query_dish_name' => 'sometimes|string',
|
||||
'query_city_id' => 'sometimes|integer|exists:system_city,id',
|
||||
'query_date_id' => 'sometimes|integer|exists:cycle,id',
|
||||
'query_status' => 'sometimes|integer',
|
||||
'query_chef_id' => 'sometimes|integer',
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
protected array $scenes = [
|
||||
'list' => ['limit','query_id','query_dish_name','query_city_id','query_date_id','query_status','query_chef_id'],
|
||||
];
|
||||
}
|
||||
114
app/Service/Admin/Depot/DepotService.php
Normal file
114
app/Service/Admin/Depot/DepotService.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Depot;
|
||||
|
||||
use App\Constants\Admin\DepotCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Depot;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class DepotService extends BaseService{
|
||||
|
||||
/**
|
||||
* @var Depot
|
||||
*/
|
||||
#[Inject]
|
||||
protected Depot $DepotModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function depotList():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->DepotModel
|
||||
->where('is_del',DepotCode::IS_NO_DEL)
|
||||
->when($id,function ($query) use ($id) {
|
||||
$query->where('id',$id);
|
||||
})
|
||||
->when($kitchenId,function ($query) use ($kitchenId) {
|
||||
$query->where('kitchen_id',$kitchenId);
|
||||
})
|
||||
->paginate($limit)->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function add():array
|
||||
{
|
||||
$name = $this->request->input('name');
|
||||
$kitchen_id = (int)$this->request->input('kitchen_id');
|
||||
$info = $this->DepotModel->getInfoByName($name,$kitchen_id);
|
||||
if (!empty($info)) throw new ErrException('仓库已存在');
|
||||
|
||||
$depot = new Depot();
|
||||
$depot->name = $name;
|
||||
$depot->city_id = $this->request->input('city_id');
|
||||
$depot->kitchen_id = $kitchen_id;
|
||||
|
||||
if (!$depot->save()) throw new ErrException('仓库添加失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function edit(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$depotName = $this->request->input('name');
|
||||
$kitchen_id = (int)$this->request->input('kitchen_id');
|
||||
|
||||
$info = $this->DepotModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
|
||||
$name = $this->DepotModel->getInfoByName($depotName,$kitchen_id);
|
||||
if (!empty($name)){
|
||||
if ($name->id != $info->id && $info->kitchen_id == $kitchen_id)
|
||||
throw new ErrException('仓库已存在');
|
||||
}
|
||||
|
||||
$info->name = $depotName;
|
||||
$info->city_id = (int)$this->request->input('city_id');
|
||||
$info->kitchen_id = $kitchen_id;
|
||||
|
||||
if (!$info->save()) throw new ErrException('仓库修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function delete(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->DepotModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('仓库不存在');
|
||||
|
||||
$info->is_del = DepotCode::IS_DEL;
|
||||
|
||||
if (!$info->save()) throw new ErrException('删除失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
64
app/Service/Admin/Good/DishService.php
Normal file
64
app/Service/Admin/Good/DishService.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Good;
|
||||
|
||||
use App\Constants\Common\DishCode;
|
||||
use App\Model\Dish;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class DishService extends BaseService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Dish
|
||||
*/
|
||||
#[Inject]
|
||||
protected Dish $DishModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dishList(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$id = (int)$this->request->input('query_id');
|
||||
$cityId = (int)$this->request->input('query_city_id',0);
|
||||
$dishName = $this->request->input('query_dish_name');
|
||||
$dateId = (int)$this->request->input('query_date_id');
|
||||
$status = (int)$this->request->input('query_status');
|
||||
$chefId = (int)$this->request->input('query_chef_id',0);
|
||||
|
||||
$list = $this->DishModel
|
||||
->where('is_del',DishCode::IS_NO_DEL)
|
||||
->when($id > 0, function ($query) use ($id) {
|
||||
$query->where('id', $id);
|
||||
})
|
||||
->when($cityId > 0, function ($query) use ($cityId) {
|
||||
$query->where('city_id', $cityId);
|
||||
})
|
||||
->when($dishName, function ($query) use ($dishName) {
|
||||
$query->where('dish', 'like', "$dishName%");
|
||||
})
|
||||
->when($dateId, function ($query) use ($dateId) {
|
||||
$query->where('cycle_id', $dateId);
|
||||
})
|
||||
->when($status, function ($query) use ($status) {
|
||||
$query->where('status', $status);
|
||||
})
|
||||
->when($chefId, function ($query) use ($chefId) {
|
||||
$query->where('chef_id', $chefId);
|
||||
})
|
||||
->paginate($limit)->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -276,3 +276,31 @@ GET {{host}}/admin/member/list?limit=10
|
||||
content-type: application/json
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 排菜列表
|
||||
GET {{host}}/admin/dish/list?limit=10
|
||||
content-type: application/json
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 仓库列表
|
||||
GET {{host}}/admin/depot/depot_list?limit=10
|
||||
content-type: application/json
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 仓库添加
|
||||
POST {{host}}/admin/depot/depot_add
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
name=蔬菜仓库&city_id=1&kitchen_id=1
|
||||
|
||||
### 仓库修改信息
|
||||
POST {{host}}/admin/depot/depot_edit
|
||||
content-type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
id=2&name=冻品仓库&city_id=1&kitchen_id=1
|
||||
|
||||
### 仓库删除
|
||||
GET {{host}}/admin/depot/depot_delete?id=2
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
Reference in New Issue
Block a user