All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 3s
139 lines
3.3 KiB
PHP
139 lines
3.3 KiB
PHP
<?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',
|
|
'is_show',
|
|
'page/d' => 1,
|
|
'size/d' => 10
|
|
]);
|
|
|
|
$list = ProductCompatPartsModel::withoutField([
|
|
'language_id',
|
|
'deleted_at'
|
|
])
|
|
->language(request()->lang_id)
|
|
->where(function($query) use($params) {
|
|
if (empty($params['is_show'])) return;
|
|
$query->disabled($params['is_show'] == 1 ? 0 : 1);
|
|
})
|
|
->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("操作成功");
|
|
}
|
|
}
|