feat 添加一级类目和二级类目接口

This commit is contained in:
lwh 2023-07-01 15:21:08 +08:00
parent 88462eb8e4
commit e37aeee1be
2 changed files with 89 additions and 83 deletions

View File

@ -19,104 +19,64 @@ use think\facade\Env;
class CodeModuleCategory extends BaseController
{
/**
* 获取代码块类目列表
* 获取一级类目列表
*/
public function getCodeModuleCategoryList(Request $request)
public function getCodeModuleFirstCategoryList(Request $request)
{
$params = $request->param();
$con = Tool::getOptionalQuery(
['cmc.code_module_category_name', 'LIKE'],
['cmc.code_module_category_ps', 'LIKE'],
['cmc.code_module_category_library_type', '='],
['cust.customer_name|cust.customer_account', 'LIKE', 'customer'],
['cmc.code_module_category_audit', '='],
);
$con[] = ['a.code_module_category_audit', '=', '2'];
// 筛选已审核
$con[] = ['cmc.code_module_category_audit','=','2'];
if (isset($params['code_module_category_global_mode']) && $params['code_module_category_global_mode']) {
$con[] = ['cmc.code_module_category_global_mode', 'REGEXP', implode('|', $params['code_module_category_global_mode'])];
}
$query = ModelCodeModuleCategory::alias('a')->field([
'a.code_module_category_guid' => 'guid',
'a.code_module_category_name' => 'name',
'a.code_module_category_ps' => 'tips',
'a.code_module_category_sort' => 'sort',
'a.code_module_category_global_mode',
'a.code_module_category_library_type',
'c.customer_guid' => 'customer_guid',
'c.customer_name' => 'customer_name',
])
->append(['langHit', 'libraryType'])
->hidden(['code_module_category_global_mode', 'code_module_category_library_type'])
->leftjoin('customer c', 'a.customer_guid = c.customer_guid')
->where($con)
->where('a.code_module_category_parent_guid', 0)->select();
$tree_data = [];
//只针对主级类目进行的分页处理
$query = ModelCodeModuleCategory::alias('cmc')->leftjoin('customer cust', 'cmc.customer_guid = cust.customer_guid')
->scope('master')->where($con);
$module_category_guids = self::pageWrapper($query)->column('code_module_category_guid');
if ($module_category_guids) {
//分页后的主级类目开始构建树形结构(此时才会获取到各个父级类目所包含的子级类目)
$data = ModelCodeModuleCategory::alias('cmc')
->whereOr([
['cmc.code_module_category_guid', 'in', $module_category_guids],
['cmc.code_module_category_parent_guid', 'in', $module_category_guids],
])->field([
'cmc.code_module_category_id',
'cmc.code_module_category_guid',
'cmc.customer_guid',
'cmc.code_module_category_audit',
'cmc.code_module_category_sort',
'cmc.code_module_category_parent_guid',
'cmc.code_module_category_name',
'cmc.code_module_category_audit',
'cmc.code_module_category_global_mode',
'cmc.code_module_category_library_type',
'cmc.code_module_category_ps',
'cmcp.code_module_category_name' => "code_module_category_parent_name",
'cust.customer_name',
])
->leftjoin('code_module_category cmcp', 'cmc.code_module_category_parent_guid = cmcp.code_module_category_guid')
->leftjoin('customer cust', 'cmc.customer_guid = cust.customer_guid')
->order('code_module_category_sort')
->select()
->toArray();
$Traverse = new Traverse('code_module_category_guid', 'code_module_category_parent_guid');
$tree_data = $Traverse->tree($data, ModelCodeModuleCategory::MASTER_DEFAULT, function ($v) {
return [
'guid' => $v['code_module_category_guid'],
'name' => $v['code_module_category_name'],
'parent_name' => $v['code_module_category_parent_name'],
'parent_guid' => $v['code_module_category_parent_guid'],
'tips' => $v['code_module_category_ps'],
'sort' => $v['code_module_category_sort'],
'langHit' => $v['code_module_category_global_mode'],
'code_module_category_library_type' => $v['code_module_category_library_type'],
'customer_guid' => $v['customer_guid'],
'customer_name' => $v['customer_name'],
];
});
}
return msg(0, "获取代码块类目列表成功!", [
return msg(0, "获取一级类目列表成功!", [
'count' => $query->count(),
'data' => $tree_data,
'data' => $query,
]);
}
/**
* 获取代码块类目详情
* 获取当前一级类目的二级类目列表
*/
public function getCodeModuleCategoryInfo(Request $request): array
public function getCodeModuleSecondCategoryList(Request $request)
{
$params = $request->param();
$this->validate($params, ['code_module_category_guid' => 'require']);
$this->validate($params, ['code_module_category_guid|当前类目guid' => 'require']);
$find = ModelCodeModuleCategory::field([
'code_module_category_id',
'code_module_category_guid',
'code_module_category_name',
'code_module_category_ps',
'code_module_category_parent_guid',
'code_module_category_sort',
'code_module_category_global_mode',
'code_module_category_library_type',
'customer_guid',
'code_module_category_audit'
$con[] = ['a.code_module_category_audit', '=', '2'];
$query = ModelCodeModuleCategory::alias('a')->field([
'a.code_module_category_guid' => 'guid',
'a.code_module_category_name' => 'name',
'a.code_module_category_ps' => 'tips',
'a.code_module_category_sort' => 'sort',
'a.code_module_category_global_mode',
'a.code_module_category_library_type',
'c.customer_guid' => 'customer_guid',
'c.customer_name' => 'customer_name',
])
->where('code_module_category_guid', $params['code_module_category_guid'])
->find();
->append(['langHit', 'libraryType'])
->hidden(['code_module_category_global_mode', 'code_module_category_library_type'])
->leftjoin('customer c', 'a.customer_guid = c.customer_guid')
->where($con)->where('code_module_category_parent_guid', $params['code_module_category_guid'])
->select();
return msg(0, '获取代码块类目详情成功!', ['data' => $find]);
return msg(0, "获取当前一级类目的二级类目列表成功!", [
'count' => $query->count(),
'data' => $query,
]);
}
}

View File

@ -10,6 +10,7 @@ use app\Request;
use app\common\exception\Tool;
use think\facade\Db;
use app\common\model\Token as ModelToken;
use app\common\model\Dictionary\Dictionary as ModelDictionary;
use app\common\logic\Code\CodeModuleCategory as CommonLogicCodeModuleCategory;
class CodeModuleCategory extends BaseModel
@ -169,4 +170,49 @@ class CodeModuleCategory extends BaseModel
{
$query->where('code_module_category.code_module_category_parent_guid', '!=', self::MASTER_DEFAULT);
}
}
/**
* 获取命中模型模式名称
*
* @param string $value
* @return array
* @date 2023-07-01
* @author lwh
* @since 1.0.0
*/
public function getLangHitAttr($value, $data)
{
$mode = $data['code_module_category_global_mode'];
$mode_arr = explode(',', $mode);
$mode_name_arr = [];
foreach ($mode_arr as $key => $value) {
$global_mode = ModelDictionary::getDictionaryData('global_mode');
$mode_name_arr[] = ModelDictionary::getDataDictionaryName($global_mode, $value);
}
return $mode_name_arr;
}
/**
* 获取库类型名称
*
* @param string $value
* @return array
* @date 2023-07-01
* @author lwh
* @since 1.0.0
*/
public function getLibraryTypeAttr($value,$data)
{
$library = $data['code_module_category_library_type'];
$library_arr = explode(',', $library);
$library_name_arr = [];
foreach ($library_arr as $key => $value) {
$library_type = ModelDictionary::getDictionaryData('library_type');
$library_name_arr[] = ModelDictionary::getDataDictionaryName($library_type, $value);
}
return $library_name_arr;
}
}