feat: 新增产品兼容数据、产品兼容数据配件类型相关接口
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 5s
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 5s
This commit is contained in:
133
app/admin/controller/v1/ProductCompatParts.php
Normal file
133
app/admin/controller/v1/ProductCompatParts.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\controller\v1;
|
||||
|
||||
use app\admin\model\v1\ProductCompatPartsModel;
|
||||
use app\admin\validate\v1\ProductCompatPartsValidate;
|
||||
use think\Request;
|
||||
|
||||
class ProductCompatParts
|
||||
{
|
||||
/**
|
||||
* 兼容配件列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$params = request()->param([
|
||||
'name',
|
||||
'page/d' => 1,
|
||||
'size/d' => 10
|
||||
]);
|
||||
|
||||
$list = ProductCompatPartsModel::withoutField([
|
||||
'language_id',
|
||||
'deleted_at'
|
||||
])
|
||||
->language(request()->lang_id)
|
||||
->withSearch('name', [
|
||||
'name' => $params['name']??null
|
||||
])
|
||||
->order(['id' => 'desc'])
|
||||
->paginate([
|
||||
'list_rows' => $params['size'],
|
||||
'page' => $params['page'],
|
||||
]);
|
||||
|
||||
return success('获取成功', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加兼容配件
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$post = request()->post([
|
||||
'name',
|
||||
'sort',
|
||||
'disabled'
|
||||
]);
|
||||
$data = array_merge($post, ['language_id' => request()->lang_id]);
|
||||
|
||||
// 校验输入
|
||||
$validate = new ProductCompatPartsValidate;
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return error($validate->getError());
|
||||
}
|
||||
|
||||
$parts = ProductCompatPartsModel::create($data);
|
||||
if ($parts->isEmpty()) {
|
||||
return error('操作失败');
|
||||
}
|
||||
|
||||
return success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容配件详细
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
$id = request()->param('id');
|
||||
|
||||
$parts = ProductCompatPartsModel::withoutField([
|
||||
'language_id',
|
||||
'deleted_at'
|
||||
])
|
||||
->bypk($id)
|
||||
->find();
|
||||
if (empty($parts)) {
|
||||
return error('获取失败');
|
||||
}
|
||||
|
||||
return success('获取成功', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容配件更新
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$id = request()->param('id');
|
||||
$put = request()->put([
|
||||
'name',
|
||||
'sort',
|
||||
'disabled'
|
||||
]);
|
||||
$data = array_merge($put, ['id' => $id, 'language_id' => request()->lang_id]);
|
||||
|
||||
$validate = new ProductCompatPartsValidate;
|
||||
if (!$validate->scene('edit')->check($data)) {
|
||||
return error($validate->getError());
|
||||
}
|
||||
|
||||
$parts = ProductCompatPartsModel::bypk($id)->find();
|
||||
if (empty($parts)) {
|
||||
return error('请确认操作对象是否正确');
|
||||
}
|
||||
|
||||
if (!$parts->save($put)) {
|
||||
return error('操作失败');
|
||||
}
|
||||
|
||||
return success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容配件删除
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$id = request()->param('id');
|
||||
$parts = ProductCompatPartsModel::bypk($id)->find();
|
||||
if (empty($parts)) {
|
||||
return error('请确认操作对象是否正确');
|
||||
}
|
||||
|
||||
if (!$parts->delete()) {
|
||||
return error("操作失败");
|
||||
}
|
||||
|
||||
return success("操作成功");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user