feat: 添加对应成本分类树接口
This commit is contained in:
34
app/admin/controller/v1/ProductTcoCategory.php
Normal file
34
app/admin/controller/v1/ProductTcoCategory.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
declare (strict_types = 1);
|
||||||
|
|
||||||
|
namespace app\admin\controller\v1;
|
||||||
|
|
||||||
|
use app\admin\model\v1\ProductTcoCategoryModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品 - 产品目录分类控制器
|
||||||
|
*/
|
||||||
|
class ProductTcoCategory
|
||||||
|
{
|
||||||
|
// 分类树
|
||||||
|
public function tree()
|
||||||
|
{
|
||||||
|
$param = request()->param(['name']);
|
||||||
|
|
||||||
|
$categorys = ProductTcoCategoryModel::field([
|
||||||
|
'tco_id' => 'id',
|
||||||
|
'tco_pid' => 'pid',
|
||||||
|
'name',
|
||||||
|
])
|
||||||
|
->withSearch(['name'], [
|
||||||
|
'name' => $param['name'] ?? null,
|
||||||
|
])
|
||||||
|
->language(request()->lang_id)
|
||||||
|
->enabled()
|
||||||
|
->order(['id' => 'asc'])
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return success('获取成功', array_to_tree($categorys, 0, 'pid', false));
|
||||||
|
}
|
||||||
|
}
|
||||||
40
app/admin/model/v1/ProductTcoCategoryModel.php
Normal file
40
app/admin/model/v1/ProductTcoCategoryModel.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
declare (strict_types = 1);
|
||||||
|
|
||||||
|
namespace app\admin\model\v1;
|
||||||
|
|
||||||
|
use app\common\model\ProductTcoCategoryBaseModel;
|
||||||
|
use think\model\concern\SoftDelete;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品 - 产品目录分类同步记录模型
|
||||||
|
* @mixin \think\Model
|
||||||
|
*/
|
||||||
|
class ProductTcoCategoryModel extends ProductTcoCategoryBaseModel
|
||||||
|
{
|
||||||
|
// 启用软删除
|
||||||
|
use SoftDelete;
|
||||||
|
// 软删除字段
|
||||||
|
protected $deleteTime = 'deleted_at';
|
||||||
|
|
||||||
|
// 根据语言查询
|
||||||
|
public function scopeLanguage($query, $value)
|
||||||
|
{
|
||||||
|
$query->where('language_id', '=', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按分类名称搜索
|
||||||
|
public function searchNameAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
if (is_null($value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$query->where('name', 'like', "%{$value}%");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只查询启用的
|
||||||
|
public function scopeEnabled($query)
|
||||||
|
{
|
||||||
|
$query->where('disabled', '=', 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -269,7 +269,10 @@ Route::group('v1', function () {
|
|||||||
|
|
||||||
// 产品分类
|
// 产品分类
|
||||||
Route::group('category', function () {
|
Route::group('category', function () {
|
||||||
// 分类列表
|
// tco分类树
|
||||||
|
Route::get('tco/tree', 'ProductTcoCategory/tree');
|
||||||
|
|
||||||
|
// 分类树
|
||||||
Route::get('index', 'ProductCategory/index');
|
Route::get('index', 'ProductCategory/index');
|
||||||
|
|
||||||
// 分类详情
|
// 分类详情
|
||||||
|
|||||||
Reference in New Issue
Block a user