fix;TOOL、BaseController文件修改、代码类目查询范围Bug修复、代码类目树形列表接口优化完善
This commit is contained in:
parent
b741270bfa
commit
cfcb7c40e9
@ -9,6 +9,7 @@ use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Request;
|
||||
use think\Validate;
|
||||
use app\common\exception\Tool;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
@ -123,21 +124,14 @@ abstract class BaseController
|
||||
* 分页包装器
|
||||
*
|
||||
* @param $query
|
||||
* @param bool $allowAll 是否全查
|
||||
* @date 2022-03-03
|
||||
* @example
|
||||
* @author admin
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static function pageWrapper($query)
|
||||
protected static function pageWrapper($query, bool $allowAll = true)
|
||||
{
|
||||
$query_copy = (clone $query);
|
||||
if (Request::param('all') === true) {
|
||||
return $query_copy;
|
||||
} else {
|
||||
return $query_copy->page(
|
||||
(int) Request::param('page', 1),
|
||||
(int) Request::param('limit', 10)
|
||||
);
|
||||
}
|
||||
return Tool::pageWrapper($query);
|
||||
}
|
||||
}
|
||||
}
|
@ -30,28 +30,10 @@ class CodeModuleCategory extends BaseController
|
||||
*/
|
||||
public function getCodeModuleCategoryList(Request $request): array
|
||||
{
|
||||
$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', '='],
|
||||
);
|
||||
|
||||
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('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');
|
||||
|
||||
//分页后的主级类目开始构建树形结构(此时才会获取到各个父级类目所包含的子级类目)
|
||||
$tree_data = LogicCodeModuleCategory::buildTreeData($module_category_guids);
|
||||
|
||||
$paging_info = LogicCodeModuleCategory::handleCodeModuleCategoryPaging($request->param());
|
||||
$tree_data = LogicCodeModuleCategory::buildTreeData($paging_info['guids']);
|
||||
return msg(0, "获取代码块类目列表成功!", [
|
||||
'count' => $query->count(),
|
||||
'count' => $paging_info['count'],
|
||||
'data' => $tree_data,
|
||||
]);
|
||||
}
|
||||
|
@ -9,8 +9,54 @@ use app\common\arw\adjfut\src\Traverse;
|
||||
|
||||
class CodeModuleCategory
|
||||
{
|
||||
|
||||
/**
|
||||
* 类目分页处理
|
||||
*
|
||||
* @param array $params 请求参数
|
||||
* @return array ['count' => 总数量 ,'guids' => 分页后的主级类目guid数组]
|
||||
* @date 2023-07-05
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function handleCodeModuleCategoryPaging(array $params): array
|
||||
{
|
||||
$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', '='],
|
||||
);
|
||||
|
||||
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'])];
|
||||
}
|
||||
|
||||
$module_category_guids = [];
|
||||
//【分页处理1】(正常情况)
|
||||
$query = ModelCodeModuleCategory::alias('cmc')->leftjoin('customer cust', 'cmc.customer_guid = cust.customer_guid')->scope('master')->where($con);
|
||||
$module_category_guids = Tool::pageWrapper($query)->column('code_module_category_guid');
|
||||
|
||||
//【分页处理2】(当前查询未审核的类目时,原正常情况分页处理查询不到子类目未审核的数据,此时要走这条查询)
|
||||
//情况:目前查询未审核的类目数据,并且分页处理1未能查出任何数据
|
||||
//该查询会将未审核子类目的所属主类目给查询出来并分页处理
|
||||
if ($params['code_module_category_audit'] == ModelCodeModuleCategory::AUDIT_UNAUDITED) {
|
||||
if (!$module_category_guids) {
|
||||
$query = ModelCodeModuleCategory::alias('cmc')->leftjoin('customer cust', 'cmc.customer_guid = cust.customer_guid')->where($con)->group('code_module_category_parent_guid');
|
||||
$module_category_guids = Tool::pageWrapper($query)->column('code_module_category_parent_guid');
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'count' => $query->count(),
|
||||
'guids' => $module_category_guids
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建代码块类目树形结构数据
|
||||
* 分页后的主级类目开始构建树形结构(此时才会获取到各个父级类目所包含的子级类目)
|
||||
*
|
||||
* @param array $module_category_guids 主类目guid数组
|
||||
* @return array
|
||||
|
@ -9,6 +9,7 @@ use think\helper\Arr;
|
||||
use think\facade\Db;
|
||||
use app\common\exception\Sort;
|
||||
use app\common\arw\adjfut\src\Exception\ErrorMsg;
|
||||
use think\db\Query;
|
||||
|
||||
class Tool
|
||||
{
|
||||
@ -332,11 +333,10 @@ class Tool
|
||||
$order_field_name = null;
|
||||
$order_field_val = null;
|
||||
if (is_array($sort_field_info)) {
|
||||
$order_field_name = $sort_field_info[0];
|
||||
$order_field_val = $sort_field_info[1];
|
||||
} else if (is_int($sort_field_info)) {
|
||||
list($order_field_name, $order_field_val) = $sort_field_info;
|
||||
} else if (is_int($sort_field_info)) {
|
||||
if (!isset($model->order_field)) {
|
||||
throwErrorMsg(__METHOD__ . "若排序字段信息为字符串,则必须要在模型层定义排序字段");
|
||||
throwErrorMsg(__METHOD__ . "若排序字段信息为数字,则必须要在模型层定义排序字段");
|
||||
}
|
||||
$order_field_name = $model->order_field;
|
||||
$order_field_val = $sort_field_info;
|
||||
@ -533,7 +533,28 @@ class Tool
|
||||
foreach ($search_and_replace as $key => $val) {
|
||||
$search[] = $key;
|
||||
$replace[] = $val;
|
||||
};
|
||||
}
|
||||
;
|
||||
return str_replace($search, $replace, $subject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页包装器
|
||||
*
|
||||
* @param Query $query
|
||||
* @param bool $allowAll 是否全查
|
||||
* @return Query
|
||||
*/
|
||||
public static function pageWrapper(Query $query, bool $allowAll = true): Query
|
||||
{
|
||||
$query_copy = (clone $query);
|
||||
if ($allowAll && Request::param('all')) {
|
||||
return $query_copy;
|
||||
} else {
|
||||
return $query_copy->page(
|
||||
(int) Request::param('page', 1),
|
||||
(int) Request::param('limit', 10)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -168,7 +168,7 @@ class CodeModuleCategory extends BaseModel
|
||||
*/
|
||||
public function scopeNotMaster($query): void
|
||||
{
|
||||
$query->where('code_module_category.code_module_category_parent_guid', '!=', self::MASTER_DEFAULT);
|
||||
$query->where('code_module_category.code_module_category_parent_guid', '<>', self::MASTER_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user